diff --git a/.project b/.project index 4b92280..f5bcc1f 100644 --- a/.project +++ b/.project @@ -6,12 +6,12 @@ - org.eclipse.buildship.core.gradleprojectbuilder + org.eclipse.jdt.core.javabuilder - org.eclipse.jdt.core.javabuilder + org.eclipse.buildship.core.gradleprojectbuilder diff --git a/src/main/java/Colosseum.java b/src/main/java/Colosseum.java index f68697b..12b587b 100644 --- a/src/main/java/Colosseum.java +++ b/src/main/java/Colosseum.java @@ -72,8 +72,62 @@ public class Colosseum { *

* Implement this function. */ - public static Pokemon buildPokemon() { - Pokemon tempPokemon = new Pokemon(); + public static Pokemon buildPokemon(final int player) { + Pokemon tempPokemon; + + String name = ""; + int health = 0; + int attack = 0; + int defense = 0; + int maxPoints = 50; + boolean isValid = false; + + while(!isValid){ + //resets the maxPoints + maxPoints = 50; + + System.out.println("Player "+player+", build your Pokemon!"); + System.out.println("================="); + + System.out.println("Enter your Pokemon's name!"); + name = myScan.next(); + + System.out.println("Enter your Pokemon's hitpoints! (1 - 50)"); + health = myScan.nextInt(); + + System.out.println("Enter your Pokemon's attack! (0 - "+maxPoints+")"); + attack = myScan.nextInt(); + + maxPoints -= attack; + + if (maxPoints < 0) { + System.out.println("Too many points in attack!\n"); + continue; + } + + System.out.println("Enter your Pokemon's defense! (0 - "+maxPoints+")"); + defense = myScan.nextInt(); + + if (defense > maxPoints){ + System.out.println("Too many points in defense!\n"); + continue; + } + + if (health < 1) { + System.out.println("Your pokemon's health \""+health+"\" is too low.\n"); + continue; + } + + if (health > 50) { + System.out.println("Your pokemon's health \""+health+"\" is too high.\n"); + continue; + } + + isValid = true; + } + + tempPokemon = new Pokemon(name, health, attack, defense); + return tempPokemon; } @@ -90,8 +144,13 @@ public static Pokemon buildPokemon() { *

* Implement this function. */ - public static void printWhoIsAhead() { - System.out.println("Implement me!"); + public static void printWhoIsAhead(final Pokemon firstPokemon, final Pokemon secondPokemon) { + System.out.println(firstPokemon.name+" has "+firstPokemon.hitPoints+" hitpoints"); + System.out.println(secondPokemon.name+" has "+secondPokemon.hitPoints+" hitpoints"); + + if(firstPokemon.hitPoints > secondPokemon.hitPoints) System.out.println(firstPokemon.name+" is ahead!"); + else System.out.println(secondPokemon.name+" is ahead!"); + //System.out.println("Implement me!"); } /** @@ -101,27 +160,24 @@ public static void printWhoIsAhead() { *

* Write this function. */ - public static void determineWinner() { - System.out.println("Implement me!"); + public static void determineWinner(final Pokemon firstPokemon, final Pokemon secondPokemon) { + if(firstPokemon.hitPoints < 0) System.out.println(firstPokemon.name+" is the winner"); + else if(secondPokemon.hitPoints < 0) System.out.println(secondPokemon.name+" is the winner!"); + //Added just because + else System.out.println("It's a tie!"); } + /** * Initializes the member Pokemons. *

* You do not need to modify this function. */ public static void initializePokemon() { - System.out.println("Player 1, build your Pokemon!"); - System.out.println("================="); - firstPokemon = buildPokemon(); - firstPokemon.name = "Chuchu"; - + firstPokemon = buildPokemon(1); System.out.println(""); - - System.out.println("Player 2, build your Pokemon!"); - System.out.println("=================="); - secondPokemon = buildPokemon(); - secondPokemon.name = "Xyz"; + secondPokemon = buildPokemon(2); + //secondPokemon.name = "Xyz"; } /** @@ -146,7 +202,7 @@ public static void determineOrder() { * Swap Pokemon for second outcome. */ System.out.print("second"); - Pokemon tempPokemon = new Pokemon(); + Pokemon tempPokemon; tempPokemon = firstPokemon; firstPokemon = secondPokemon; secondPokemon = tempPokemon; @@ -178,7 +234,7 @@ public static void main(final String[] unused) { if (!ifWinner) { ifWinner = secondPokemon.attack(firstPokemon); if (!ifWinner) { - printWhoIsAhead(); + printWhoIsAhead(firstPokemon, secondPokemon); } } @@ -188,7 +244,7 @@ public static void main(final String[] unused) { if (!ifWinner) { System.out.println("It's a tie!"); } else { - determineWinner(); + determineWinner(firstPokemon, secondPokemon); } myScan.close(); diff --git a/src/main/java/Pokemon.java b/src/main/java/Pokemon.java index 02229fb..1a35735 100644 --- a/src/main/java/Pokemon.java +++ b/src/main/java/Pokemon.java @@ -58,16 +58,23 @@ public class Pokemon { *

* Constructs a new Pokemon with a 6-sided die, 20-sided die, 0 hit points, attack level of 0, * defense level of 0, and an empty name. + * @param name name of the pokemon + * @param hitPoints health of the pokemon + * @param attackLevel attack of the pokemon + * @param defenseLevel defense of the pokemon */ - public Pokemon() { + public Pokemon(final String name, final int hitPoints, + final int attackLevel, final int defenseLevel) { final int d6num = 6; final int d20num = 20; this.d6 = new Dice(d6num); this.d20 = new Dice(d20num); - this.hitPoints = 0; - this.attackLevel = 0; - this.defenseLevel = 0; - this.name = ""; + this.hitPoints = hitPoints; + this.attackLevel = attackLevel; + this.defenseLevel = defenseLevel; + this.name = name; + + if(hitPoints > Colosseum.MAX_HIT_POINTS) this.hitPoints = Colosseum.MAX_HIT_POINTS; } /**