Update Travel.java
This commit is contained in:
@@ -1,64 +1,79 @@
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Travel extends Player {
|
||||
public class Travel {
|
||||
|
||||
private void seaAtlas(int locationOfTravel){
|
||||
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) {
|
||||
switch (locationOfTravel) {
|
||||
case 1:
|
||||
System.out.println("\nArriving at Hong Kong");
|
||||
setLocation(1);
|
||||
player.setLocation(1);
|
||||
break;
|
||||
case 2:
|
||||
System.out.println("\nArriving at Shanghai");
|
||||
setLocation(2);
|
||||
player.setLocation(2);
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("\nArriving at Nagasaki");
|
||||
setLocation(3);
|
||||
player.setLocation(3);
|
||||
break;
|
||||
case 4:
|
||||
System.out.println("\nArriving at Saigon");
|
||||
setLocation(4);
|
||||
player.setLocation(4);
|
||||
break;
|
||||
case 5:
|
||||
System.out.println("\nArriving at Manila");
|
||||
setLocation(5);
|
||||
player.setLocation(5);
|
||||
break;
|
||||
case 6:
|
||||
System.out.println("\nArriving at Singapore");
|
||||
setLocation(6);
|
||||
player.setLocation(6);
|
||||
break;
|
||||
case 7:
|
||||
System.out.println("\nArriving at Batavia");
|
||||
setLocation(7);
|
||||
player.setLocation(7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void randomEventSea(int locationOfTravel) throws Exception {
|
||||
ShipWarfare attackShip = new ShipWarfare();
|
||||
ShipWarfare attackShip = new ShipWarfare(player);
|
||||
Random rand = new Random();
|
||||
int randGenNum = rand.nextInt(3) + 1;
|
||||
if(randGenNum == 1){
|
||||
if (randGenNum == 1) {
|
||||
attackShip.peasantFleetAttack();
|
||||
}
|
||||
else if(randGenNum == 2){
|
||||
} else if (randGenNum == 2) {
|
||||
disaster(locationOfTravel);
|
||||
}
|
||||
System.out.println("We made it!");
|
||||
}
|
||||
|
||||
private void disaster(int locationOfTravel){
|
||||
System.out.print("Storm "+getName()+"! ");
|
||||
private void disaster(int locationOfTravel) {
|
||||
System.out.print("Storm " + player.getName() + "! ");
|
||||
Random rand = new Random();
|
||||
int randGenNum = rand.nextInt(5) + 1;
|
||||
|
||||
if(randGenNum <= 2){
|
||||
if (randGenNum <= 2) {
|
||||
System.out.println(" We made it through!");
|
||||
}
|
||||
else{
|
||||
while(randGenNum == locationOfTravel){
|
||||
} else {
|
||||
while (randGenNum == locationOfTravel) {
|
||||
randGenNum = rand.nextInt(7) + 1;
|
||||
if (randGenNum != locationOfTravel) {
|
||||
System.out.println("We've been blown off course!");
|
||||
@@ -68,36 +83,31 @@ public class Travel extends Player {
|
||||
}
|
||||
}
|
||||
|
||||
public void travelTo(){
|
||||
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("\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?");
|
||||
|
||||
response = keyboard.nextLine();
|
||||
try {
|
||||
tempInt = Integer.parseInt(response);
|
||||
System.out.println(tempInt + " " + getLocation());
|
||||
if(tempInt != getLocation()){
|
||||
System.out.println(tempInt + " " + player.getLocation());
|
||||
if (tempInt != player.getLocation()) {
|
||||
randomEventSea(tempInt);
|
||||
seaAtlas(tempInt);
|
||||
hasTraveled = true;
|
||||
}
|
||||
else System.out.println("\nYou're already here " + getName() + ".");
|
||||
} else System.out.println("\nYou're already here " + player.getName() + ".");
|
||||
} catch (Exception e) {
|
||||
System.out.print("\nSorry, " + player.getName() + " could you say that again?");
|
||||
}
|
||||
catch (Exception e){
|
||||
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
||||
if (hasTraveled) {
|
||||
break;
|
||||
}
|
||||
if(hasTraveled){break;}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
Travel ship = new Travel();
|
||||
ship.travelTo();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user