From 568f2b5b9d7ece82611124054a3f7569db2f0ae7 Mon Sep 17 00:00:00 2001 From: Solargale Date: Tue, 19 Feb 2019 17:49:09 -0700 Subject: [PATCH] Added disasters as well as removing a bug from the flee method in Haris's code --- src/ShipWarfare.java | 1 - src/Travel.java | 131 +++++++++++++++++++++---------------------- 2 files changed, 64 insertions(+), 68 deletions(-) diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java index 428ea84..5f5ef03 100644 --- a/src/ShipWarfare.java +++ b/src/ShipWarfare.java @@ -24,7 +24,6 @@ public class ShipWarfare extends Player { } else if (response.equalsIgnoreCase("r")) { - runFromShips(); if(runFromShips()==true){ break; } diff --git a/src/Travel.java b/src/Travel.java index 0a4ca30..9e22f0b 100644 --- a/src/Travel.java +++ b/src/Travel.java @@ -3,6 +3,65 @@ import java.util.Scanner; 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(){ Scanner keyboard = new Scanner(System.in); String response; @@ -17,81 +76,19 @@ public class Travel extends Player { try { tempInt = Integer.parseInt(response); if(tempInt != getLocation()){ - switch (tempInt) { - case 1: - randomEventSea(); - System.out.println("\nArriving at Hong Kong"); - setLocation(1); - 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; - } + randomEventSea(tempInt); + seaAtlas(tempInt); + hasTraveled = true; } - else System.out.println("\nYou're already here Taipan."); + else System.out.println("\nYou're already here " + getName() + "."); } 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;} } } - 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){ Travel ship = new Travel(); ship.travelTo();