I've done some research on this site about this already, however, I'm having some trouble finding something I can use. I'm trying to create a similar program to pokemon, but much much simpler and text based. Currently I'm using arrays to store the Pokemon's stats. That's working great, but when I need to print the Pokemon's name I have to manually type it out. This has worked fine, but I want to have the player battle a random Pokemon. This is my current code:
public static void main(String[] args) {
//Declare the Pokemon to be used
int[] Player = {0, 0, 0, 0, 0, 0 };
int[] Blastoise = {79, 83, 100, 85, 105, 78 };
int[] Raichu = {60, 90, 55, 90, 80, 110};
int[][] Pokemon = new int[][] {Blastoise, Raichu, Player};
Scanner input = new Scanner(System.in);
startBattle(input, Pokemon)
}
public static String startBattle(Scanner input, int[][] Pokemon) {
System.out.println("A wild Pokemon appeared!");
int r = (int) (Math.random() * 1);
System.out.println("A wild " + **POKEMON NAME** + " appeared!");
System.out.print("What Pokemon do you choose? ");
String userPokemon = input.next();
return userPokemon;
}
Where it says POKEMON NAME is where I want to have the Pokemon's name be. I know it's super difficult to get the name of an array, or add a String to an int array (I would add the name to the list[0] spot). Is there any way I could at least associate a String with one of the lists so I could call the name of that randomly selected Pokemon? Thanks!
Create a class. Give it properties that represent things that describe your real-world entity, in this case a Pokemon.
The properties at a minimum are a string representing the name and the integer array you use to describe a character.
Here's an example:
public class Pokemon {
private String name;
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
private int hp;
public int getHP() { return this.hp; }
public void setHP(int hp) { this.hp = hp; }
// Repeat the pattern for all properties that describe a Pokemon
// hp, attack, defense, special attack, special defense, and speed
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With