Added disasters as well as removing a bug from the flee method in Haris's code
This commit is contained in:
@@ -24,7 +24,6 @@ public class ShipWarfare extends Player {
|
|||||||
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("r")) {
|
} else if (response.equalsIgnoreCase("r")) {
|
||||||
runFromShips();
|
|
||||||
if(runFromShips()==true){
|
if(runFromShips()==true){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
129
src/Travel.java
129
src/Travel.java
@@ -3,6 +3,65 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class Travel extends Player {
|
public class Travel extends Player {
|
||||||
|
|
||||||
|
private void seaAtlas(int locationOfTravel){
|
||||||
|
setLocation(locationOfTravel);
|
||||||
|
switch (locationOfTravel) {
|
||||||
|
case 1:
|
||||||
|
System.out.println("\nArriving at Hong Kong");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
System.out.println("\nArriving at Shanghai");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
System.out.println("\nArriving at Nagasaki");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
System.out.println("\nArriving at Saigon");
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
System.out.println("\nArriving at Manila");
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
System.out.println("\nArriving at Singapore");
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
System.out.println("\nArriving at Batavia");
|
||||||
|
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(){
|
public void travelTo(){
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
String response;
|
String response;
|
||||||
@@ -17,81 +76,19 @@ public class Travel extends Player {
|
|||||||
try {
|
try {
|
||||||
tempInt = Integer.parseInt(response);
|
tempInt = Integer.parseInt(response);
|
||||||
if(tempInt != getLocation()){
|
if(tempInt != getLocation()){
|
||||||
switch (tempInt) {
|
randomEventSea(tempInt);
|
||||||
case 1:
|
seaAtlas(tempInt);
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Hong Kong");
|
|
||||||
setLocation(1);
|
|
||||||
hasTraveled = true;
|
hasTraveled = true;
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Shanghai");
|
|
||||||
setLocation(2);
|
|
||||||
hasTraveled = true;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Nagasaki");
|
|
||||||
setLocation(3);
|
|
||||||
hasTraveled = true;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Saigon");
|
|
||||||
setLocation(4);
|
|
||||||
hasTraveled = true;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Manila");
|
|
||||||
setLocation(5);
|
|
||||||
hasTraveled = true;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Singapore");
|
|
||||||
setLocation(6);
|
|
||||||
hasTraveled = true;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
randomEventSea();
|
|
||||||
System.out.println("\nArriving at Batavia");
|
|
||||||
setLocation(7);
|
|
||||||
hasTraveled = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
else System.out.println("\nYou're already here " + getName() + ".");
|
||||||
else System.out.println("\nYou're already here Taipan.");
|
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
System.out.print("\nSorry, Taipan could you say that again?");
|
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
||||||
}
|
}
|
||||||
if(hasTraveled){break;}
|
if(hasTraveled){break;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void randomEventSea() throws Exception {
|
|
||||||
ShipWarfare attackShip = new ShipWarfare();
|
|
||||||
Random rand = new Random();
|
|
||||||
int randGenNum = rand.nextInt(2) + 1;
|
|
||||||
System.out.println("\n");
|
|
||||||
|
|
||||||
if(randGenNum == 1){
|
|
||||||
attackShip.peasantFleetAttack();
|
|
||||||
System.out.println("We made it " + getName());
|
|
||||||
}
|
|
||||||
else if(randGenNum == 2){
|
|
||||||
disaster();
|
|
||||||
System.out.println("We made it " + getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disaster(){
|
|
||||||
System.out.println("Storm Taipan!");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
Travel ship = new Travel();
|
Travel ship = new Travel();
|
||||||
ship.travelTo();
|
ship.travelTo();
|
||||||
|
|||||||
Reference in New Issue
Block a user