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

View File

@@ -37,14 +37,10 @@ public class ShipWarfare extends Player {
}
public int getNumOfPeasantShips() {
return numOfPeasantShips;
}
public void setNumOfPeasantShips(int numOfPeasantShips) {
this.numOfPeasantShips = numOfPeasantShips;
}
@@ -132,12 +128,12 @@ public class ShipWarfare extends Player {
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
//Computer volley
setHp(getHp() - randomValue.nextInt(10));
if (getHp() <= 0) {
setHP(getHP() - randomValue.nextInt(10));
if (getHP() <= 0) {
exitValue = 2;
break;
}
System.out.printf("EEK, we have %d health left\n", getHp());
System.out.printf("EEK, we have %d health left\n", getHP());
delayForASecond();
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) {
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;
} else if (exitValue == 2) {
gameOver();