Sloppy but completed ShipWarfare class
This commit is contained in:
@@ -8,7 +8,7 @@ public class Player {
|
||||
private int generalHeld = 0;
|
||||
private int armsHeld = 0;
|
||||
private int location = 1;
|
||||
private int guns = 1000;
|
||||
private int guns = 3;
|
||||
private int HP = 100;
|
||||
|
||||
|
||||
|
||||
@@ -5,22 +5,27 @@ import java.util.concurrent.TimeUnit;
|
||||
public class ShipWarfare extends Player {
|
||||
|
||||
private int numOfPeasantShips = 0;
|
||||
private int numOfLittyShips=0;
|
||||
private int numOfLittyShips = 0;
|
||||
private boolean userAttacks = true;
|
||||
private int startingShips=0;
|
||||
private int startingPeasantShips = 0;
|
||||
private int startingLittyShips =0;
|
||||
private int howMuchRun = 0;
|
||||
private String pirateName = "Liu Yen";
|
||||
|
||||
|
||||
public void peasantFleetAttack() throws Exception {
|
||||
Scanner userResponse = new Scanner(System.in);
|
||||
setNumOfPeasantShips(numOfShips());
|
||||
System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", getMoney(), getNumOfPeasantShips(),getHP());
|
||||
|
||||
System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", getMoney(), numOfLittyShips, getHP());
|
||||
|
||||
fightOrRunMessage();
|
||||
while (true) {
|
||||
String response = userResponse.nextLine();
|
||||
if (response.equalsIgnoreCase("f")) {
|
||||
userAttacks = true;
|
||||
System.out.println("Ohh, fight ehh?");
|
||||
boolean winOrLose = destroyShipsOrEscape(getNumOfPeasantShips());
|
||||
boolean winOrLose = destroyPeasantShipsOrEscape();
|
||||
if (winOrLose == true) {
|
||||
break;
|
||||
}
|
||||
@@ -29,7 +34,40 @@ public class ShipWarfare extends Player {
|
||||
} else if (response.equalsIgnoreCase("r")) {
|
||||
if (runFromShips() == false) {
|
||||
System.out.println("Couldn't run away!");
|
||||
if(destroyShipsOrEscape(getNumOfPeasantShips()))
|
||||
if (destroyPeasantShipsOrEscape())
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Phew! Got away safely");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void littyFleetAttack() throws Exception {
|
||||
Scanner userResponse = new Scanner(System.in);
|
||||
setNumOfLittyShips(numOfShips());
|
||||
System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", getMoney(), numOfLittyShips, pirateName, getHP());
|
||||
fightOrRunMessage();
|
||||
while (true) {
|
||||
String response = userResponse.nextLine();
|
||||
if (response.equalsIgnoreCase("f")) {
|
||||
userAttacks = true;
|
||||
System.out.println("Ohh, fight ehh?");
|
||||
boolean winOrLose = destroyLittyShipsOrEscape();
|
||||
if (winOrLose == true) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
} else if (response.equalsIgnoreCase("r")) {
|
||||
if (runFromShips() == false) {
|
||||
System.out.println("Couldn't run away!");
|
||||
if (destroyLittyShipsOrEscape())
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Phew! Got away safely");
|
||||
@@ -49,14 +87,20 @@ public class ShipWarfare extends Player {
|
||||
|
||||
}
|
||||
|
||||
public int getNumOfPeasantShips() {
|
||||
public int numOfPeasantShips() {
|
||||
return numOfPeasantShips;
|
||||
|
||||
}
|
||||
|
||||
public void setNumOfLittyShips(int numOfLittyShips) {
|
||||
this.numOfLittyShips = numOfLittyShips;
|
||||
startingLittyShips = numOfLittyShips;
|
||||
|
||||
}
|
||||
|
||||
public void setNumOfPeasantShips(int numOfPeasantShips) {
|
||||
this.numOfPeasantShips = numOfPeasantShips;
|
||||
startingShips = numOfPeasantShips;
|
||||
startingPeasantShips = numOfPeasantShips;
|
||||
|
||||
}
|
||||
|
||||
@@ -100,12 +144,125 @@ public class ShipWarfare extends Player {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean destroyShipsOrEscape(int typeOfShip) throws Exception {
|
||||
int calculateLoot=0;
|
||||
public boolean destroyLittyShipsOrEscape() throws Exception {
|
||||
int calculateLoot = 0;
|
||||
int chanceOfEnemyRun = 0;
|
||||
|
||||
|
||||
Scanner userInput = new Scanner(System.in);
|
||||
Random randomValue = new Random();
|
||||
int exitValue = 0;
|
||||
|
||||
//Player volley
|
||||
while (exitValue == 0) {
|
||||
for (int j = 0; j < getGuns(); j++) {
|
||||
if (userAttacks == true) {
|
||||
int hitOrMiss = randomValue.nextInt(3) + 1;
|
||||
if (hitOrMiss == 1) {
|
||||
numOfLittyShips--;
|
||||
if (numOfLittyShips <= 0) {
|
||||
exitValue = 1;
|
||||
break;
|
||||
}
|
||||
System.out.println("Got eem");
|
||||
delayForASecond();
|
||||
} else if (hitOrMiss == 2) {
|
||||
System.out.printf("ARRG! We missed %s\n", getName());
|
||||
delayForASecond();
|
||||
} else {
|
||||
System.out.println("Darn! Their fleet tanked our attack");
|
||||
delayForASecond();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (numOfLittyShips <= 0) {
|
||||
exitValue = 1;
|
||||
break;
|
||||
}
|
||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||
if (chanceOfEnemyRun == 2) {
|
||||
howMuchRun = randomValue.nextInt(10) + 1;
|
||||
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
|
||||
|
||||
|
||||
setNumOfLittyShips(numOfLittyShips - howMuchRun);
|
||||
if (userAttacks == true) {
|
||||
System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, getName());
|
||||
} else {
|
||||
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("%d ships remaining\n", numOfLittyShips);
|
||||
System.out.println("Oh no, they are taking the offensive!");
|
||||
delayForASecond();
|
||||
//Computer volley
|
||||
int takeGunChance = randomValue.nextInt(4) + 1;
|
||||
if (takeGunChance == 1 && getGuns() > 0) {
|
||||
setGuns(getGuns() - 1);
|
||||
System.out.println("Dang it! They destroyed one of our guns");
|
||||
} else {
|
||||
setHP(getHP() - (1 + randomValue.nextInt(15)));
|
||||
}
|
||||
if (getHP() <= 0) {
|
||||
exitValue = 2;
|
||||
break;
|
||||
}
|
||||
System.out.printf("EEK, our current ship status is %d%% \n", getHP());
|
||||
delayForASecond();
|
||||
if (userAttacks == false) {
|
||||
userAttacks = true;
|
||||
}
|
||||
|
||||
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", getGuns());
|
||||
|
||||
String response = userInput.nextLine();
|
||||
if (response.equalsIgnoreCase("r")) {
|
||||
if (runFromShips() == false) {
|
||||
System.out.println("Couldn't run away");
|
||||
} else {
|
||||
exitValue = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (exitValue == 1) {
|
||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", getHP());
|
||||
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
||||
setMoney(getMoney() + calculateLoot);
|
||||
System.out.printf("We got $%,d!\n", calculateLoot);
|
||||
return true;
|
||||
} else if (exitValue == 2) {
|
||||
gameOver();
|
||||
return true;
|
||||
} else if (exitValue == 3) {
|
||||
System.out.printf("We made it out at %d%% ship status!\n", getHP());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean destroyPeasantShipsOrEscape() throws Exception {
|
||||
int calculateLoot = 0;
|
||||
int chanceOfEnemyRun = 0;
|
||||
|
||||
|
||||
Scanner userInput = new Scanner(System.in);
|
||||
Random randomValue = new Random();
|
||||
numOfPeasantShips = typeOfShip;
|
||||
int exitValue = 0;
|
||||
|
||||
//Player volley
|
||||
@@ -122,7 +279,7 @@ public class ShipWarfare extends Player {
|
||||
System.out.println("Got eem");
|
||||
delayForASecond();
|
||||
} else {
|
||||
System.out.println("ARRG! We missed captain");
|
||||
System.out.printf("ARRG! We missed %s\n", getName());
|
||||
delayForASecond();
|
||||
}
|
||||
|
||||
@@ -137,8 +294,22 @@ public class ShipWarfare extends Player {
|
||||
exitValue = 1;
|
||||
break;
|
||||
}
|
||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||
if (chanceOfEnemyRun == 2) {
|
||||
howMuchRun = randomValue.nextInt(15) + 1;
|
||||
if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
|
||||
|
||||
System.out.printf("%d ships remaining\n", getNumOfPeasantShips());
|
||||
|
||||
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
||||
if (userAttacks == true) {
|
||||
System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, getName());
|
||||
} else {
|
||||
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("%d ships remaining\n", numOfPeasantShips);
|
||||
System.out.println("Oh no, they are taking the offensive!");
|
||||
delayForASecond();
|
||||
//Computer volley
|
||||
@@ -159,7 +330,7 @@ public class ShipWarfare extends Player {
|
||||
userAttacks = true;
|
||||
}
|
||||
|
||||
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)", getGuns());
|
||||
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", getGuns());
|
||||
|
||||
String response = userInput.nextLine();
|
||||
if (response.equalsIgnoreCase("r")) {
|
||||
@@ -177,9 +348,9 @@ 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%% ship status\n", getHP());
|
||||
calculateLoot= (randomValue.nextInt(startingShips) + startingShips) *100;
|
||||
setMoney(getMoney()+calculateLoot);
|
||||
System.out.printf("We got $%,d!",calculateLoot);
|
||||
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
||||
setMoney(getMoney() + calculateLoot);
|
||||
System.out.printf("We got $%,d!", calculateLoot);
|
||||
return true;
|
||||
} else if (exitValue == 2) {
|
||||
gameOver();
|
||||
@@ -192,12 +363,11 @@ public class ShipWarfare extends Player {
|
||||
|
||||
|
||||
}
|
||||
//Type of ship implied to be Liu Yen fleet
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ShipWarfare littyObject = new ShipWarfare();
|
||||
littyObject.peasantFleetAttack();
|
||||
littyObject.littyFleetAttack();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,134 +131,10 @@ public class TaipanShop extends Player {
|
||||
System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, or Quit Trading?");
|
||||
String response = input.next();
|
||||
if (response.equalsIgnoreCase("B")) {
|
||||
boolean notDone2 = true;
|
||||
System.out.println("What do you wish me to buy, " + getName() + "?");
|
||||
while (notDone2) {
|
||||
response = input.nextLine();
|
||||
if (response.equalsIgnoreCase("O")) {
|
||||
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / opiumPrice && num >= 0) {
|
||||
setOpiumHeld(getOpiumHeld()+num);
|
||||
setMoney(getMoney()-num * opiumPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() / silkPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / silkPrice && num >= 0) {
|
||||
setSilkHeld(getSilkHeld()+num);
|
||||
setMoney(getMoney()-num * silkPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("A")) {
|
||||
System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() / armsPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / armsPrice && num >= 0) {
|
||||
setArmsHeld(getArmsHeld()+num);
|
||||
setMoney(getMoney() - num*armsPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("G")) {
|
||||
System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() / generalPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / generalPrice && num >= 0) {
|
||||
setGeneralHeld(getGeneralHeld()+num);
|
||||
setMoney(getMoney() - num*generalPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ayyy(input);
|
||||
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
boolean notDone2 = true;
|
||||
System.out.println("What do you wish me to sell, " + getName() + "?");
|
||||
while (notDone2) {
|
||||
response = input.nextLine();
|
||||
if (response.equalsIgnoreCase("O")) {
|
||||
System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getOpiumHeld() && num >= 0) {
|
||||
setOpiumHeld(getOpiumHeld()-num);
|
||||
setMoney(getMoney() + num*opiumPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getSilkHeld() && num >= 0) {
|
||||
setSilkHeld(getSilkHeld()-num);
|
||||
setMoney(getMoney() + num*silkPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("A")) {
|
||||
System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getArmsHeld() && num >= 0) {
|
||||
setArmsHeld(getArmsHeld()-num);
|
||||
setMoney(getMoney() + num*armsPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("G")) {
|
||||
System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getGeneralHeld() && num >= 0) {
|
||||
setGeneralHeld(getGeneralHeld()-num);
|
||||
setMoney(getMoney() + num*generalPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
duplicateLittiness(input);
|
||||
|
||||
} else if (response.equalsIgnoreCase("V")) {
|
||||
System.out.println("\n*** PLACEHOLDER FOR BANK ***\n");
|
||||
@@ -275,133 +151,10 @@ public class TaipanShop extends Player {
|
||||
System.out.println("\nShall I Buy, Sell, or Quit Trading?");
|
||||
String response = input.next();
|
||||
if (response.equalsIgnoreCase("B")) {
|
||||
boolean notDone2 = true;
|
||||
System.out.println("What do you wish me to buy, " + getName() + "?");
|
||||
while (notDone2) {
|
||||
response = input.nextLine();
|
||||
if (response.equalsIgnoreCase("O")) {
|
||||
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / opiumPrice && num >= 0) {
|
||||
setOpiumHeld(getOpiumHeld()+num);
|
||||
setMoney(getMoney() - num*opiumPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() / silkPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / silkPrice && num >= 0) {
|
||||
setSilkHeld(getSilkHeld()+num);
|
||||
setMoney(getMoney() - num*silkPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("A")) {
|
||||
System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() / armsPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / armsPrice && num >= 0) {
|
||||
setArmsHeld(getArmsHeld()+num);
|
||||
setMoney(getMoney() - num*armsPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("G")) {
|
||||
System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() / generalPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / generalPrice && num >= 0) {
|
||||
setGeneralHeld(getGeneralHeld()+num);
|
||||
setMoney(getMoney() - num*generalPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ayyy(input);
|
||||
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
boolean notDone2 = true;
|
||||
System.out.println("What do you wish me to sell, " + getName() + "?");
|
||||
while (notDone2) {
|
||||
response = input.nextLine();
|
||||
if (response.equalsIgnoreCase("O")) {
|
||||
System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getOpiumHeld() && num >= 0) {
|
||||
setOpiumHeld(getOpiumHeld()-num);
|
||||
setMoney(getMoney() + num*opiumPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getSilkHeld() && num >= 0) {
|
||||
setSilkHeld(getSilkHeld()-num);
|
||||
setMoney(getMoney() + num*silkPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("A")) {
|
||||
System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getArmsHeld() && num >= 0) {
|
||||
setArmsHeld(getArmsHeld()-num);
|
||||
setMoney(getMoney() + num*armsPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("G")) {
|
||||
System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getGeneralHeld() && num >= 0) {
|
||||
setGeneralHeld(getGeneralHeld()-num);
|
||||
setMoney(getMoney() + num*generalPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
duplicateLittiness(input);
|
||||
} else if (response.equalsIgnoreCase("Q")) {
|
||||
System.out.println("\n*** PLACEHOLDER FOR TRAVEL ***\n");
|
||||
notDone = false;
|
||||
@@ -410,6 +163,141 @@ public class TaipanShop extends Player {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void duplicateLittiness(Scanner input) {
|
||||
String response;
|
||||
boolean notDone2 = true;
|
||||
System.out.println("What do you wish me to sell, " + getName() + "?");
|
||||
while (notDone2) {
|
||||
response = input.nextLine();
|
||||
if (response.equalsIgnoreCase("O")) {
|
||||
System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getOpiumHeld() && num >= 0) {
|
||||
setOpiumHeld(getOpiumHeld()-num);
|
||||
setMoney(getMoney() + num*opiumPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getSilkHeld() && num >= 0) {
|
||||
setSilkHeld(getSilkHeld()-num);
|
||||
setMoney(getMoney() + num*silkPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("A")) {
|
||||
System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getArmsHeld() && num >= 0) {
|
||||
setArmsHeld(getArmsHeld()-num);
|
||||
setMoney(getMoney() + num*armsPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("G")) {
|
||||
System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getGeneralHeld() && num >= 0) {
|
||||
setGeneralHeld(getGeneralHeld()-num);
|
||||
setMoney(getMoney() + num*generalPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you don't have that many to sell!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void ayyy(Scanner input) {
|
||||
String response;
|
||||
boolean notDone2 = true;
|
||||
System.out.println("What do you wish me to buy, " + getName() + "?");
|
||||
while (notDone2) {
|
||||
response = input.nextLine();
|
||||
if (response.equalsIgnoreCase("O")) {
|
||||
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / opiumPrice && num >= 0) {
|
||||
setOpiumHeld(getOpiumHeld()+num);
|
||||
setMoney(getMoney() - num*opiumPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("S")) {
|
||||
System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() / silkPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / silkPrice && num >= 0) {
|
||||
setSilkHeld(getSilkHeld()+num);
|
||||
setMoney(getMoney() - num*silkPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("A")) {
|
||||
System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() / armsPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / armsPrice && num >= 0) {
|
||||
setArmsHeld(getArmsHeld()+num);
|
||||
setMoney(getMoney() - num*armsPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
||||
}
|
||||
}
|
||||
} else if (response.equalsIgnoreCase("G")) {
|
||||
System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() / generalPrice + ")");
|
||||
while (notDone2) {
|
||||
int num = input.nextInt();
|
||||
if (num <= getMoney() / generalPrice && num >= 0) {
|
||||
setGeneralHeld(getGeneralHeld()+num);
|
||||
setMoney(getMoney() - num*generalPrice);
|
||||
notDone2 = false;
|
||||
} else if (num >= 0) {
|
||||
System.out.println(getName() + ", you can't afford that!");
|
||||
} else {
|
||||
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
TaipanShop shop = new TaipanShop();
|
||||
shop.shop();
|
||||
|
||||
Reference in New Issue
Block a user