Rewrote some methods as non-static.

Functions for getting potions, pokeballs and pokemon are now in non-static classes.
This will make it easier to manage other npc trainers in the future.
This commit is contained in:
2017-11-27 20:48:24 +01:00
parent b39f03c447
commit 8860f39f2c
4 changed files with 112 additions and 118 deletions

View File

@ -1,6 +1,8 @@
import java.util.ArrayList;
import java.util.Scanner;
public class Trainer {
public static Scanner in = new Scanner(System.in);
String name;
private ArrayList<Pokemon> pokemon;
private Inventory inventory;
@ -50,4 +52,48 @@ public class Trainer {
public Inventory getInventory() {
return this.inventory;
}
/** Lists all currently available pokemon for the trainer.*/
public void availablePokemon(boolean alive) {
ArrayList<Pokemon> pokemonList = null;
if (alive) {
pokemonList = this.getConsciousPokemon();
} else {
pokemonList = this.getFaintedPokemon();
}
System.out.println("You may choose from these pokemon:");
for (int i = 0; i < pokemonList.size(); i++) {
System.out.printf("%d: %s%n", i + 1, pokemonList.get(i));
}
System.out.print(">");
}
public void printPokemon() {
for (Pokemon pokemon : this.pokemon) {
System.out.println(pokemon);
}
}
/**
* Asks the user for the name of a pokemon and returns it.
* @param pokemonList A list of available pokemon
* @return A pokemon object or null.
*/
public Pokemon choosePokemon(boolean alive) {
ArrayList<Pokemon> pokemonList = null;
if (alive) {
pokemonList = this.getConsciousPokemon();
} else {
pokemonList = this.getFaintedPokemon();
}
if (in.hasNextInt()) {
int choice = in.nextInt() - 1;
if (choice >= 0 && choice < pokemonList.size()) {
in.nextLine();
return pokemonList.get(choice);
}
}
in.nextLine();
return null;
}
}