Video Game Character ArrayList Help?
Hey guys, so currently I have this ArrayList set up.
I was wondering if there would be anyway to set up a prompt which asks the user to choose the element they would like to use, as you see the characters each have a unique element. After choosing which one, would there be a way to create a user input to change the default name that is currently there, or even just have no data in the name part of the object and just have the user input one.
Also, Is there a way to use a search function such as to be something like "Search for ATTACK of 20 or more?".
Thank you in advance and I would really appreciate your help <3
package arraylistca;
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListCa {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
//Create objects of Hero class
Hero s1 = new Hero("Damian", 1,50,50,"Light");
Hero s2 = new Hero("Walter", 1,40,60,"Water");
Hero s3 = new Hero("Nathan", 1,20,80,"Air");
Hero s4 = new Hero("Bella", 1,90,10,"Fire");
Hero s5 = new Hero("Tyson", 1,10,90,"Eath");
Hero s6 = new Hero("Lucas", 1,50,50,"Darkness");
Hero s7 = new Hero("Amelia", 1,100,0,"Aether");
Hero s8 = new Hero("Seth", 1,0,100,"Time");
//Create an ArrayList of objects Hero
ArrayList<Hero> aListHeroes = new ArrayList<Hero>();
//add Objects of Hero to ArrayList
aListHeroes.add(s1);
aListHeroes.add(s2);
aListHeroes.add(s3);
aListHeroes.add(s4);
aListHeroes.add(s5);
aListHeroes.add(s6);
aListHeroes.add(s7);
aListHeroes.add(s8);
//display ArrayList objects
System.out.println("Heroes Stats");
for(Hero stats : aListHeroes){
System.out.println("Name: " + stats.getName()
+ ", Level: " +stats.getLevel()
+ ", Attack: " +stats.getAttack()
+ ", Defense: " +stats.getDefense()
+ ", Element: " +stats.getElement());
}
}
}
class Hero{
String name;
int level;
int attack;
int defense;
String element;
public Hero(String name, int level, int attack, int defense, String element){
this.name = name;
this.level = level;
this.attack = attack;
this.defense = defense;
this.element = element;
}
public String getName(){
return this.name;
}
public int getLevel(){
return this.level;
}
public int getAttack(){
return this.attack;
}
public int getDefense(){
return this.defense;
}
public String getElement(){
return this.element;
}
}
Re: Video Game Character ArrayList Help?
In the Hero class you will need to create some new methods for doing what you want. For example a change hero class for which you will pass any values (the name) that you would like to change for that particular hero. You can also create your search for attack class where you would pass a value to seach for and create a loop checking all of your heroes for that specific attack. Hope this helps get you started.