Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/ShipWarfare.java
#	src/TaipanShop.java
This commit is contained in:
KahootChampion
2019-02-21 23:44:57 -07:00
5 changed files with 501 additions and 199 deletions

View File

@@ -11,6 +11,21 @@ public class Player {
private int guns = 3; private int guns = 3;
private int HP = 100; private int HP = 100;
public Player(){
}
public Player(Player player){
this.bank = player.bank;
this.money = player.money;
this.opiumHeld = player.opiumHeld;
this.silkHeld = player.silkHeld;
this.generalHeld = player.generalHeld;
this.armsHeld = player.armsHeld;
this.location = player.location;
this.guns = player.guns;
this.HP = player.HP;
}
public String getName() { public String getName() {
return name; return name;
@@ -115,15 +130,4 @@ public class Player {
System.out.println("Game over"); System.out.println("Game over");
} }
public static void main(String[] args) throws Exception {
ShipWarfare littyWarfare = new ShipWarfare();
TaipanShop littyShop = new TaipanShop();
littyShop.shop();
littyWarfare.peasantFleetAttack();
littyShop.shop();
}
} }

View File

@@ -1,7 +1,8 @@
import java.util.Random; import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
public class TaipanShop extends Player { public class TaipanShop {
private Player player;
private int cargoSpace = 60; private int cargoSpace = 60;
private int currentCargo = 0; private int currentCargo = 0;
private int opiumPrice = 16000; private int opiumPrice = 16000;
@@ -9,6 +10,21 @@ public class TaipanShop extends Player {
private int armsPrice = 160; private int armsPrice = 160;
private int generalPrice = 8; private int generalPrice = 8;
public void setPlayer(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public Player getPlayer(){
Player playerDummy = new Player(player);
return playerDummy;
}
public TaipanShop(Player player){
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public int getCargoSpace() { public int getCargoSpace() {
return cargoSpace; return cargoSpace;
} }
@@ -60,7 +76,7 @@ public class TaipanShop extends Player {
} }
private void updatePrices(){ private void updatePrices(){
String s = "\n" + getName() + ", the price of "; String s = "\n" + player.getName() + ", the price of ";
double value = 80*Math.random(); double value = 80*Math.random();
Random rand = new Random(); Random rand = new Random();
opiumPrice = (rand.nextInt(201) + 60)*100; opiumPrice = (rand.nextInt(201) + 60)*100;
@@ -105,18 +121,18 @@ public class TaipanShop extends Player {
} }
private void printShop(){ private void printShop(){
currentCargo = getOpiumHeld()+getGuns()*10+getSilkHeld()+getArmsHeld()+getGeneralHeld(); currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld();
if(cargoSpace - currentCargo < 0){ if(cargoSpace - currentCargo < 0){
System.out.println("Hold: Overloaded" + " Guns: " + getGuns()); System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns());
}else{ }else{
System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + getGuns()); System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + player.getGuns());
} }
System.out.println("-------------------------------------------------------------"); System.out.println("-------------------------------------------------------------");
System.out.println(" Opium: " + getOpiumHeld() + " Silk: " + getSilkHeld()); System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld());
System.out.println(" Arms: " + getArmsHeld() + " General: " + getGeneralHeld()); System.out.println(" Arms: " + player.getArmsHeld() + " General: " + player.getGeneralHeld());
System.out.println("-------------------------------------------------------------"); System.out.println("-------------------------------------------------------------");
System.out.println("Cash: " + getMoney() + " Bank: " + getBank()+"\n"); System.out.println("Cash: " + player.getMoney() + " Bank: " + player.getBank()+"\n");
System.out.println(getName() + ", present prices per unit here are:"); System.out.println(player.getName() + ", present prices per unit here are:");
System.out.println(" Opium: " + opiumPrice + " Silk: " + silkPrice); System.out.println(" Opium: " + opiumPrice + " Silk: " + silkPrice);
System.out.println(" Arms: " + armsPrice + " General: " + generalPrice); System.out.println(" Arms: " + armsPrice + " General: " + generalPrice);
} }
@@ -125,16 +141,140 @@ public class TaipanShop extends Player {
updatePrices(); updatePrices();
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
boolean notDone = true; boolean notDone = true;
if (getLocation() == 1) { if (player.getLocation() == 1) {
while (notDone) { while (notDone) {
printShop(); printShop();
System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, or Quit Trading?"); System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, or Quit Trading?");
String response = input.next(); String response = input.next();
if (response.equalsIgnoreCase("B")) { if (response.equalsIgnoreCase("B")) {
ayyy(input); boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney()-num * opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney()-num * silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} else if (response.equalsIgnoreCase("S")) { } else if (response.equalsIgnoreCase("S")) {
duplicateLittiness(input); boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} else if (response.equalsIgnoreCase("V")) { } else if (response.equalsIgnoreCase("V")) {
System.out.println("\n*** PLACEHOLDER FOR BANK ***\n"); System.out.println("\n*** PLACEHOLDER FOR BANK ***\n");
@@ -151,10 +291,133 @@ public class TaipanShop extends Player {
System.out.println("\nShall I Buy, Sell, or Quit Trading?"); System.out.println("\nShall I Buy, Sell, or Quit Trading?");
String response = input.next(); String response = input.next();
if (response.equalsIgnoreCase("B")) { if (response.equalsIgnoreCase("B")) {
ayyy(input); boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney() - num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney() - num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} else if (response.equalsIgnoreCase("S")) { } else if (response.equalsIgnoreCase("S")) {
duplicateLittiness(input); boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
}
} else if (response.equalsIgnoreCase("Q")) { } else if (response.equalsIgnoreCase("Q")) {
System.out.println("\n*** PLACEHOLDER FOR TRAVEL ***\n"); System.out.println("\n*** PLACEHOLDER FOR TRAVEL ***\n");
notDone = false; notDone = false;
@@ -163,143 +426,4 @@ 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();
}
} }

View File

@@ -1,63 +1,78 @@
import java.util.Random; import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
public class Travel extends Player { public class Travel {
private Player player;
public void Player(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
public Player getPlayer() {
Player playerDummy = new Player(player);
return playerDummy;
}
public Travel(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
private void seaAtlas(int locationOfTravel) { private void seaAtlas(int locationOfTravel) {
switch (locationOfTravel) { switch (locationOfTravel) {
case 1: case 1:
System.out.println("\nArriving at Hong Kong"); System.out.println("\nArriving at Hong Kong");
setLocation(1); player.setLocation(1);
break; break;
case 2: case 2:
System.out.println("\nArriving at Shanghai"); System.out.println("\nArriving at Shanghai");
setLocation(2); player.setLocation(2);
break; break;
case 3: case 3:
System.out.println("\nArriving at Nagasaki"); System.out.println("\nArriving at Nagasaki");
setLocation(3); player.setLocation(3);
break; break;
case 4: case 4:
System.out.println("\nArriving at Saigon"); System.out.println("\nArriving at Saigon");
setLocation(4); player.setLocation(4);
break; break;
case 5: case 5:
System.out.println("\nArriving at Manila"); System.out.println("\nArriving at Manila");
setLocation(5); player.setLocation(5);
break; break;
case 6: case 6:
System.out.println("\nArriving at Singapore"); System.out.println("\nArriving at Singapore");
setLocation(6); player.setLocation(6);
break; break;
case 7: case 7:
System.out.println("\nArriving at Batavia"); System.out.println("\nArriving at Batavia");
setLocation(7); player.setLocation(7);
break; break;
} }
} }
private void randomEventSea(int locationOfTravel) throws Exception { private void randomEventSea(int locationOfTravel) throws Exception {
ShipWarfare attackShip = new ShipWarfare(); ShipWarfare attackShip = new ShipWarfare(player);
Random rand = new Random(); Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1; int randGenNum = rand.nextInt(3) + 1;
if (randGenNum == 1) { if (randGenNum == 1) {
attackShip.peasantFleetAttack(); attackShip.peasantFleetAttack();
} } else if (randGenNum == 2) {
else if(randGenNum == 2){
disaster(locationOfTravel); disaster(locationOfTravel);
} }
System.out.println("We made it!"); System.out.println("We made it!");
} }
private void disaster(int locationOfTravel) { private void disaster(int locationOfTravel) {
System.out.print("Storm "+getName()+"! "); System.out.print("Storm " + player.getName() + "! ");
Random rand = new Random(); Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1; int randGenNum = rand.nextInt(5) + 1;
if (randGenNum <= 2) { if (randGenNum <= 2) {
System.out.println(" We made it through!"); System.out.println(" We made it through!");
} } else {
else{
while (randGenNum == locationOfTravel) { while (randGenNum == locationOfTravel) {
randGenNum = rand.nextInt(7) + 1; randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) { if (randGenNum != locationOfTravel) {
@@ -75,29 +90,24 @@ public class Travel extends Player {
boolean hasTraveled = false; boolean hasTraveled = false;
while (true) { while (true) {
System.out.println("\n" + getName() + ", do you wish to go to:\n"); System.out.println("\n" + player.getName() + ", do you wish to go to:\n");
System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?"); System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?");
response = keyboard.nextLine(); response = keyboard.nextLine();
try { try {
tempInt = Integer.parseInt(response); tempInt = Integer.parseInt(response);
System.out.println(tempInt + " " + getLocation()); System.out.println(tempInt + " " + player.getLocation());
if(tempInt != getLocation()){ if (tempInt != player.getLocation()) {
randomEventSea(tempInt); randomEventSea(tempInt);
seaAtlas(tempInt); seaAtlas(tempInt);
hasTraveled = true; hasTraveled = true;
} else System.out.println("\nYou're already here " + player.getName() + ".");
} catch (Exception e) {
System.out.print("\nSorry, " + player.getName() + " could you say that again?");
} }
else System.out.println("\nYou're already here " + getName() + "."); if (hasTraveled) {
} break;
catch (Exception e){
System.out.print("\nSorry, " + getName() + " could you say that again?");
}
if(hasTraveled){break;}
} }
} }
public static void main(String[] args){
Travel ship = new Travel();
ship.travelTo();
} }
} }

136
src/Warehouse.java Normal file
View File

@@ -0,0 +1,136 @@
import java.util.Scanner;
public class Warehouse extends Player {
private int wOpium = 25;
private int wSilk = 0;
private int wGeneral = 0;
private int wArms = 0;
private String good = "";
private int finalAmount = 0;
public void addAmount(String good, int amount) {
int held = 0;
if (amount > 0) {
if (this.good.equalsIgnoreCase("O")) {
this.wOpium += amount;
held = getOpiumHeld();
setOpiumHeld(held - amount);
System.out.println(getOpiumHeld());
}
else if(this.good.equalsIgnoreCase("S")) {
this.wSilk += amount;
held = getSilkHeld();
setSilkHeld(held - amount);
}
else if(this.good.equalsIgnoreCase("G")) {
this.wGeneral += amount;
held = getGeneralHeld();
setGeneralHeld(held - amount);
}
else if(this.good.equalsIgnoreCase("A")) {
this.wArms += amount;
held = getArmsHeld();
setArmsHeld(held - amount);
}
}
else {
System.out.println("Sorry this transfer cannot be made");
}
}
public void removeAmount(String good, int amount) {
int held = 0;
if (amount > 0) {
if (this.good.equalsIgnoreCase("O")) {
this.wOpium -= amount;
held = getOpiumHeld();
setOpiumHeld(held + amount);
}
else if(this.good.equalsIgnoreCase("S")) {
this.wSilk -= amount;
held = getSilkHeld();
setSilkHeld(held + amount);
}
else if(this.good.equalsIgnoreCase("G")) {
this.wGeneral -= amount;
held = getGeneralHeld();
setGeneralHeld(held + amount);
}
else if(this.good.equalsIgnoreCase("A")) {
this.wArms -= amount;
held = getArmsHeld();
setArmsHeld(held + amount);
}
}
else {
System.out.println("Sorry this transfer cannot be made");
}
}
public void showWarehouse() {
System.out.println("Opium : " + this.wOpium);
System.out.println("Silk : " + this.wSilk);
System.out.println("General : " + this.wGeneral);
System.out.println("Arms : " + this.wArms);
}
private void askGood() {
String aGood = "k";
System.out.println("Please enter a good to transfer O, S, G, A :");
Scanner keyboard = new Scanner(System.in);
aGood = keyboard.nextLine();
aGood = aGood.toUpperCase();
this.good = aGood;
}
public void askAddAmount() {
askGood();
int amount = 0;
System.out.println("Please enter the amount of the good you would like to transfer, put negative amount to remove");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextInt();
if(this.good.equalsIgnoreCase("O") && amount <= getOpiumHeld()) {
finalAmount = amount;
}
else if(this.good.equalsIgnoreCase("S") && amount <= getSilkHeld()) {
finalAmount = amount;
}
else if(this.good.equalsIgnoreCase("G") && amount <= getGeneralHeld()) {
finalAmount = amount;
}
else if(this.good.equalsIgnoreCase("A") && amount <= getArmsHeld()) {
finalAmount = amount;
}
}
public void askRemoveAmount() {
askGood();
int amount = 0;
System.out.println("Please enter the amount of the good you would like to remove");
Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextInt();
if(this.good.equalsIgnoreCase("O") && amount <= this.wOpium) {
finalAmount = amount;
}
else if(this.good.equalsIgnoreCase("S") && amount <= this.wSilk) {
finalAmount = amount;
}
else if(this.good.equalsIgnoreCase("G") && amount <= this.wGeneral) {
finalAmount = amount;
}
else if(this.good.equalsIgnoreCase("A") && amount <= this.wArms) {
finalAmount = amount;
}
}
public static void main(String[] args){
Warehouse hi = new Warehouse();
hi.showWarehouse();
hi.askRemoveAmount();
hi.removeAmount(hi.good, hi.finalAmount);
hi.showWarehouse();
hi.askAddAmount();
hi.addAmount(hi.good, hi.finalAmount);
hi.showWarehouse();
}
}

28
src/main.java Normal file
View File

@@ -0,0 +1,28 @@
public class main {
private static Player player = new Player();
public void shop(TaipanShop shop){
shop.setPlayer(player);
shop.shop();
player = shop.getPlayer();
}
public void peasantFleet(ShipWarfare warfare) throws Exception {
warfare.setPlayer(player);
warfare.peasantFleetAttack();
player = warfare.getPlayer();
}
public static void main(String[] args) throws Exception {
main main = new main();
ShipWarfare littyWarfare = new ShipWarfare(player);
TaipanShop littyShop = new TaipanShop(player);
main.shop(littyShop);
main.peasantFleet(littyWarfare);
main.shop(littyShop);
}
}