Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Lab 7 #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
94 changes: 75 additions & 19 deletions src/main/java/Colosseum.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,62 @@ public class Colosseum {
* <p>
* 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;
}

Expand All @@ -90,8 +144,13 @@ public static Pokemon buildPokemon() {
* <p>
* 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!");
}

/**
Expand All @@ -101,27 +160,24 @@ public static void printWhoIsAhead() {
* <p>
* 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.
* <p>
* 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";
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -178,7 +234,7 @@ public static void main(final String[] unused) {
if (!ifWinner) {
ifWinner = secondPokemon.attack(firstPokemon);
if (!ifWinner) {
printWhoIsAhead();
printWhoIsAhead(firstPokemon, secondPokemon);
}

}
Expand All @@ -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();
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/Pokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ public class Pokemon {
* <p>
* 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;
}

/**
Expand Down