Redid a bunch of commenting making sure that every method was commented.
This commit is contained in:
@@ -1,4 +1,31 @@
|
||||
package logic;
|
||||
|
||||
public class BankLogic extends Player {
|
||||
|
||||
/**
|
||||
* 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 BankLogic(Player player) {
|
||||
Player playerDummy = new Player(player);
|
||||
setPlayer(playerDummy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraws a set amount of money from the player's bank account and gives it to the player
|
||||
* @param withdraw the amount of money which the player is withdrawing
|
||||
*/
|
||||
public void withdrawing(int withdraw) {
|
||||
setMoney(withdraw + getMoney());
|
||||
setBank(getBank() - withdraw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deposits a set amount of money from the player to the player's bank account
|
||||
* @param deposit the amount of money which the player is depositing
|
||||
*/
|
||||
public void depositing(int deposit) {
|
||||
setBank(deposit + getBank());
|
||||
setMoney(getMoney() - deposit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,28 +9,36 @@ import java.io.*;
|
||||
|
||||
public class FileSaving extends Player implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
*loads the file of type player which contains all the player instances
|
||||
* loads the file of type player which contains all the player instances
|
||||
* @return player
|
||||
*/
|
||||
public Player loadFile() {
|
||||
|
||||
try {
|
||||
//Load the previous save file
|
||||
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
||||
return getPlayer(in);
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
//Loads the player save in a alternate location if the original location isn't available
|
||||
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
|
||||
return getPlayer(in);
|
||||
}
|
||||
catch(Exception e2){
|
||||
//Only it's impossible for the player to load a file
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only run inside this class, returns save files. Throws exceptions if it fails
|
||||
* @param in The input stream from the previous save(If there is one)
|
||||
* @return Returns the player object from the previous save file
|
||||
* @throws IOException Only if the file cannot be read
|
||||
* @throws ClassNotFoundException Only if there is no file available for the player to load
|
||||
*/
|
||||
private Player getPlayer(InputStream in) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream inObject = new ObjectInputStream(in);
|
||||
Player player = (Player) inObject.readObject();
|
||||
@@ -45,6 +53,7 @@ public class FileSaving extends Player implements Serializable {
|
||||
*/
|
||||
public boolean saveFile(Player player){
|
||||
try{
|
||||
//Saves the object to a file
|
||||
FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt"));
|
||||
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
||||
outObject.writeObject(player);
|
||||
@@ -52,20 +61,23 @@ public class FileSaving extends Player implements Serializable {
|
||||
out.close();
|
||||
outObject.close();
|
||||
|
||||
//returns true if program can save file
|
||||
//returns true if program can save the file
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
//If the player is running from the terminal it changes the files location, this catch statement fixes that
|
||||
FileOutputStream out = new FileOutputStream(new File("saves/playerSave.txt"));
|
||||
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
||||
outObject.writeObject(player);
|
||||
|
||||
out.close();
|
||||
outObject.close();
|
||||
//returns true if the program can save the file
|
||||
return true;
|
||||
}
|
||||
catch(Exception e2){
|
||||
//returns false if it's impossible for the player to save the file
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package logic;
|
||||
|
||||
public class GameEndLogic extends Player{
|
||||
|
||||
/**
|
||||
* Calculates the networth of the player by the end of the game
|
||||
* Calculates the networth of the player by the end of the game.
|
||||
* Calculation is based off the total guns and items bought throughout the game
|
||||
* @return the total networth of the player
|
||||
*/
|
||||
public int getNetWorth() {
|
||||
@@ -24,4 +26,13 @@ public class GameEndLogic extends Player{
|
||||
return "Congratulations!";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method that creates an array filled will all the user's stats
|
||||
* @param netWorthInt the total net worth of the user
|
||||
* @return Returns the firm name of the user, the guns they held and their total net worth
|
||||
*/
|
||||
public String[] endGameStats(int netWorthInt) {
|
||||
return new String[]{"Firm Name: " + getName(), "Guns Held: " + getGuns(), "Net Worth: " + netWorthInt};
|
||||
}
|
||||
}
|
||||
|
||||
24
src/logic/LoanSharkLogic.java
Normal file
24
src/logic/LoanSharkLogic.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package logic;
|
||||
|
||||
public class LoanSharkLogic extends Player{
|
||||
|
||||
/**
|
||||
* 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 LoanSharkLogic(Player player) {
|
||||
Player playerDummy = new Player(player);
|
||||
setPlayer(playerDummy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to set and change loans for the Player
|
||||
* @param debt the amount of money the loan is for
|
||||
* @param money How much money is either taken or give to the Player
|
||||
*/
|
||||
public void changeLoan(int debt, int money) {
|
||||
setDebt(debt);
|
||||
setMoney(money);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ public class RandomEventLogic extends Player{
|
||||
|
||||
/**
|
||||
* 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 RandomEventLogic(Player player) {
|
||||
@@ -15,9 +14,9 @@ public class RandomEventLogic extends Player{
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that generates a random number and based on that number, a random event happens.
|
||||
*
|
||||
*/
|
||||
* Method that generates a random number and based on that number, a random event happens.
|
||||
* @return randGenNum and itemPrice, randGen number is the number which dictates the event, the item price is how much it will cost
|
||||
*/
|
||||
public int[] randEvent() {
|
||||
Random rand = new Random();
|
||||
int itemPrice;
|
||||
@@ -39,6 +38,7 @@ public class RandomEventLogic extends Player{
|
||||
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
||||
break;
|
||||
}
|
||||
//Forces random event to be gun related if nothing else is avaliable
|
||||
else {
|
||||
randGenNum = 2;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ public class ShipWarfareLogic extends Player {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ public class StartLogic extends Player {
|
||||
|
||||
/**
|
||||
* 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 StartLogic(Player player) {
|
||||
@@ -13,9 +12,9 @@ public class StartLogic extends Player {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in the Start Class
|
||||
* method that sets the player's money and debt to 400 and 5000 respectively.
|
||||
* also sets the player's guns to 0.
|
||||
*
|
||||
*/
|
||||
public void money_and_debt() {
|
||||
setMoney(400);
|
||||
@@ -24,17 +23,17 @@ public class StartLogic extends Player {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in the Start Class
|
||||
* method that sets the player's guns to 5.
|
||||
*
|
||||
*/
|
||||
public void guns() {
|
||||
setGuns(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in the Start Class
|
||||
* for testing purposes
|
||||
* sets the player's money, bank, guns, hp, ad cargo space to max values.
|
||||
*
|
||||
*/
|
||||
public void cheat() {
|
||||
setMoney(999999999);
|
||||
|
||||
@@ -10,7 +10,6 @@ public class TaipanShopLogic extends Player {
|
||||
|
||||
/**
|
||||
* 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 TaipanShopLogic(Player player) {
|
||||
@@ -19,7 +18,8 @@ public class TaipanShopLogic extends Player {
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is when the shop is accessed, randomizing the prices of all the items.
|
||||
* This method is used when the shop is accessed, randomizing the prices of all the items.
|
||||
* @return Returns the string which will be said to the player when they open the shop
|
||||
*/
|
||||
public String updatePrices() {
|
||||
String s = "\t" + getName() + ", the price of ";
|
||||
@@ -72,7 +72,6 @@ public class TaipanShopLogic extends Player {
|
||||
|
||||
/**
|
||||
* returns the user's condition based upon their current HP.
|
||||
*
|
||||
* @return shipStatus -- a representation of their ship's health in words.
|
||||
*/
|
||||
public String shipStatusString(){
|
||||
@@ -96,7 +95,6 @@ public class TaipanShopLogic extends Player {
|
||||
|
||||
/**
|
||||
* converts the user's location (an integer) to a String, and returns it.
|
||||
*
|
||||
* @return location -- the user's location as a string; the actual name of the location.
|
||||
*/
|
||||
public String getStringLocation(){
|
||||
|
||||
@@ -4,6 +4,12 @@ import java.util.Random;
|
||||
|
||||
public class TravelLogic extends Player {
|
||||
|
||||
|
||||
/**
|
||||
* 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 TravelLogic(Player player) {
|
||||
Player playerDummy = new Player(player);
|
||||
setPlayer(playerDummy);
|
||||
@@ -56,6 +62,7 @@ public class TravelLogic extends Player {
|
||||
*
|
||||
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||
* by a typhoon.
|
||||
* @return returns the string which is to be said to the player
|
||||
**/
|
||||
public String disaster(int locationOfTravel) {
|
||||
//Tells player that there is a storm approaching.
|
||||
|
||||
@@ -13,9 +13,9 @@ public class WarehouseLogic extends Player {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that tranfers your cargo from your ship to your warehouse.
|
||||
* Method that transfers your cargo from your ship to your warehouse.
|
||||
* Has error handling to prevent incorrect inputs
|
||||
*
|
||||
* @return returns the string which is to be said to the player
|
||||
*/
|
||||
public String deposit(String str, int goodsNum) {
|
||||
try {
|
||||
@@ -60,7 +60,7 @@ public class WarehouseLogic extends Player {
|
||||
/**
|
||||
* Method that transfers cargo from your warehouse onto your ship.
|
||||
* Has error handling to prevent incorrect inputs
|
||||
*
|
||||
* @return returns the string which is to be said to the player
|
||||
*/
|
||||
public String withdraw(String str, int goodsNum) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user