Created Player class

This commit is contained in:
2019-02-18 19:36:03 -07:00
parent 534b8728a5
commit 08edd6069b
2 changed files with 10 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ public class Player {
private int armsHeld = 0; private int armsHeld = 0;
private int location = 1; private int location = 1;
private int guns = 3; private int guns = 3;
private int Hp = 100; private int HP = 100;
public String getName() { public String getName() {
return name; return name;
@@ -19,13 +19,13 @@ public class Player {
this.name = name; this.name = name;
} }
public int getHp() { public int getHP() {
return Hp; return HP;
} }
public void setHp(int Hp) { public void setHP(int HP) {
if(Hp>= 0){ if(HP>= 0){
this.Hp = Hp; this.HP = HP;
} }
} }

View File

@@ -37,14 +37,10 @@ public class ShipWarfare extends Player {
} }
public int getNumOfPeasantShips() { public int getNumOfPeasantShips() {
return numOfPeasantShips; return numOfPeasantShips;
} }
public void setNumOfPeasantShips(int numOfPeasantShips) { public void setNumOfPeasantShips(int numOfPeasantShips) {
this.numOfPeasantShips = numOfPeasantShips; this.numOfPeasantShips = numOfPeasantShips;
} }
@@ -132,12 +128,12 @@ public class ShipWarfare extends Player {
System.out.println("Oh no, they are taking the offensive!"); System.out.println("Oh no, they are taking the offensive!");
delayForASecond(); delayForASecond();
//Computer volley //Computer volley
setHp(getHp() - randomValue.nextInt(10)); setHP(getHP() - randomValue.nextInt(10));
if (getHp() <= 0) { if (getHP() <= 0) {
exitValue = 2; exitValue = 2;
break; break;
} }
System.out.printf("EEK, we have %d health left\n", getHp()); System.out.printf("EEK, we have %d health left\n", getHP());
delayForASecond(); delayForASecond();
System.out.println("Shall we continue the offensive? Enter \"f\" to fight, and \"r\" to run"); System.out.println("Shall we continue the offensive? Enter \"f\" to fight, and \"r\" to run");
@@ -160,7 +156,7 @@ public class ShipWarfare extends Player {
} }
} }
if (exitValue == 1) { if (exitValue == 1) {
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d health\n", getHp()); System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d health\n", getHP());
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
gameOver(); gameOver();