Merge remote-tracking branch 'origin/master'

# Conflicts:
#	.idea/workspace.xml
#	src/ShipWarfare.java
#	src/TaipanShop.java
This commit is contained in:
KahootChampion
2019-02-20 09:48:19 -07:00
3 changed files with 172 additions and 23 deletions

38
src/Bank.java Normal file
View File

@@ -0,0 +1,38 @@
import java.util.Scanner;
public class Bank extends Player {
public int promtMoney() {
int addVal = 0;
int retVal = 0;
System.out.println("Please enter an amount");
Scanner keyboard = new Scanner(System.in);
addVal = keyboard.nextInt();
if(addVal >= 0) {
retVal = addVal;
}
return retVal;
}
public void addMoney() {
int addMon = promtMoney();
if(addMon >= 0) {
setBank(promtMoney() + getMoney());
}
}
public void removeMoney() {
int subMon = promtMoney();
if(subMon <= getMoney()) {
setBank(subMon - getMoney());
}
}
public void addInterest() {
setBank((int)((getBank() * 1.05)));
}
}

View File

@@ -2,7 +2,6 @@ import java.util.Random;
import java.util.Scanner;
public class TaipanShop extends Player {
private Player player = new Player();
private int cargoSpace = 60;
private int currentCargo = 0;
private int opiumPrice = 16000;
@@ -10,58 +9,73 @@ public class TaipanShop extends Player {
private int armsPrice = 160;
private int generalPrice = 8;
public int getCargoSpace() {
return cargoSpace;
}
public void setCargoSpace(int cargoSpace) {
if(cargoSpace > 0){
this.cargoSpace = cargoSpace;
}
}
public int getOpiumPrice() {
return opiumPrice;
}
public void setOpiumPrice(int opiumPrice) {
if(opiumPrice > 0){
this.opiumPrice = opiumPrice;
}
}
public int getSilkPrice() {
return silkPrice;
}
public void setSilkPrice(int silkPrice) {
if(silkPrice > 0){
this.silkPrice = silkPrice;
}
}
public int getArmsPrice() {
return armsPrice;
}
public void setArmsPrice(int armsPrice) {
if(armsPrice > 0){
this.armsPrice = armsPrice;
}
}
public int getGeneralPrice() {
return generalPrice;
}
public void setGeneralPrice(int generalPrice) {
if(generalPrice > 0){
this.generalPrice = generalPrice;
}
}
private void updatePrices(){
String s = "\n" + getName() + ", the price of ";
double value = 80*Math.random();
Random rand = new Random();
setOpiumPrice((rand.nextInt(201) + 60)*100);
setSilkPrice((rand.nextInt(201) + 60)*10);
setArmsPrice((rand.nextInt(21) + 6)*10);
setGeneralPrice(rand.nextInt(17) + 4);
opiumPrice = (rand.nextInt(201) + 60)*100;
silkPrice = (rand.nextInt(201) + 60)*10;
armsPrice = (rand.nextInt(21) + 6)*10;
generalPrice = rand.nextInt(17) + 4;
if(value < 8){
if(value < 2){
if(value < 1){
setOpiumPrice(getOpiumPrice()/5);
System.out.println(s + "Opium has dropped to " + getOpiumPrice() +"!!!\n");
opiumPrice /= 5;
System.out.println(s + "Opium has dropped to " + opiumPrice +"!!!\n");
}else{
setOpiumPrice(getOpiumPrice()*5);
System.out.println(s + "Opium has risen to " + getOpiumPrice() +"!!!\n");
opiumPrice *= 5;
System.out.println(s + "Opium has risen to " + opiumPrice +"!!!\n");
}
}else if(value < 4){
if(value < 3){
silkPrice /= 5;
@@ -396,12 +410,8 @@ public class TaipanShop extends Player {
}
}
public static void main(String[] args){
TaipanShop shop = new TaipanShop();
shop.shop();
}
}

View File

@@ -1,2 +1,103 @@
public class Travel {
import java.util.Random;
import java.util.Scanner;
public class Travel extends Player {
private void seaAtlas(int locationOfTravel){
switch (locationOfTravel) {
case 1:
System.out.println("\nArriving at Hong Kong");
setLocation(1);
break;
case 2:
System.out.println("\nArriving at Shanghai");
setLocation(2);
break;
case 3:
System.out.println("\nArriving at Nagasaki");
setLocation(3);
break;
case 4:
System.out.println("\nArriving at Saigon");
setLocation(4);
break;
case 5:
System.out.println("\nArriving at Manila");
setLocation(5);
break;
case 6:
System.out.println("\nArriving at Singapore");
setLocation(6);
break;
case 7:
System.out.println("\nArriving at Batavia");
setLocation(7);
break;
}
}
private void randomEventSea(int locationOfTravel) throws Exception {
ShipWarfare attackShip = new ShipWarfare();
Random rand = new Random();
int randGenNum = rand.nextInt(3) + 1;
if(randGenNum == 1){
attackShip.peasantFleetAttack();
}
else if(randGenNum == 2){
disaster(locationOfTravel);
}
System.out.println("We made it!");
}
private void disaster(int locationOfTravel){
System.out.print("Storm "+getName()+"! ");
Random rand = new Random();
int randGenNum = rand.nextInt(5) + 1;
if(randGenNum <= 2){
System.out.println(" We made it through!");
}
else{
while(randGenNum == locationOfTravel){
randGenNum = rand.nextInt(7) + 1;
if (randGenNum != locationOfTravel) {
System.out.println("We've been blown off course!");
seaAtlas(randGenNum);
}
}
}
}
public void travelTo(){
Scanner keyboard = new Scanner(System.in);
String response;
int tempInt;
boolean hasTraveled = false;
while (true) {
System.out.println("\n" + 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?");
response = keyboard.nextLine();
try {
tempInt = Integer.parseInt(response);
System.out.println(tempInt + " " + getLocation());
if(tempInt != getLocation()){
randomEventSea(tempInt);
seaAtlas(tempInt);
hasTraveled = true;
}
else System.out.println("\nYou're already here " + getName() + ".");
}
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();
}
}