2 Commits

Author SHA1 Message Date
2b861a53de Rename docs/LICENSE to LICENSE 2017-11-28 16:44:23 +01:00
e588c16736 Rename LICENSE to docs/LICENSE 2017-11-28 16:44:00 +01:00
15 changed files with 793 additions and 1021 deletions

8
.gitignore vendored
View File

@ -23,11 +23,3 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
# Script files
*.bat
*.sh
#IDEA files
*.xml
*.iml

2
Compile.bat Normal file
View File

@ -0,0 +1,2 @@
javac -cp java java/Game.java
jar cvfm Game.jar manifest.txt -C java config/Pokemon.txt java/*.class

1
Run.bat Normal file
View File

@ -0,0 +1 @@
java -jar Game.jar -Dfile.encoding=UTF-8

View File

@ -1,21 +0,0 @@
class MapTest {
public static void main(String[] args) {
Tile rock = new Tile('■', true, "NONE");
Tile empty = new Tile(' ', false, "NONE");
Map map = new Map(10, 10, 5, 5, empty, rock);
Tile wallTopRight = new Tile('╗', true, "NONE");
Tile wallTopLeft = new Tile('╔', true, "NONE");
Tile wallBottomRight = new Tile('╝', true, "NONE");
Tile wallBottomLeft = new Tile('╚', true, "NONE");
Tile wallSide = new Tile('║', true, "NONE");
Tile wallLying = new Tile('═', true, "NONE");
Tile roof = new Tile(' ', true, "NONE");
Tile door = new Tile('╼', false, "TELEPORT", 10, 10);
Tile player = new Tile('P', false, "NONE");
Tile[][] tiles = {{wallTopLeft, wallSide, wallBottomLeft}, {wallLying, roof, door}, {wallTopRight, wallSide, wallBottomRight}};
new Structure("House", tiles);
map.generateStructure("House", 4, 2);
map.placeTile(player, 8, 8);
System.out.println(map);
}
}

View File

@ -1,3 +0,0 @@
public enum Direction {
NORTH, SOUTH, EAST, WEST;
}

View File

@ -10,7 +10,7 @@ import java.text.ParseException;
/** Simulates the game Pokémon. */ /** Simulates the game Pokémon. */
public class Game { public class Game {
private static final Scanner in = new Scanner(System.in); public static Scanner in = new Scanner(System.in);
public static void main(String[] args) { public static void main(String[] args) {
ArrayList<Pokemon> pokemon = readPokemon(); ArrayList<Pokemon> pokemon = readPokemon();
@ -21,12 +21,12 @@ public class Game {
Trainer player = new Trainer(name, randomTeam(), createInventory()); Trainer player = new Trainer(name, randomTeam(), createInventory());
boolean done = false; boolean done = false;
Pokemon opponentPokemon; Pokemon opponentPokemon = null;
Pokemon trainersPokemon = null; Pokemon trainersPokemon = null;
Pokeball currentPokeball; Pokeball currentPokeball = null;
Potion currentPotion; Potion currentPotion = null;
boolean fleeSuccess; boolean fleeSuccess = false;
Pokemon pokemonToHeal; Pokemon pokemonToHeal = null;
opponentPokemon = randomPokemon(pokemon); opponentPokemon = randomPokemon(pokemon);
System.out.printf("A wild %s appeared.%n", opponentPokemon.getName()); System.out.printf("A wild %s appeared.%n", opponentPokemon.getName());
@ -187,7 +187,7 @@ public class Game {
* @param pokemonList List of pokemon to search. * @param pokemonList List of pokemon to search.
* @param target The pokemon to remove. * @param target The pokemon to remove.
*/ */
private static void pokemonFainted(ArrayList<Pokemon> pokemonList, Pokemon target) { public static void pokemonFainted(ArrayList<Pokemon> pokemonList, Pokemon target) {
for (int i = 0; i < pokemonList.size(); i++) { for (int i = 0; i < pokemonList.size(); i++) {
if (pokemonList.get(i).equals(target)) { if (pokemonList.get(i).equals(target)) {
pokemonList.remove(i); pokemonList.remove(i);
@ -199,7 +199,7 @@ public class Game {
* Gives a trainer necessary starting items. * Gives a trainer necessary starting items.
* @return A list of items. * @return A list of items.
*/ */
private static Inventory createInventory() { public static Inventory createInventory() {
Inventory inventory = new Inventory(); Inventory inventory = new Inventory();
inventory.addPokeball("Poke Ball", "A device for catching wild Pokémon. It's thrown like a ball at a Pokémon, comfortably encapsulating its target.", 15); inventory.addPokeball("Poke Ball", "A device for catching wild Pokémon. It's thrown like a ball at a Pokémon, comfortably encapsulating its target.", 15);
inventory.addPokeball("Great ball", "A good, high-performance Poké Ball that provides a higher Pokémon catch rate than a standard Poké Ball.", 10); inventory.addPokeball("Great ball", "A good, high-performance Poké Ball that provides a higher Pokémon catch rate than a standard Poké Ball.", 10);
@ -218,7 +218,7 @@ public class Game {
* @param pokemon The list to choose from. * @param pokemon The list to choose from.
* @return A Pokemon object, or null if the list is empty. * @return A Pokemon object, or null if the list is empty.
*/ */
private static Pokemon randomPokemon(ArrayList<Pokemon> pokemon) { public static Pokemon randomPokemon(ArrayList<Pokemon> pokemon) {
if (pokemon.size() > 0) { if (pokemon.size() > 0) {
return pokemon.get((int)(Math.random() * pokemon.size())); return pokemon.get((int)(Math.random() * pokemon.size()));
} else { } else {
@ -230,14 +230,14 @@ public class Game {
* Reads pokemon from Pokemon.txt to an ArrayList. * Reads pokemon from Pokemon.txt to an ArrayList.
* @return An ArrayList of pokemon objects. * @return An ArrayList of pokemon objects.
*/ */
private static ArrayList<Pokemon> readPokemon() { public static ArrayList<Pokemon> readPokemon() {
ArrayList<Pokemon> pokemon = new ArrayList<>(); ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
try (Scanner file = new Scanner(new File("config/Pokemon.txt"))) { try (Scanner file = new Scanner(new File("config/Pokemon.txt"))) {
while (file.hasNextLine()) { while (file.hasNextLine()) {
pokemon.add(new Pokemon(file.nextLine())); pokemon.add(new Pokemon(file.nextLine()));
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
/* If the file is compiled as jar, this will prevent an empty list. */ /** If the file is compiled as jar, this will prevent an empty list. */
try (Scanner file = new Scanner(Game.class.getResourceAsStream("/config/Pokemon.txt"))) { try (Scanner file = new Scanner(Game.class.getResourceAsStream("/config/Pokemon.txt"))) {
while (file.hasNextLine()) { while (file.hasNextLine()) {
pokemon.add(new Pokemon(file.nextLine())); pokemon.add(new Pokemon(file.nextLine()));
@ -252,7 +252,7 @@ public class Game {
* @param pokemon A list of pokemon objects. * @param pokemon A list of pokemon objects.
* @return A pokemon object. * @return A pokemon object.
*/ */
private static Pokemon pick(ArrayList<Pokemon> pokemon) { public static Pokemon pick(ArrayList<Pokemon> pokemon) {
int index = (int)(Math.random() * (pokemon.size())); int index = (int)(Math.random() * (pokemon.size()));
Pokemon randomPokemon = pokemon.get(index); Pokemon randomPokemon = pokemon.get(index);
pokemon.remove(index); pokemon.remove(index);
@ -264,7 +264,7 @@ public class Game {
* @param pokemonList List of Pokemon objects to save. * @param pokemonList List of Pokemon objects to save.
* @param savefile The file to write to. * @param savefile The file to write to.
*/ */
private static void savePokemon(ArrayList<Pokemon> pokemonList, String savefile) { public static void savePokemon(ArrayList<Pokemon> pokemonList, String savefile) {
try (PrintWriter file = new PrintWriter(savefile)) { try (PrintWriter file = new PrintWriter(savefile)) {
for (Pokemon pokemon : pokemonList) { for (Pokemon pokemon : pokemonList) {
file.println(pokemon.saveString()); file.println(pokemon.saveString());
@ -277,10 +277,10 @@ public class Game {
/** /**
* Saves all items in a list to a text file. * Saves all items in a list to a text file.
* @param inventory The items of a player * @param itemList List of Item objects to save.
* @param savefile The file to write to. * @param savefile The file to write to.
*/ */
private static void saveInventory(Inventory inventory, String savefile) { public static void saveInventory(Inventory inventory, String savefile) {
try (PrintWriter file = new PrintWriter(savefile)) { try (PrintWriter file = new PrintWriter(savefile)) {
for (Pokeball pokeball : inventory.getPokeballs()) { for (Pokeball pokeball : inventory.getPokeballs()) {
file.println(pokeball.saveString()); file.println(pokeball.saveString());
@ -300,15 +300,17 @@ public class Game {
* @param savefile The file to write to. * @param savefile The file to write to.
* @return A list of pokemon or null on failiure. * @return A list of pokemon or null on failiure.
*/ */
private static ArrayList<Pokemon> loadPokemon(String savefile) { public static ArrayList<Pokemon> loadPokemon(String savefile) {
ArrayList<Pokemon> pokemon = new ArrayList<>(); ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
try (Scanner file = new Scanner(new File(savefile))) { try (Scanner file = new Scanner(new File(savefile))) {
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
while (file.hasNextLine()) { while (file.hasNextLine()) {
String[] data = file.nextLine().split(";"); String[] data = file.nextLine().split(";");
try { try {
pokemon.add(new Pokemon(data[0], Integer.parseInt(data[1]), Integer.parseInt(data[2]), Integer.parseInt(data[3]), format.parse(data[4]).doubleValue(), Integer.parseInt(data[5]), Integer.parseInt(data[6]), Integer.parseInt(data[7]))); pokemon.add(new Pokemon(data[0], Integer.parseInt(data[1]), Integer.parseInt(data[2]), Integer.parseInt(data[3]), format.parse(data[4]).doubleValue(), Integer.parseInt(data[5]), Integer.parseInt(data[6]), Integer.parseInt(data[7])));
} catch (NumberFormatException | ParseException e) { } catch (NumberFormatException e) {
System.out.println("Malformed number " + e);
} catch (ParseException e) {
System.out.println("Malformed number " + e); System.out.println("Malformed number " + e);
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Invalid savefile: " + savefile); System.out.println("Invalid savefile: " + savefile);
@ -328,9 +330,9 @@ public class Game {
* @param savefile The file to write to. * @param savefile The file to write to.
* @return A list of items or null on failiure. * @return A list of items or null on failiure.
*/ */
private static Inventory loadInventory(String savefile) { public static Inventory loadInventory(String savefile) {
ArrayList<Pokeball> pokeballs = new ArrayList<>(); ArrayList<Pokeball> pokeballs = new ArrayList<Pokeball>();
ArrayList<Potion> potions = new ArrayList<>(); ArrayList<Potion> potions = new ArrayList<Potion>();
try (Scanner file = new Scanner(new File(savefile))) { try (Scanner file = new Scanner(new File(savefile))) {
String next = ""; String next = "";
while (file.hasNextLine() && !next.equals(":NEXTLIST:")) { while (file.hasNextLine() && !next.equals(":NEXTLIST:")) {
@ -362,9 +364,9 @@ public class Game {
return new Inventory(pokeballs, potions); return new Inventory(pokeballs, potions);
} }
private static ArrayList<Pokemon> randomTeam() { public static ArrayList<Pokemon> randomTeam() {
ArrayList<Pokemon> temporary = readPokemon(); ArrayList<Pokemon> temporary = readPokemon();
ArrayList<Pokemon> pokemon = new ArrayList<>(); ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
for (int i = 1; i <= 6; i++) { for (int i = 1; i <= 6; i++) {
pokemon.add(pick(temporary)); pokemon.add(pick(temporary));
} }

View File

@ -2,13 +2,13 @@ import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
public class Inventory { public class Inventory {
private static final Scanner in = new Scanner(System.in); public static Scanner in = new Scanner(System.in);
private final ArrayList<Pokeball> pokeballs; private ArrayList<Pokeball> pokeballs;
private final ArrayList<Potion> potions; private ArrayList<Potion> potions;
public Inventory() { public Inventory() {
this.pokeballs = new ArrayList<>(); this.pokeballs = new ArrayList<Pokeball>();
this.potions = new ArrayList<>(); this.potions = new ArrayList<Potion>();
} }
public Inventory(ArrayList<Pokeball> pokeballs, ArrayList<Potion> potions) { public Inventory(ArrayList<Pokeball> pokeballs, ArrayList<Potion> potions) {
@ -18,16 +18,20 @@ public class Inventory {
public void addPokeball(String name, String description, int amount) { public void addPokeball(String name, String description, int amount) {
Pokeball pokeball = new Pokeball(name, description, amount, Pokeball.Pokeballs.valueOf(name.toUpperCase().replace(" ", ""))); Pokeball pokeball = new Pokeball(name, description, amount, Pokeball.Pokeballs.valueOf(name.toUpperCase().replace(" ", "")));
if (pokeball != null) {
this.pokeballs.add(pokeball); this.pokeballs.add(pokeball);
} }
}
public void addPotion(String name, String description, int amount, boolean alive) { public void addPotion(String name, String description, int amount, boolean alive) {
Potion potion = new Potion(name, description, amount, Potion.Potions.valueOf(name.toUpperCase().replace(" ", "")), alive); Potion potion = new Potion(name, description, amount, Potion.Potions.valueOf(name.toUpperCase().replace(" ", "")), alive);
if (potion != null) {
this.potions.add(potion); this.potions.add(potion);
} }
}
public ArrayList<Pokeball> getPokeballs() { public ArrayList<Pokeball> getPokeballs() {
ArrayList<Pokeball> pokeballs = new ArrayList<>(); ArrayList<Pokeball> pokeballs = new ArrayList<Pokeball>();
for (Pokeball pokeball : this.pokeballs) { for (Pokeball pokeball : this.pokeballs) {
if (pokeball.getAmount() > 0) { if (pokeball.getAmount() > 0) {
pokeballs.add(pokeball); pokeballs.add(pokeball);
@ -37,7 +41,7 @@ public class Inventory {
} }
public ArrayList<Potion> getPotions() { public ArrayList<Potion> getPotions() {
ArrayList<Potion> potions = new ArrayList<>(); ArrayList<Potion> potions = new ArrayList<Potion>();
for (Potion potion : this.potions) { for (Potion potion : this.potions) {
if (potion.getAmount() > 0) { if (potion.getAmount() > 0) {
potions.add(potion); potions.add(potion);

View File

@ -1,89 +0,0 @@
class Map {
private final Tile[][] tiles;
private int fullWidth;
private int fullHeight;
public Map(int width, int height, int wWidth, int wHeight, Tile empty, Tile wall) {
this.fullHeight = height + (2 * wHeight);
this.fullWidth = width + (2 * wWidth);
Tile[][] map = new Tile[this.fullWidth][this.fullHeight];
for (int i = 0; i < this.fullWidth; i++) {
for (int j = 0; j < this.fullHeight; j++) {
if (i < wWidth || i >= width + wWidth || j < wHeight || j >= height + wHeight) {
map[i][j] = wall;
} else {
map[i][j] = empty;
}
}
}
this.tiles = map;
}
private Tile[][] getTiles() {
return this.tiles;
}
public void generateStructure(String name, int x, int y) throws IllegalArgumentException {
for (Structure structure : Structure.getStructures()) {
if (name.equals(structure.getName())) {
this.placeStructure(structure, x, y);
return;
}
}
throw new IllegalArgumentException("Invalid structure name.");
}
private void placeStructure(Structure structure, int x, int y) throws IllegalArgumentException {
if (x < 0 || y < 0 || this.fullWidth < x + structure.getWidth() || this.fullHeight < y + structure.getHeight()) {
throw new IllegalArgumentException("The structure is misplaced or does not fit.");
}
Tile[][] tiles = structure.getTiles();
for (int i = 0; i < structure.getWidth(); i++) {
for (int j = 0; j < structure.getHeight(); j++) {
if (!tiles[i][j].isSolid()) {
switch (structure.getDoorDirection()) {
case NORTH:
if (this.tiles[x+i][y+j-1].isSolid()) {
throw new IllegalArgumentException("A structure is blocked");
}
break;
case SOUTH:
if (this.tiles[x+i][y+j+1].isSolid()) {
throw new IllegalArgumentException("A structure is blocked");
}
break;
case WEST:
if (this.tiles[x+i-1][y+j].isSolid()) {
throw new IllegalArgumentException("A structure is blocked");
}
break;
case EAST:
if (this.tiles[x+i+1][y+j].isSolid()) {
throw new IllegalArgumentException("A structure is blocked");
}
}
}
this.tiles[x+i][y+j] = tiles[i][j];
}
}
}
public void placeTile(Tile tile, int x, int y) {
if (x < 0 || y < 0 || x >= this.tiles.length || y >= this.tiles[0].length) {
throw new IllegalArgumentException("Invalid tile position");
}
this.tiles[x][y] = tile;
}
public String toString() {
Tile[][] tiles = this.getTiles();
StringBuilder str = new StringBuilder();
for (int i = 0; i < tiles.length; i++) {
for (int j = 0; j < tiles.length; j++) {
str.append(tiles[j][i].toChar());
}
str.append("\n");
}
return str.toString();
}
}

View File

@ -1,10 +1,10 @@
import java.util.ArrayList; import java.util.ArrayList;
public class Pokeball { public class Pokeball {
public enum Pokeballs { POKEBALL, GREATBALL, ULTRABALL, MASTERBALL } public static enum Pokeballs { POKEBALL, GREATBALL, ULTRABALL, MASTERBALL }
private final String name; private String name;
private final String description; private String description;
private final Pokeballs type; private Pokeballs type;
private int amount; private int amount;
public Pokeball(String name, String description, int amount, Pokeballs type) { public Pokeball(String name, String description, int amount, Pokeballs type) {

View File

@ -2,13 +2,13 @@ import java.util.Random;
import java.util.ArrayList; import java.util.ArrayList;
public class Pokemon { public class Pokemon {
private final String name; private String name;
private int healthPoints; private int healthPoints;
private int maxHealthPoints; private int maxHealthPoints;
private int strength; private int strength;
private final double criticalChance; private double criticalChance;
private final Random random; private Random random;
private final int catchRate; private int catchRate;
private int exp; private int exp;
private int level; private int level;
private int fleeCount; private int fleeCount;
@ -79,7 +79,7 @@ public class Pokemon {
/** /**
* Checks if a pokemon has not taken any damage or is fully healed. * Checks if a pokemon has not taken any damage or is fully healed.
* @return True if health is full. False otherwise. * @param return True if health is full. False otherwise.
*/ */
public boolean isDamaged() { public boolean isDamaged() {
return this.healthPoints < this.maxHealthPoints; return this.healthPoints < this.maxHealthPoints;
@ -110,7 +110,7 @@ public class Pokemon {
/** /**
* Captures a wild pokemon. * Captures a wild pokemon.
* @param current The pokemon list the pokemon belongs to. * @param current The pokemon list the pokemon belongs to.
* @param trainer The trainer who is capturing. * @param catcher The pokemon list of the trainer.
*/ */
private void capture(ArrayList<Pokemon> current, Trainer trainer) { private void capture(ArrayList<Pokemon> current, Trainer trainer) {
trainer.addPokemon(this); trainer.addPokemon(this);
@ -136,16 +136,16 @@ public class Pokemon {
/** /**
* Damages a pokemon. * Damages a pokemon.
* @param damageTaken How many hitpoints are to be deducted. * @param How many hitpoints are to be deducted.
*/ */
private void damage(int damageTaken) { public void damage(int damageTaken) {
this.healthPoints = Math.max(this.healthPoints -= damageTaken, 0); this.healthPoints = Math.max(this.healthPoints -= damageTaken, 0);
System.out.printf("%s takes %d damage and is left with %d/%d HP%n", this.name, damageTaken, this.healthPoints, this.maxHealthPoints); System.out.printf("%s takes %d damage and is left with %d/%d HP%n", this.name, damageTaken, this.healthPoints, this.maxHealthPoints);
} }
/** /**
* Gives a pokemon exp after each successfull battle. Also handles leveling up. * Gives a pokemon exp after each successfull battle. Also handles leveling up.
* @param target Which pokemon did we beat. * @target Which pokemon did we beat.
*/ */
private void giveEXP(Pokemon target) { private void giveEXP(Pokemon target) {
int exp = (100 * target.level)/7; int exp = (100 * target.level)/7;

View File

@ -1,9 +1,11 @@
import java.util.ArrayList;
public class Potion { public class Potion {
public enum Potions { POTION, SUPERPOTION, HYPERPOTION, MAXPOTION, REVIVE } public static enum Potions { POTION, SUPERPOTION, HYPERPOTION, MAXPOTION, REVIVE }
private final String name; private String name;
private final String description; private String description;
private final Potions type; private Potions type;
private final boolean alive; private boolean alive;
private int amount; private int amount;
public Potion(String name, String description, int amount, Potions type) { public Potion(String name, String description, int amount, Potions type) {

View File

@ -1,58 +0,0 @@
import java.util.ArrayList;
class Structure {
private static final ArrayList<Structure> structures = new ArrayList<>();
private final Tile[][] tiles;
private final String name;
public Structure(String name, Tile[][] tiles) {
this.name = name;
this.tiles = tiles;
structures.add(this);
}
public String getName() {
return this.name;
}
public Tile[][] getTiles() {
return this.tiles;
}
public static ArrayList<Structure> getStructures() {
return structures;
}
public int getWidth() {
return this.tiles.length;
}
public Direction getDoorDirection() {
for (int x = 0; x < this.getWidth(); x++) {
for (int y = 0; y < this.getHeight(); y++) {
if (!tiles[x][y].isSolid()) {
if (y == tiles[x].length - 1) {
return Direction.SOUTH;
} else if (y == 0) {
return Direction.NORTH;
} else if (x == 0) {
return Direction.WEST;
} else if (x == tiles.length - 1) {
return Direction.EAST;
}
}
}
}
return null;
}
public int getHeight() {
int max = 0;
for (Tile[] tile : this.tiles) {
if (tile.length > max) {
max = tile.length;
}
}
return max;
}
}

View File

@ -1,60 +0,0 @@
public class Tile {
private final char representation;
private final boolean solid;
private enum Action { TELEPORT, NONE, ENCOUNTER, MENUBATTLE, MENUSHOP }
private final Action action;
private int[] teleportTarget;
public Tile (char representation, boolean solid, String action) throws IllegalArgumentException {
this.representation = representation;
this.solid = solid;
this.action = Action.valueOf(action.toUpperCase());
if (this.action != Action.TELEPORT) {
this.teleportTarget = null;
} else {
throw new IllegalArgumentException("A teleport tile must have a valid target.");
}
}
public Tile (char representation, boolean solid, String action, int x, int y) throws IllegalArgumentException {
this.representation = representation;
this.solid = solid;
this.action = Action.valueOf(action.toUpperCase());
if (this.action == Action.TELEPORT) {
this.teleportTarget = new int[]{x, y};
} else {
throw new IllegalArgumentException("A non-teleport tile can't have a teleport target.");
}
}
public char toChar() {
return this.representation;
}
public int[] getTeleportTarget() {
return this.teleportTarget;
}
public boolean isSolid() {
return this.solid;
}
public int onWalk() {
if (this.solid) {
System.out.println("You bumped against an immovable structure.");
return -1;
} else {
switch (this.action) {
case TELEPORT:
return 1;
case ENCOUNTER:
return 2;
case MENUBATTLE:
return 3;
case MENUSHOP:
return 4;
}
}
return 0;
}
}

View File

@ -1,13 +1,13 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
class Trainer { public class Trainer {
private static final Scanner in = new Scanner(System.in); public static Scanner in = new Scanner(System.in);
private final String name; String name;
private ArrayList<Pokemon> pokemon; private ArrayList<Pokemon> pokemon;
private Inventory inventory; private Inventory inventory;
Trainer(String name, ArrayList<Pokemon> pokemon, Inventory inventory) { public Trainer(String name, ArrayList<Pokemon> pokemon, Inventory inventory) {
this.name = name; this.name = name;
this.pokemon = pokemon; this.pokemon = pokemon;
this.inventory = inventory; this.inventory = inventory;
@ -30,7 +30,7 @@ class Trainer {
} }
public ArrayList<Pokemon> getConsciousPokemon() { public ArrayList<Pokemon> getConsciousPokemon() {
ArrayList<Pokemon> pokemon = new ArrayList<>(); ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
for (Pokemon singlePokemon : this.pokemon) { for (Pokemon singlePokemon : this.pokemon) {
if (singlePokemon.isConscious()) { if (singlePokemon.isConscious()) {
pokemon.add(singlePokemon); pokemon.add(singlePokemon);
@ -39,8 +39,8 @@ class Trainer {
return pokemon; return pokemon;
} }
private ArrayList<Pokemon> getFaintedPokemon() { public ArrayList<Pokemon> getFaintedPokemon() {
ArrayList<Pokemon> pokemon = new ArrayList<>(); ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
for (Pokemon singlePokemon : this.pokemon) { for (Pokemon singlePokemon : this.pokemon) {
if (!singlePokemon.isConscious()) { if (!singlePokemon.isConscious()) {
pokemon.add(singlePokemon); pokemon.add(singlePokemon);
@ -55,7 +55,7 @@ class Trainer {
/** Lists all currently available pokemon for the trainer.*/ /** Lists all currently available pokemon for the trainer.*/
public void availablePokemon(boolean alive) { public void availablePokemon(boolean alive) {
ArrayList<Pokemon> pokemonList; ArrayList<Pokemon> pokemonList = null;
if (alive) { if (alive) {
pokemonList = this.getConsciousPokemon(); pokemonList = this.getConsciousPokemon();
} else { } else {
@ -76,11 +76,11 @@ class Trainer {
/** /**
* Asks the user for the name of a pokemon and returns it. * Asks the user for the name of a pokemon and returns it.
* @param alive Are we looking for alive pokemon? * @param pokemonList A list of available pokemon
* @return A pokemon object or null. * @return A pokemon object or null.
*/ */
public Pokemon choosePokemon(boolean alive) { public Pokemon choosePokemon(boolean alive) {
ArrayList<Pokemon> pokemonList; ArrayList<Pokemon> pokemonList = null;
if (alive) { if (alive) {
pokemonList = this.getConsciousPokemon(); pokemonList = this.getConsciousPokemon();
} else { } else {