Added some content to the textgame files and added some stuff to the logic files. Also fixed formating in TravelGUI

This commit is contained in:
2019-04-07 16:35:22 -06:00
parent f37aa91fad
commit 26064ebac3
14 changed files with 1906 additions and 385 deletions

View File

@@ -18,20 +18,12 @@ public class FileSaving extends Player implements Serializable {
try {
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
return getPlayer(in);
}
catch (Exception e) {
try {
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
return getPlayer(in);
}
catch(Exception e2){
return null;
@@ -39,6 +31,14 @@ public class FileSaving extends Player implements Serializable {
}
}
private Player getPlayer(InputStream in) throws IOException, ClassNotFoundException {
ObjectInputStream inObject = new ObjectInputStream(in);
Player player = (Player) inObject.readObject();
in.close();
inObject.close();
return player;
}
/**
* Saves the file of type player which contains all the player instances
* @param player The player object being saved

View File

@@ -1,4 +1,27 @@
package logic;
public class GameEndLogic extends Player{
/**
* Calculates the networth of the player by the end of the game
* @return the total networth of the player
*/
public int getNetWorth() {
int netWorthInt;
netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
netWorthInt -= getDebt();
return netWorthInt;
}
/**
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
* @return the endGame message
*/
public String endGameText() {
if (getHP() <= 0) {
return "Game Over!";
} else {
return "Congratulations!";
}
}
}

View File

@@ -74,45 +74,21 @@ public class TaipanShopLogic extends Player {
*
* @return shipStatus -- a representation of their ship's health in words.
*/
public String shipStatusString() {
public String shipStatusString(){
String shipStatus;
switch (getHP() / 10) {
case 10:
shipStatus = "Mint Condition";
break;
case 9:
shipStatus = "Near Perfect";
break;
case 8:
shipStatus = "Great";
break;
case 7:
shipStatus = "Good";
break;
case 6:
shipStatus = "Acceptable";
break;
case 5:
shipStatus = "Tolerable";
break;
case 4:
shipStatus = "Needs Repair";
break;
case 3:
shipStatus = "Damaged";
break;
case 2:
shipStatus = "Indangered";
break;
case 1:
shipStatus = "Near Sinking";
break;
case 0:
shipStatus = "Sinking";
break;
default:
shipStatus = "Invincible";
break;
switch(getHP()/10){
case 10: shipStatus = "Mint Condition"; break;
case 9: shipStatus = "Near Perfect"; break;
case 8: shipStatus = "Great"; break;
case 7: shipStatus = "Good"; break;
case 6: shipStatus = "Acceptable"; break;
case 5: shipStatus = "Tolerable"; break;
case 4: shipStatus = "Needs Repair"; break;
case 3: shipStatus = "Damaged"; break;
case 2: shipStatus = "Indangered"; break;
case 1: shipStatus = "Near Sinking"; break;
case 0: shipStatus = "Sinking"; break;
default: shipStatus = "Invincible"; break;
}
return shipStatus;
}
@@ -122,35 +98,20 @@ public class TaipanShopLogic extends Player {
*
* @return location -- the user's location as a string; the actual name of the location.
*/
public String getStringLocation() {
public String getStringLocation(){
String location;
switch (getLocation()) {
case 1:
location = "Hong Kong";
break;
case 2:
location = "Shanghai";
break;
case 3:
location = "Nagasaki";
break;
case 4:
location = "Saigon";
break;
case 5:
location = "Manila";
break;
case 6:
location = "Singapore";
break;
case 7:
location = "Batavia";
break;
default:
location = "Error";
break;
switch(getLocation()){
case 1: location = "Hong Kong"; break;
case 2: location = "Shanghai"; break;
case 3: location = "Nagasaki"; break;
case 4: location = "Saigon"; break;
case 5: location = "Manila"; break;
case 6: location = "Singapore"; break;
case 7: location = "Batavia"; break;
default: location = "Error"; break;
}
return location;
}
}