Fixed the commenting on a lot of the code. Also added some stuff to Travel, fixed some bugs.
This commit is contained in:
Binary file not shown.
@@ -419,9 +419,10 @@ public class Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to indicate that you have lost the game
|
* Method to indicate that you have lost the game. If the player has lost, console will be cleared and will only
|
||||||
*
|
* show the statement "Game Over". After showing the message the game closes.
|
||||||
*/
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
public void gameOver(){
|
public void gameOver(){
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ public class Start
|
|||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getter method for obtaining a player object.
|
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
|
||||||
*
|
*
|
||||||
* @return returns object of the class Player
|
* @return playerDummy -- playerDummy is a copy of the player instance variable.
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
Player playerTemp = new Player(player);
|
Player playerTemp = new Player(player);
|
||||||
@@ -14,9 +14,9 @@ public class Start
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setter method that takes in a Player object as an argument.
|
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
|
||||||
*
|
*
|
||||||
* @param player takes object of the class Player as an argument
|
* @param player is a Player object that will replace the current instance of the player instance variable.
|
||||||
*/
|
*/
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
Player playerTemp = new Player(player);
|
Player playerTemp = new Player(player);
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ public class TaipanShop {
|
|||||||
public void retire(){
|
public void retire(){
|
||||||
player.setRetire(true);
|
player.setRetire(true);
|
||||||
System.out.println("You win!");
|
System.out.println("You win!");
|
||||||
if(player.playAgain()){
|
System.exit(0);
|
||||||
setPlayer(new Player());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
113
src/Travel.java
113
src/Travel.java
@@ -5,21 +5,42 @@ public class Travel {
|
|||||||
|
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will replace the current instance of the player instance variable.
|
||||||
|
*/
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
this.player = playerDummy;
|
this.player = playerDummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for obtaining a player object.
|
||||||
|
*
|
||||||
|
* @return returns player object
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
return playerDummy;
|
return playerDummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
public Travel(Player player) {
|
public Travel(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
this.player = playerDummy;
|
this.player = playerDummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When provided a location number: the method returns a print statement stating the location's name and call another
|
||||||
|
* method to change the location of the Player object.
|
||||||
|
*
|
||||||
|
* @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
private void seaAtlas(int locationOfTravel) {
|
private void seaAtlas(int locationOfTravel) {
|
||||||
switch (locationOfTravel) {
|
switch (locationOfTravel) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -53,25 +74,43 @@ public class Travel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing.
|
||||||
|
*
|
||||||
|
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||||
|
* by a typhoon.
|
||||||
|
**/
|
||||||
private void randomEventSea(int locationOfTravel) throws Exception {
|
private void randomEventSea(int locationOfTravel) throws Exception {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
int randGenNum = rand.nextInt(4) + 1;
|
||||||
if (randGenNum == 1) {
|
if (randGenNum == 1) {
|
||||||
peasantFleet();
|
peasantFleet();
|
||||||
} else if (randGenNum == 2) {
|
}else if (randGenNum == 2){
|
||||||
|
littyFleet();
|
||||||
|
}else if (randGenNum == 3) {
|
||||||
disaster(locationOfTravel);
|
disaster(locationOfTravel);
|
||||||
|
System.out.println("We made it!");
|
||||||
}
|
}
|
||||||
System.out.println("We made it!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on random chance either throws the player character off course, or continues them on their way to their
|
||||||
|
* destination.
|
||||||
|
*
|
||||||
|
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||||
|
* by a typhoon.
|
||||||
|
**/
|
||||||
private void disaster(int locationOfTravel) {
|
private void disaster(int locationOfTravel) {
|
||||||
|
//Tells player that there is a storm approaching.
|
||||||
System.out.print("Storm " + player.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 the player lands within this range, nothing happens to them
|
||||||
|
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
|
||||||
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) {
|
||||||
@@ -82,39 +121,67 @@ public class Travel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To use the peasant fleet class while still maintaining encapsulation we have to create a ShipWarefare object and
|
||||||
|
* run the method from there. After the method has been run we can update the player object in this class.
|
||||||
|
*
|
||||||
|
**/
|
||||||
public void peasantFleet() throws Exception {
|
public void peasantFleet() throws Exception {
|
||||||
ShipWarfare attackShip = new ShipWarfare(player);
|
ShipWarfare attackShip = new ShipWarfare(player);
|
||||||
attackShip.peasantFleetAttack();
|
attackShip.peasantFleetAttack();
|
||||||
player = attackShip.getPlayer();
|
player = attackShip.getPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To use the litty fleet class while still maintaining encapsulation we have to create a ShipWarefare object and
|
||||||
|
* run the method from there. After the method has been run we can update the player object in this class.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
public void littyFleet() throws Exception {
|
||||||
|
ShipWarfare attackShip = new ShipWarfare(player);
|
||||||
|
attackShip.littyFleetAttack();
|
||||||
|
player = attackShip.getPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Used to travel between different areas inside of the game world.
|
||||||
|
* If the player's inventory is too full it won't run.
|
||||||
|
* Also calculates loan and bank interest between the jumps between islands.
|
||||||
|
**/
|
||||||
public void travelTo() {
|
public void travelTo() {
|
||||||
Scanner keyboard = new Scanner(System.in);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
String response;
|
String response;
|
||||||
int tempInt;
|
int tempInt;
|
||||||
boolean hasTraveled = false;
|
boolean hasTraveled = false;
|
||||||
|
|
||||||
while (true) {
|
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
|
||||||
System.out.println("\n" + player.getName() + ", do you wish to go to:\n");
|
if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
|
||||||
System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?");
|
while (true) {
|
||||||
|
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();
|
response = keyboard.nextLine();
|
||||||
try {
|
//Just in case the player types something that was not intended. It will refresh the question and ask it again
|
||||||
tempInt = Integer.parseInt(response);
|
try {
|
||||||
System.out.println(tempInt + " " + player.getLocation());
|
tempInt = Integer.parseInt(response);
|
||||||
if (tempInt != player.getLocation()) {
|
//Makes sure you can't travel to your own location.
|
||||||
randomEventSea(tempInt);
|
if (tempInt != player.getLocation()) {
|
||||||
seaAtlas(tempInt);
|
randomEventSea(tempInt);
|
||||||
hasTraveled = true;
|
seaAtlas(tempInt);
|
||||||
player.setBank((int)(player.getBank() * 1.01));
|
hasTraveled = true;
|
||||||
player.setDebt((int)(player.getDebt() * 1.01));
|
player.setBank((int) (player.getBank() * 1.01));
|
||||||
} else System.out.println("\nYou're already here " + player.getName() + ".");
|
player.setDebt((int) (player.getDebt() * 1.01));
|
||||||
} catch (Exception e) {
|
} else System.out.println("\nYou're already here " + player.getName() + ".");
|
||||||
System.out.print("\nSorry, " + player.getName() + " could you say that again?");
|
} catch (Exception e) {
|
||||||
}
|
System.out.print("\nSorry, " + player.getName() + " could you say that again?");
|
||||||
if (hasTraveled) {
|
}
|
||||||
break;
|
if (hasTraveled) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
System.out.println(player.getName() + " the cargo is too heavy! We can't set sail!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ public class main {
|
|||||||
/**
|
/**
|
||||||
* Updates main class with player data and starts the game.
|
* Updates main class with player data and starts the game.
|
||||||
* The game will only run as long as the player has not retired or has been destroyed.
|
* The game will only run as long as the player has not retired or has been destroyed.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
main main = new main();
|
main main = new main();
|
||||||
TaipanShop littyShop = new TaipanShop(main.getPlayer());
|
TaipanShop littyShop = new TaipanShop(main.getPlayer());
|
||||||
|
|||||||
Reference in New Issue
Block a user