138 Commits
1.1 ... legacy

Author SHA1 Message Date
c24d485463 Adding back the old files 2019-03-12 08:45:44 -06:00
ae39a210be Remade Legacy branch after destroying it 2019-03-12 08:44:25 -06:00
36f72b22e4 Merge remote-tracking branch 'origin/master' 2019-03-11 19:40:25 -06:00
4efe650091 Fixed the problem where shipwarfare didn't run after Travel 2019-03-11 19:40:13 -06:00
Vikramb987
e341112aec Update TaipanShopGUI.java
javadocs update.
2019-03-11 19:38:02 -06:00
Vikram
a56a6690ee Merge remote-tracking branch 'origin/master' 2019-03-11 19:17:31 -06:00
Vikram
c179ac17ae fixed one small issue. 2019-03-11 19:17:13 -06:00
29e0f3e683 Merge remote-tracking branch 'origin/master' 2019-03-11 19:07:26 -06:00
923ff50c87 Finished the fix for negative numbers and Strings messing up the travel textField 2019-03-11 19:07:11 -06:00
Vikram
15525d789e fixed one small issue. 2019-03-11 19:07:06 -06:00
Vikram
e0171bacfa finished javadocs 2019-03-11 19:00:26 -06:00
KahootChampion
8c776b769b wrote javadocs for authorname 2019-03-11 18:47:10 -06:00
428a7caf80 Fixed the problem where the player could recalculate price values by leaving and entering the travel screen. 2019-03-11 18:27:42 -06:00
Vikramb987
af81624e27 Update TaipanShopGUI.java
changed the javadoc slightly.
2019-03-11 17:21:15 -06:00
KahootChampion
762b399c4b Added JavaDocs for ShipWarfare 2019-03-11 15:33:08 -06:00
Nathan Lum
8402a2368c Added Javadoc comments 2019-03-11 15:28:11 -06:00
Nathan Lum
8c3098a498 Added Javadoc comments 2019-03-11 15:20:38 -06:00
Vikramb987
f1a43a279a Update TaipanShopGUI.java 2019-03-11 15:18:05 -06:00
Nathan Lum
140e8dc706 Added Javadoc comments 2019-03-11 15:17:42 -06:00
Nathan Lum
e21a7c9f54 Added Javadoc comments 2019-03-11 15:12:03 -06:00
Nathan Lum
023e77f034 Added Javadoc comments 2019-03-11 15:07:35 -06:00
Vikramb987
696af67665 Update TaipanShopGUI.java
comment
2019-03-11 14:07:12 -06:00
cf0fd1281f Update README.md 2019-03-11 13:56:54 -06:00
Vikramb987
4e4d30c222 Update TravelGUI.java
aesthetic changes
2019-03-11 12:41:32 -06:00
Vikramb987
d2e42048b2 Update TaipanShopGUI.java
aesthetic changes boi
2019-03-11 12:40:08 -06:00
KahootChampion
303be2eea6 Fixed output for start and TaipanShop GUI 2019-03-11 12:27:17 -06:00
Siddhant Dewani
963f16afca Fixed bank label 2019-03-11 11:49:50 -06:00
Siddhant Dewani
fd03a7c588 FIXED Loanshark and bank 2019-03-11 11:41:06 -06:00
Vikramb987
c912394dd9 Update TaipanShopGUI.java
fixed minor error
2019-03-11 09:09:53 -06:00
c0914d8e5e Renamed a few classes so that all of them are uppercase 2019-03-11 02:12:10 -06:00
11b16b4e40 Finished cleaning up the code. Ready for Demo 2 2019-03-11 02:05:26 -06:00
076ba12ef1 Update README.md 2019-03-10 23:54:43 -06:00
59de84a47d Made it GUI friendly 2019-03-10 23:52:35 -06:00
e1671d8d21 Merge remote-tracking branch 'origin/master' 2019-03-10 23:50:56 -06:00
e6a67ce1e4 Removed previous textbased game 2019-03-10 23:50:41 -06:00
Nathan Lum
1ac82edf1e Added Javadoc comments 2019-03-10 23:43:19 -06:00
Nathan Lum
1df0cbec36 Added Javadoc comments 2019-03-10 23:42:24 -06:00
KahootChampion
0af20d9f67 Changed one line of text in shipwarfare GUI 2019-03-10 23:42:46 -06:00
Vikramb987
5b8682a900 Update TaipanShopGUI.java
finished javadocs
2019-03-10 23:18:20 -06:00
a58d0fa184 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/WarehouseGUI.java
2019-03-10 23:05:39 -06:00
KahootChampion
4d09891665 Added to my javadocs a bit 2019-03-10 23:03:30 -06:00
91bb72351e Fixed the Game End screen into Taipan Shop 2019-03-10 23:00:25 -06:00
KahootChampion
ba16ea1809 Completed javadocs for shipwarfare GUI 2019-03-10 22:58:43 -06:00
Nathan Lum
9b9af573a8 Added Javadoc comments 2019-03-10 22:56:26 -06:00
KahootChampion
c6df980f8e Fixed ShipWarfare bug about one-shotting. 2019-03-10 22:43:46 -06:00
Vikram
666e409e74 Merge remote-tracking branch 'origin/master' 2019-03-10 22:42:55 -06:00
Vikram
89f9e47921 some changes... 2019-03-10 22:42:40 -06:00
414a9634b5 Merge remote-tracking branch 'origin/master' 2019-03-10 22:11:07 -06:00
f4fbc474e7 Finished the End Game Screen 2019-03-10 22:10:45 -06:00
Vikram
4c8b99d4bb Merge remote-tracking branch 'origin/master' 2019-03-10 21:50:27 -06:00
Vikram
ffb77b14a0 some changes... 2019-03-10 21:49:50 -06:00
Vikramb987
0c5317cf6f Update TaipanShopGUI.java
fixed to adapt to loanshark
2019-03-10 21:15:38 -06:00
Vikram
461171ff46 minor changes. Still in progress. 2019-03-10 21:12:44 -06:00
Vikramb987
13f30b681a Update TaipanShopGUI.java
made it so that certain buttons are invisible in certain locations.
2019-03-10 21:12:26 -06:00
Siddhant Dewani
1d5e5aa706 Fixed bank and loanshark 2019-03-10 21:11:49 -06:00
Vikramb987
01ee9b2600 Update TaipanShopGUI.java
fixed shop prices not changing
2019-03-10 20:49:45 -06:00
3aa6ad619d Merge remote-tracking branch 'origin/master' 2019-03-10 20:13:33 -06:00
0b8b8ed50c Fixed output for travel 2019-03-10 20:13:06 -06:00
KahootChampion
df372522e4 Probably should upload 2019-03-10 20:12:01 -06:00
KahootChampion
4fd40af606 Completed ShipWarfareGUI 2019-03-10 20:01:20 -06:00
KahootChampion
664d194d7b Completed SHipWarfareGUI 2019-03-10 20:00:36 -06:00
KahootChampion
2198fffbd5 A lot of errors but easily fixable SHipwarfareGUI 2019-03-10 19:41:43 -06:00
d395d91730 Made it so you're not locked out of Taipan shop for Bank and Loanshark 2019-03-10 18:54:03 -06:00
31e93f6997 Fixed BorderPane issue in Warehouse 2019-03-10 18:38:24 -06:00
0f2e8848ad Merged together Taipanshop with both Loanshark and Bank GUI 2019-03-10 18:36:54 -06:00
c3f7cc16d2 Merge remote-tracking branch 'origin/master' 2019-03-10 18:29:17 -06:00
9a15f6bc63 Merged TaipanShop and Warehouse. Just need to add functionality to warehouse. 2019-03-10 18:28:59 -06:00
Siddhant Dewani
680225550f Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-03-10 18:23:48 -06:00
Siddhant Dewani
6778aa5737 Merge remote-tracking branch 'origin/master' 2019-03-10 18:07:34 -06:00
Siddhant Dewani
46624389f5 Finished LoanShark!! 2019-03-10 18:06:03 -06:00
a0e0ab517d Merged Travel and Ship warfare 2019-03-10 17:35:46 -06:00
Nathan Lum
5e33374e3c Add files via upload 2019-03-10 17:27:17 -06:00
325c4127dd Fix bunch of issues with Travel and Taipanshop, also merged Main, Shop, Travel and Start. Now attempting to merge in ship. 2019-03-10 16:06:48 -06:00
KahootChampion
fde76a5bfb Just checking 2019-03-10 15:45:31 -06:00
KahootChampion
888d8a1c92 Fined minor bugs in shipwarfareGUI including the "gun frustration" variable 2019-03-10 12:10:33 -06:00
KahootChampion
42c4534f52 Fixed probability of ships running away 2019-03-10 12:00:00 -06:00
KahootChampion
a07d633ff9 Basic functionality of buttons completed, think all I have to do now is to find a way to break the code when the user wins, loses or runs away. 2019-03-10 11:26:54 -06:00
KahootChampion
b4e0e18d20 Completely ruined shipWarfare with a previous edit, fixed it and added a better loot feature for peasant ships 2019-03-10 03:30:28 -06:00
KahootChampion
d558e7cf0c Fixed the loot system a bit 2019-03-10 01:44:02 -07:00
KahootChampion
36aa789590 Fixed numOfShips method for ShipWarfareGUI 2019-03-10 01:14:37 -07:00
KahootChampion
e5807a46af Shipwarfare fight button GUI almost complete 2019-03-10 00:39:59 -07:00
KahootChampion
5f6abbc817 ShipWarfare fight button coming along nicely 2019-03-09 23:52:51 -07:00
b376ad5284 Fixed loop problem ShipwarfareGUI 2019-03-09 23:36:58 -07:00
b945cafe98 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.idea/workspace.xml
2019-03-09 23:27:03 -07:00
75673d40e1 Finished TravelGUI and StartGUI 2019-03-09 23:26:25 -07:00
KahootChampion
9feac6e90e Forces you to fight in ShipWarfareGUI unfortunately 2019-03-09 22:52:30 -07:00
KahootChampion
1bb00d0d01 Super broken but fight button is in progress for shipwarfare 2019-03-09 22:32:45 -07:00
KahootChampion
80102eabee Please find error 2019-03-09 20:03:51 -07:00
KahootChampion
f5845cb8df Messed up player by setting money to 1000 2019-03-09 18:34:27 -07:00
KahootChampion
5a7d1e7c34 Missed one statement that I needed to encapsulate 2019-03-09 18:33:33 -07:00
KahootChampion
370b3ee041 Made ShipWarfare easier to access by ShipWarfareGUI 2019-03-09 18:28:44 -07:00
Vikramb987
7314bc174f Update ShopGUI
Mostly done.
2019-03-09 16:51:26 -07:00
KahootChampion
5c78f561d8 Added fight stuff 2019-03-09 16:13:36 -07:00
KahootChampion
271a37877b Notified of getting attacked 2019-03-09 16:09:15 -07:00
KahootChampion
89188152e6 Added time stuff to Shipwarfare GUI 2019-03-09 15:00:00 -07:00
6b9e3dcc06 Added some logic to ShipWarfareGUI 2019-03-09 14:33:27 -07:00
14e5eb2d30 Added basic functionality with KahootChampion 2019-03-09 14:28:02 -07:00
bf2d1c3fb0 Basic layout for ShipwarefareGUI. 2019-03-09 14:14:03 -07:00
Vikramb987
b62274cda3 Update ShopGUI
another set of updates.
2019-03-09 12:04:18 -07:00
Vikramb987
72708e53f2 Update ShopGUI
small change.
2019-03-08 19:44:05 -07:00
Vikramb987
540605f0f1 Update ShopGUI
Updated. Still a w.i.p
2019-03-08 19:36:55 -07:00
Vikramb987
f6fa9dc646 Create ShopGUI
This file is the temporary placeholder for my shop GUI. Very much still in progress.
2019-03-07 20:57:36 -07:00
93f16751f1 Fixed some little problems with documenting. 2019-02-25 23:47:34 -07:00
507fe4debd Fixed some little problems with documenting. 2019-02-25 23:42:27 -07:00
2d1864bb87 Fixed the commenting on a lot of the code. Also added some stuff to Travel, fixed some bugs. 2019-02-25 23:31:39 -07:00
Nathan Lum
de3c686db7 Added Javadoc comments 2019-02-25 22:50:58 -07:00
Nathan Lum
2abef09de8 Added Javadoc comments 2019-02-25 22:00:01 -07:00
Nathan Lum
b1421e19d4 Added Javadoc comments 2019-02-25 21:15:46 -07:00
Nathan Lum
55e1ae2d5f Added Javadoc comments 2019-02-25 21:12:33 -07:00
Vikramb987
697c221323 Update Player.java 2019-02-25 20:19:40 -07:00
Vikramb987
4aaff2809a Update main.java 2019-02-25 20:19:14 -07:00
KahootChampion
581bee7bfe Test out this code BOIZ 2019-02-25 20:20:11 -07:00
KahootChampion
1295d625fb KK 2019-02-25 20:07:21 -07:00
KahootChampion
52ec4c2422 Aight fixed some stuff 2019-02-25 20:06:21 -07:00
KahootChampion
27ac100618 Test this Vikram 2019-02-25 20:01:21 -07:00
Vikramb987
94762234af Update main.java 2019-02-25 19:58:32 -07:00
Vikramb987
207d258e05 Update Start.java
very small change -- again just for testing
2019-02-25 19:47:20 -07:00
Vikramb987
f236650611 Update TaipanShop.java
javadocs and some changes to how the game ends
2019-02-25 19:46:09 -07:00
Vikramb987
757d258e3d Update Player.java
changes to how the game ends
2019-02-25 19:44:21 -07:00
KahootChampion
e7a0ddf085 Small change to javadocs for shipwarfare 2019-02-25 19:42:19 -07:00
KahootChampion
70b698c22e Java Docs BOIZ for ShipWarafare 2019-02-25 19:35:50 -07:00
Siddhant Dewani
4cc9ac5d26 Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-02-25 19:16:09 -07:00
Siddhant Dewani
c66e3d5d70 Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-02-25 19:06:02 -07:00
Siddhant Dewani
40ba6b0c9b Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-02-25 18:53:51 -07:00
Siddhant Dewani
2ae60073c0 Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-02-25 18:53:25 -07:00
Vikram
c4c4a41776 Merge remote-tracking branch 'origin/master' 2019-02-25 18:43:11 -07:00
Vikram
6b379bae3a minor changes. Still in progress. 2019-02-25 18:42:48 -07:00
Siddhant Dewani
67ddc34c65 Small thing, changed an output of warehouse a bit, shows user its the warehouse they are concerned with. 2019-02-25 18:42:40 -07:00
Vikram
b6b5c14c56 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	out/production/TaipanClone/ShipWarfare.class
2019-02-25 18:33:26 -07:00
Vikram
d1c3fe0f7e minor changes. Still in progress. 2019-02-25 18:31:54 -07:00
Nathan Lum
fcb0b50468 Added Javadocs comments 2019-02-25 17:45:06 -07:00
KahootChampion
237ce1da27 Stupid error was fixed 2019-02-25 17:42:58 -07:00
Nathan Lum
3b068d869b Update main.java 2019-02-25 16:28:36 -07:00
Nathan Lum
70d9a36af5 Update Start.java 2019-02-25 16:28:09 -07:00
Vikramb987
06739ed20c Update loanShark.java 2019-02-25 14:31:34 -07:00
Vikram
8d35d073e4 Merge remote-tracking branch 'origin/master' 2019-02-25 07:42:13 -07:00
Vikram
672707f5b6 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.idea/workspace.xml
#	src/ShipWarfare.java
2019-02-25 07:40:36 -07:00
Vikram
83057e863f the comment somehow made it so that I couldn't compile (using the command line i couldn't compile, i could compile file using intellij) Also, you the file extended player, which is not necessary. You also were calling gameOver() and getName() directly, you needed "player." before all those methods. 2019-02-25 07:39:57 -07:00
12 changed files with 1399 additions and 464 deletions

8
.idea/misc.xml generated
View File

@@ -1,9 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" value="$USER_HOME$/Desktop/Javadocs TaipanClone" />
<option name="OPTION_HIERARCHY" value="false" />
<option name="OPTION_NAVIGATOR" value="false" />
<option name="OPTION_INDEX" value="false" />
</component>
<component name="ProjectKey"> <component name="ProjectKey">
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" /> <option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_201" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="SvnBranchConfigurationManager"> <component name="SvnBranchConfigurationManager">

818
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,35 +1,62 @@
import java.util.Scanner; import java.util.Scanner;
public class Bank{ public class Bank{
private Player player; private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
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;
} }
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public Bank(Player player){ public Bank(Player player){
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
/**
* This method is used to withdraw or deposit money into the bank account
* by prompting the user if they would like to withdraw or deposit. Followed
* by prompting them to enter an amount to transfer. This method also uses the
* player class to see if the transfer can be made,and if it can it changes the
* values accordingly
*/
public void bank(){ public void bank(){
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
boolean notDone = true; boolean notDone = true;
int check = 0; int check = 0;
while(notDone){ while(notDone){
//Prompt the user if they want to withdraw or deposit
System.out.println("Would you like to Withdraw or Deposit?"); System.out.println("Would you like to Withdraw or Deposit?");
String response = input.nextLine(); String response = input.nextLine();
//If user chose withdraw then subtract the amount from bank account and add it to cash
if(response.equalsIgnoreCase("W")){ if(response.equalsIgnoreCase("W")){
boolean notDone2 = true; boolean notDone2 = true;
while(notDone2){ while(notDone2){
System.out.println("How much do you wish to Withdraw?"); System.out.println("How much do you wish to Withdraw?");
int withdraw = input.nextInt(); int withdraw = input.nextInt();
//Prompt the user for the amount and check if the bank has sufficient funds
if(withdraw <= player.getBank()){ if(withdraw <= player.getBank()){
player.setMoney(withdraw + player.getMoney()); player.setMoney(withdraw + player.getMoney());
player.setBank(player.getBank()-withdraw); player.setBank(player.getBank()-withdraw);
@@ -37,9 +64,13 @@ public class Bank{
check = 1; check = 1;
} }
} }
}else if(response.equalsIgnoreCase("D")){
}
//If the user chooses to deposit the continue to this code
else if(response.equalsIgnoreCase("D")){
boolean notDone2 = true; boolean notDone2 = true;
while(notDone2){ while(notDone2){
//Prompt the user for the amount they would like to deposit and ensure suffiecent funds
System.out.println("How much do you wish to Deposit?"); System.out.println("How much do you wish to Deposit?");
int deposit = input.nextInt(); int deposit = input.nextInt();
if(deposit <= player.getMoney()){ if(deposit <= player.getMoney()){
@@ -52,6 +83,7 @@ public class Bank{
} }
if(check == 1){ if(check == 1){
boolean notDone3 = true; boolean notDone3 = true;
// Asks user if they would like to continue in bank or not
while(notDone3){ while(notDone3){
System.out.println("Would you like to continue? Y/N"); System.out.println("Would you like to continue? Y/N");
response = input.nextLine(); response = input.nextLine();

View File

@@ -1,3 +1,5 @@
import java.util.Scanner;
public class Player { public class Player {
private String name = "Taipan"; private String name = "Taipan";
@@ -16,11 +18,17 @@ public class Player {
private int wGeneral = 0; private int wGeneral = 0;
private int wArms = 0; private int wArms = 0;
private boolean retire = false; private boolean retire = false;
private int cargoSpace = 60;
public Player(){ public Player(){
} }
/**
* Copy constructor
*
* @param player object of the class Player
*/
public Player(Player player){ public Player(Player player){
this.bank = player.bank; this.bank = player.bank;
this.money = player.money; this.money = player.money;
@@ -36,128 +44,307 @@ public class Player {
this.wSilk = player.wSilk; this.wSilk = player.wSilk;
this.wGeneral = player.wGeneral; this.wGeneral = player.wGeneral;
this.wArms = player.wArms; this.wArms = player.wArms;
} }
/**
* getter method for the instance variable cargoSpace.
*
* @return returns the instance variable cargoSpace
*/
public int getCargoSpace() {
return cargoSpace;
}
/**
* setter method for the instance variable cargoSpace.
*
* @param cargoSpace takes an int that is greater than 0 as an argument
*/
public void setCargoSpace(int cargoSpace) {
if(cargoSpace > 0){
this.cargoSpace = cargoSpace;
}
}
/**
* getter method for the instance variable retire.
*
* @return returns the instance variable retire
*/
public boolean getRetire(){ public boolean getRetire(){
return retire; return retire;
} }
/**
* setter method for the instance variable retire.
*
* @param retire takes a boolean as an argument
*/
public void setRetire(boolean retire){ public void setRetire(boolean retire){
if(retire){ if(retire){
this.retire = retire; this.retire = retire;
} }
} }
/**
* getter method for the instance variable name.
*
* @return returns the instance variable name
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* setter method for the instance variable name.
*
* @param name takes a string as an argument
*/
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* getter method for the instance variable HP.
*
* @return returns the instance variable HP
*/
public int getHP() { public int getHP() {
return HP; return HP;
} }
/**
* setter method for the instance variable HP.
*
* @param HP takes an int as an argument
*/
public void setHP(int HP) { public void setHP(int HP) {
this.HP = HP; this.HP = HP;
} }
/**
* getter method for the instance variable bank.
*
* @return returns the instance variable bank
*/
public int getBank() { public int getBank() {
return bank; return bank;
} }
/**
* setter method for the instance variable bank.
*
* @param bank takes an int that is greater than or equal to 0 as an argument
*/
public void setBank(int bank) { public void setBank(int bank) {
if (bank >= 0) { if (bank >= 0) {
this.bank = bank; this.bank = bank;
} }
} }
/**
* getter method for the instance variable money.
*
* @return returns the instance variable money
*/
public int getMoney() { public int getMoney() {
return money; return money;
} }
/**
* setter method for the instance variable money.
*
* @param money takes an int that is greater than or equal to 0 as an argument
*/
public void setMoney(int money) { public void setMoney(int money) {
if (money >= 0) { if (money >= 0) {
this.money = money; this.money = money;
} }
} }
/**
* getter method for the instance variable opiumHeld.
*
* @return returns the instance variable opiumHeld
*/
public int getOpiumHeld() { public int getOpiumHeld() {
return opiumHeld; return opiumHeld;
} }
/**
* setter method for the instance variable opiumHeld.
*
* @param opiumHeld takes an int that is greater than or equal to 0 as an argument
*/
public void setOpiumHeld(int opiumHeld) { public void setOpiumHeld(int opiumHeld) {
if (opiumHeld >= 0) { if (opiumHeld >= 0) {
this.opiumHeld = opiumHeld; this.opiumHeld = opiumHeld;
} }
} }
/**
* getter method for the instance variable silkHeld.
*
* @return returns the instance variable silkHeld
*/
public int getSilkHeld() { public int getSilkHeld() {
return silkHeld; return silkHeld;
} }
/**
* setter method for the instance variable silkHeld.
*
* @param silkHeld takes an int that is greater than or equal to 0 as an argument
*/
public void setSilkHeld(int silkHeld) { public void setSilkHeld(int silkHeld) {
if (silkHeld >= 0) { if (silkHeld >= 0) {
this.silkHeld = silkHeld; this.silkHeld = silkHeld;
} }
} }
/**
* getter method for the instance variable generalHeld.
*
* @return returns the instance variable generalHeld
*/
public int getGeneralHeld() { public int getGeneralHeld() {
return generalHeld; return generalHeld;
} }
/**
* setter method for the instance variable generalHeld.
*
* @param generalHeld takes an int that is greater than or equal to 0 as an argument
*/
public void setGeneralHeld(int generalHeld) { public void setGeneralHeld(int generalHeld) {
if (generalHeld >= 0) { if (generalHeld >= 0) {
this.generalHeld = generalHeld; this.generalHeld = generalHeld;
} }
} }
/**
* getter method for the instance variable armsHeld.
*
* @return returns the instance variable armsHeld
*/
public int getArmsHeld() { public int getArmsHeld() {
return armsHeld; return armsHeld;
} }
/**
* setter method for the instance variable armsHeld.
*
* @param armsHeld takes an int that is greater than or equal to 0 as an argument
*/
public void setArmsHeld(int armsHeld) { public void setArmsHeld(int armsHeld) {
if (armsHeld >= 0) { if (armsHeld >= 0) {
this.armsHeld = armsHeld; this.armsHeld = armsHeld;
} }
} }
/**
* getter method for the instance variable location.
*
* @return returns the instance variable location
*/
public int getLocation() { public int getLocation() {
return location; return location;
} }
/**
* setter method for the instance variable location.
*
* @param location takes an int that is greater than or equal to 0 as an argument
*/
public void setLocation(int location) { public void setLocation(int location) {
if (location >= 0) { if (location >= 0) {
this.location = location; this.location = location;
} }
} }
/**
* getter method for the instance variable guns.
*
* @return returns the instance variable guns
*/
public int getGuns() { public int getGuns() {
return guns; return guns;
} }
/**
* setter method for the instance variable guns.
*
* @param guns takes an int that is greater than or equal to 0 as an argument
*/
public void setGuns(int guns) { public void setGuns(int guns) {
if (guns >= 0) { if (guns >= 0) {
this.guns = guns; this.guns = guns;
} }
} }
/**
* getter method for the instance variable debt.
*
* @return returns the instance variable debt
*/
public int getDebt() { public int getDebt() {
return debt; return debt;
} }
/**
* setter method for the instance variable debt.
*
* @param debt takes an int that is greater than or equal to 0 as an argument
*/
public void setDebt(int debt) { public void setDebt(int debt) {
if (debt >= 0) { if (debt >= 0) {
this.debt = debt; this.debt = debt;
} }
} }
public int getwOpium(){ return wOpium; } /**
* getter method for the instance variable wOpium.
*
* @return returns the instance variable wOpium
*/
public int getwOpium() {
return wOpium;
}
/**
* setter method for the instance variable wOpium.
*
* @param wOpium takes an int that is greater than or equal to 0 as an argument
*/
public void setwOpium(int wOpium) { public void setwOpium(int wOpium) {
if (wOpium >= 0){ if (wOpium >= 0){
@@ -165,7 +352,21 @@ public class Player {
} }
} }
public int getwSilk(){return wSilk;} /**
* getter method for the instance variable wSilk.
*
* @return returns the instance variable wSilk
*/
public int getwSilk() {
return wSilk;
}
/**
* setter method for the instance variable wSilk.
*
* @param wSilk takes an int that is greater than or equal to 0 as an argument
*/
public void setwSilk(int wSilk) { public void setwSilk(int wSilk) {
if (wSilk >= 0){ if (wSilk >= 0){
@@ -173,7 +374,21 @@ public class Player {
} }
} }
public int getwGeneral(){return wGeneral;} /**
* getter method for the instance variable wGeneral.
*
* @return returns the instance variable wGeneral
*/
public int getwGeneral() {
return wGeneral;
}
/**
* setter method for the instance variable wGeneral.
*
* @param wGeneral takes an int that is greater than or equal to 0 as an argument
*/
public void setwGeneral(int wGeneral) { public void setwGeneral(int wGeneral) {
if (wGeneral >= 0){ if (wGeneral >= 0){
@@ -181,7 +396,21 @@ public class Player {
} }
} }
public int getwArms(){return wArms;} /**
* getter method for the instance variable wArms.
*
* @return returns the instance variable wArms
*/
public int getwArms() {
return wArms;
}
/**
* setter method for the instance variable wArms.
*
* @param wArms takes an int that is greater than or equal to 0 as an argument
*/
public void setwArms(int wArms) { public void setwArms(int wArms) {
if (wArms >= 0){ if (wArms >= 0){
@@ -189,9 +418,15 @@ public class Player {
} }
} }
/**
* 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();
System.out.println("Game over"); System.out.println("Game over");
System.exit(0);
} }
} }

View File

@@ -2,6 +2,7 @@ import java.util.Scanner;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class ShipWarfare { public class ShipWarfare {
private int numOfPeasantShips = 0; private int numOfPeasantShips = 0;
@@ -13,22 +14,37 @@ public class ShipWarfare {
private String pirateName = "Liu Yen"; private String pirateName = "Liu Yen";
private Player player; private Player player;
/**
* Class Constructor that takes in a type player as a parameter
* @param player object of the class Player
*/
public ShipWarfare(Player player) { public ShipWarfare(Player player) {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
/**
* setter method for player
* @param player object of the class Player
*/
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;
} }
//This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits /**
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
* @throws Exception in case of errors due to the delay
*/
public void peasantFleetAttack() throws Exception { public void peasantFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in); Scanner userResponse = new Scanner(System.in);
setNumOfPeasantShips(numOfShips()); setNumOfPeasantShips(numOfShips());
@@ -41,6 +57,7 @@ public class ShipWarfare {
if (response.equalsIgnoreCase("f")) { if (response.equalsIgnoreCase("f")) {
userAttacks = true; userAttacks = true;
System.out.println("Ohh, fight ehh?"); System.out.println("Ohh, fight ehh?");
delayForSeconds(1);
boolean winOrLose = destroyPeasantShipsOrEscape(); boolean winOrLose = destroyPeasantShipsOrEscape();
if (winOrLose == true) { if (winOrLose == true) {
break; break;
@@ -54,6 +71,7 @@ public class ShipWarfare {
break; break;
} else { } else {
System.out.println("Phew! Got away safely"); System.out.println("Phew! Got away safely");
delayForSeconds(2);
break; break;
} }
@@ -63,7 +81,11 @@ public class ShipWarfare {
} }
//This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
/**
* This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
* @throws Exception in case of errors due to the delay
*/
public void littyFleetAttack() throws Exception { public void littyFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in); Scanner userResponse = new Scanner(System.in);
setNumOfLittyShips(numOfShips()); setNumOfLittyShips(numOfShips());
@@ -83,10 +105,12 @@ public class ShipWarfare {
} else if (response.equalsIgnoreCase("r")) { } else if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) { if (runFromShips() == false) {
System.out.println("Couldn't run away!"); System.out.println("Couldn't run away!");
delayForSeconds(1);
if (destroyLittyShipsOrEscape()) if (destroyLittyShipsOrEscape())
break; break;
} else { } else {
System.out.println("Phew! Got away safely"); System.out.println("Phew! Got away safely");
delayForSeconds(2);
break; break;
} }
@@ -97,34 +121,49 @@ public class ShipWarfare {
} }
/**
* Asks user if they would like to fight or run against ships
*/
public void fightOrRunMessage() { public void fightOrRunMessage() {
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", player.getGuns()); System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)\n", player.getGuns());
}
public int numOfPeasantShips() {
return numOfPeasantShips;
} }
/**
* setter method that takes in an integer as an argument
* @param numOfLittyShips the number of ships to be used in the litty fleet attack
*/
public void setNumOfLittyShips(int numOfLittyShips) { public void setNumOfLittyShips(int numOfLittyShips) {
this.numOfLittyShips = numOfLittyShips; this.numOfLittyShips = numOfLittyShips;
startingLittyShips = numOfLittyShips; startingLittyShips = numOfLittyShips;
} }
/**
* setter method that takes in an integer as an argument
* @param numOfPeasantShips the number of ships to be used in the peasant fleet attack
*/
public void setNumOfPeasantShips(int numOfPeasantShips) { public void setNumOfPeasantShips(int numOfPeasantShips) {
this.numOfPeasantShips = numOfPeasantShips; this.numOfPeasantShips = numOfPeasantShips;
startingPeasantShips = numOfPeasantShips; startingPeasantShips = numOfPeasantShips;
} }
public void delayForASecond() throws Exception { /**
TimeUnit.SECONDS.sleep(1); * delays for a specific amount of seconds, takes an integer as an argument
* @param num the seconds to delay
* @throws Exception in case of errors due to the delay
*/
public void delayForSeconds(int num) throws Exception {
TimeUnit.SECONDS.sleep(num);
} }
//The number of ships which attack is based on the amount of money one has on hand /**
* The number of ships that attack is based on the amount of money one has on hand
* @return the number of ships which will attack
*/
public int numOfShips() { public int numOfShips() {
int numOfShipsAttacking = 0; int numOfShipsAttacking = 0;
@@ -148,7 +187,11 @@ public class ShipWarfare {
} }
//One in two chance of running away /**
* One in two chance of running away
* @return true if the user is allowed to run, false if not, the "default" is false
*/
public boolean runFromShips() { public boolean runFromShips() {
userAttacks = false; userAttacks = false;
Random randomValue = new Random(); Random randomValue = new Random();
@@ -161,7 +204,12 @@ public class ShipWarfare {
return false; return false;
} }
//The loot for defeating a litty fleet is much higher than that of a peasant one /**
* The user faces off against the litty ships and either prevails, dies, or runs away
* The loot for defeating a litty fleet is much higher than that of a peasant one
* @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay
*/
public boolean destroyLittyShipsOrEscape() throws Exception { public boolean destroyLittyShipsOrEscape() throws Exception {
int calculateLoot = 0; int calculateLoot = 0;
int chanceOfEnemyRun = 0; int chanceOfEnemyRun = 0;
@@ -173,6 +221,7 @@ public class ShipWarfare {
//Player volley //Player volley
while (exitValue == 0) { while (exitValue == 0) {
if (player.getGuns() > 0) {
for (int j = 0; j < player.getGuns(); j++) { for (int j = 0; j < player.getGuns(); j++) {
if (userAttacks == true) { if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(3) + 1; int hitOrMiss = randomValue.nextInt(3) + 1;
@@ -183,13 +232,13 @@ public class ShipWarfare {
break; break;
} }
System.out.println("Got eem"); System.out.println("Got eem");
delayForASecond(); delayForSeconds(1);
} else if (hitOrMiss == 2) { } else if (hitOrMiss == 2) {
System.out.printf("ARRG! We missed %s\n", player.getName()); System.out.printf("ARRG! We missed %s\n", player.getName());
delayForASecond(); delayForSeconds(1);
} else { } else {
System.out.println("Darn! Their fleet tanked our attack"); System.out.println("Darn! Their fleet tanked our attack");
delayForASecond(); delayForSeconds(1);
} }
@@ -197,14 +246,19 @@ public class ShipWarfare {
continue; continue;
} }
} }
} else {
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
delayForSeconds(1);
}
if (numOfLittyShips <= 0) { if (numOfLittyShips <= 0) {
exitValue = 1; exitValue = 1;
break; break;
} }
chanceOfEnemyRun = randomValue.nextInt(2) + 1; if (player.getGuns() > 0) {
if (chanceOfEnemyRun == 2) { if (chanceOfEnemyRun == 2) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
howMuchRun = randomValue.nextInt(10) + 1; howMuchRun = randomValue.nextInt(10) + 1;
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
@@ -217,10 +271,11 @@ public class ShipWarfare {
} }
} }
} }
}
System.out.printf("%d ships remaining\n", numOfLittyShips); System.out.printf("%d ships remaining\n", numOfLittyShips);
System.out.println("Oh no, they are taking the offensive!"); System.out.println("Oh no, they are taking the offensive!");
delayForASecond(); delayForSeconds(1);
//Computer volley //Computer volley
int takeGunChance = randomValue.nextInt(4) + 1; int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) { if (takeGunChance == 1 && player.getGuns() > 0) {
@@ -234,7 +289,7 @@ public class ShipWarfare {
break; break;
} }
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForASecond(); delayForSeconds(1);
if (userAttacks == false) { if (userAttacks == false) {
userAttacks = true; userAttacks = true;
} }
@@ -245,8 +300,10 @@ public class ShipWarfare {
if (response.equalsIgnoreCase("r")) { if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) { if (runFromShips() == false) {
System.out.println("Couldn't run away"); System.out.println("Couldn't run away");
delayForSeconds(1);
} else { } else {
exitValue = 3; System.out.println("Phew! Got away safely");
delayForSeconds(2);
break; break;
} }
} }
@@ -257,15 +314,19 @@ public class ShipWarfare {
if (exitValue == 1) { if (exitValue == 1) {
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP()); System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
delayForSeconds(1);
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300; calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
player.setMoney(player.getMoney() + calculateLoot); player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!\n", calculateLoot); System.out.printf("We got $%,d!\n", calculateLoot);
delayForSeconds(2);
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
player.gameOver(); player.gameOver();
return true; return true;
} else if (exitValue == 3) { } else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
delayForSeconds(2);
return true; return true;
} }
return false; return false;
@@ -273,6 +334,11 @@ public class ShipWarfare {
} }
/**
* The user faces off against the peasant ships and either prevails, dies, or runs away
* @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay
*/
public boolean destroyPeasantShipsOrEscape() throws Exception { public boolean destroyPeasantShipsOrEscape() throws Exception {
int calculateLoot = 0; int calculateLoot = 0;
@@ -285,6 +351,8 @@ public class ShipWarfare {
//Player volley //Player volley
while (exitValue == 0) { while (exitValue == 0) {
if (player.getGuns() > 0) {
for (int j = 0; j < player.getGuns(); j++) { for (int j = 0; j < player.getGuns(); j++) {
if (userAttacks == true) { if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1; int hitOrMiss = randomValue.nextInt(2) + 1;
@@ -295,10 +363,10 @@ public class ShipWarfare {
break; break;
} }
System.out.println("Got eem"); System.out.println("Got eem");
delayForASecond(); delayForSeconds(1);
} else { } else {
System.out.printf("ARRG! We missed %s\n", player.getName()); System.out.printf("ARRG! We missed %s\n", player.getName());
delayForASecond(); delayForSeconds(1);
} }
@@ -306,12 +374,19 @@ public class ShipWarfare {
continue; continue;
} }
} }
}
else{
System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName());
delayForSeconds(1);
}
if (numOfPeasantShips <= 0) { if (numOfPeasantShips <= 0) {
exitValue = 1; exitValue = 1;
break; break;
} }
if (player.getGuns() > 0) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1; chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) { if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(15) + 1; howMuchRun = randomValue.nextInt(15) + 1;
@@ -326,10 +401,12 @@ public class ShipWarfare {
} }
} }
} }
}
System.out.printf("%d ships remaining\n", numOfPeasantShips); System.out.printf("%d ships remaining\n", numOfPeasantShips);
delayForSeconds(1);
System.out.println("Oh no, they are taking the offensive!"); System.out.println("Oh no, they are taking the offensive!");
delayForASecond(); delayForSeconds(1);
//Computer volley //Computer volley
int takeGunChance = randomValue.nextInt(4) + 1; int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) { if (takeGunChance == 1 && player.getGuns() > 0) {
@@ -343,7 +420,7 @@ public class ShipWarfare {
break; break;
} }
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForASecond(); delayForSeconds(1);
if (userAttacks == false) { if (userAttacks == false) {
userAttacks = true; userAttacks = true;
} }
@@ -366,15 +443,18 @@ public class ShipWarfare {
if (exitValue == 1) { if (exitValue == 1) {
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP()); System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
delayForSeconds(1);
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100; calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
player.setMoney(player.getMoney() + calculateLoot); player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!", calculateLoot); System.out.printf("We got $%,d!", calculateLoot);
delayForSeconds(2);
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
player.gameOver(); player.gameOver();
return true; return true;
} else if (exitValue == 3) { } else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
delayForSeconds(2);
return true; return true;
} }
return false; return false;

View File

@@ -3,22 +3,42 @@ public class Start
{ {
private Player player; private Player player;
/**
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
*
* @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);
return playerTemp; return playerTemp;
} }
/**
* 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 playerTemp = new Player(player); Player playerTemp = new Player(player);
this.player = playerTemp; this.player = playerTemp;
} }
/**
* Asks the user to input the name that they would like to be called in the game
*
* @param name the name that you would like to be called in the game
*/
public void setFirm (String name) { public void setFirm (String name) {
if (name.length() <= 22) { if (name.length() <= 22) {
player.setName(name); player.setName(name);
} }
} }
public void intialize()
/**
* Initializes the game by asking for your name and if you would like to start with either: 1) money and a debt or
* 2) guns and no cash/debt.
*/
public void initialize()
{ {
Scanner userInput = new Scanner(System.in); Scanner userInput = new Scanner(System.in);
System.out.println("Taipan, \nWhat will you name your firm:"); System.out.println("Taipan, \nWhat will you name your firm:");
@@ -42,10 +62,15 @@ public class Start
player.setBank(999999999); player.setBank(999999999);
player.setGuns(999); player.setGuns(999);
player.setHP(99999999); player.setHP(99999999);
player.setCargoSpace(99999999);
} }
} }
/**
* Copy constructor.
* @param player object of the class Player
*/
public Start(Player player) public Start(Player player)
{ {
Player playerTemp = new Player(player); Player playerTemp = new Player(player);

View File

@@ -3,108 +3,170 @@ import java.util.Scanner;
public class TaipanShop { public class TaipanShop {
private Player player; private Player player;
private int cargoSpace = 60;
private int currentCargo = 0;
private int opiumPrice = 16000; private int opiumPrice = 16000;
private int silkPrice = 1600; private int silkPrice = 1600;
private int armsPrice = 160; private int armsPrice = 160;
private int generalPrice = 8; private int generalPrice = 8;
/**
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
*/
public void retire(){ public void retire(){
player.setRetire(true); player.setRetire(true);
System.out.println("You win!"); System.out.println("You win!");
System.exit(0);
} }
/**
* 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;
} }
/**
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
*
* @return playerDummy -- playerDummy is a copy of the player instance variable.
*/
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 TaipanShop(Player player){ public TaipanShop(Player player){
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
public int getCargoSpace() { /**
return cargoSpace; * getter for opiumPrice instance variable.
} *
* @return opiumPrice -- the price of opium in the shop
public void setCargoSpace(int cargoSpace) { */
if(cargoSpace > 0){
this.cargoSpace = cargoSpace;
}
}
public int getOpiumPrice() { public int getOpiumPrice() {
return opiumPrice; return opiumPrice;
} }
/**
* setter for the opiumPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param opiumPrice -- what the instance variable opiumPrice should be changed to.
*/
public void setOpiumPrice(int opiumPrice) { public void setOpiumPrice(int opiumPrice) {
if(opiumPrice > 0){ if(opiumPrice > 0){
this.opiumPrice = opiumPrice; this.opiumPrice = opiumPrice;
} }
} }
/**
* getter for silkPrice instance variable.
*
* @return silkPrice -- the price of silk in the shop.
*/
public int getSilkPrice() { public int getSilkPrice() {
return silkPrice; return silkPrice;
} }
/**
* setter for the silkPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param silkPrice -- what the instance variable silkPrice should be changed to.
*/
public void setSilkPrice(int silkPrice) { public void setSilkPrice(int silkPrice) {
if(silkPrice > 0){ if(silkPrice > 0){
this.silkPrice = silkPrice; this.silkPrice = silkPrice;
} }
} }
/**
* getter for armsPrice instance variable.
*
* @return armsPrice -- the price of arms in the shop.
*/
public int getArmsPrice() { public int getArmsPrice() {
return armsPrice; return armsPrice;
} }
/**
* setter for the armsPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param armsPrice -- what the instance variable armsPrice should be changed to.
*/
public void setArmsPrice(int armsPrice) { public void setArmsPrice(int armsPrice) {
if(armsPrice > 0){ if(armsPrice > 0){
this.armsPrice = armsPrice; this.armsPrice = armsPrice;
} }
} }
/**
* getter for generalPrice instance variable.
*
* @return generalPrice -- the price of general cargo in the shop.
*/
public int getGeneralPrice() { public int getGeneralPrice() {
return generalPrice; return generalPrice;
} }
/**
* setter for the generalPrice instance variable. Runs as long as the parameter is greater than 0.
*
* @param generalPrice -- what the instance variable generalPrice should be changed to.
*/
public void setGeneralPrice(int generalPrice) { public void setGeneralPrice(int generalPrice) {
if(generalPrice > 0){ if(generalPrice > 0){
this.generalPrice = generalPrice; this.generalPrice = generalPrice;
} }
} }
/**
* this method is evoked if the user has decided to travel elsewhere.
*/
public void travel(){ public void travel(){
Travel travel = new Travel(player); Travel travel = new Travel(player);
travel.travelTo(); travel.travelTo();
player = travel.getPlayer(); player = travel.getPlayer();
} }
/**
* this method is evoked if the user wants to use the warehouse to store items or take items out.
*/
public void warehouse(){ public void warehouse(){
Warehouse warehouse = new Warehouse(player); Warehouse warehouse = new Warehouse(player);
warehouse.changeWarehouse(); warehouse.changeWarehouse();
player = warehouse.getPlayer(); player = warehouse.getPlayer();
} }
/**
* this method is evoked if the user wants to use the bank to deposit or withdraw money.
*/
public void bank(){ public void bank(){
Bank bank = new Bank(player); Bank bank = new Bank(player);
bank.bank(); bank.bank();
player = bank.getPlayer(); player = bank.getPlayer();
} }
/**
* this method is evoked if the user wants to use get a loan or pay a loan off.
*/
public void loan(){ public void loan(){
loanShark loan = new loanShark(player); loanShark loan = new loanShark(player);
loan.loanMoney(); loan.loanMoney();
player = loan.getPlayer(); player = loan.getPlayer();
} }
private void updatePrices(){ /**
* this method is when the shop is accessed, randomizing the prices of all the items.
*/
public void updatePrices(){
String s = "\n" + player.getName() + ", the price of "; String s = "\n" + player.getName() + ", the price of ";
double value = 80*Math.random(); double value = 80*Math.random();
Random rand = new Random(); Random rand = new Random();
@@ -112,6 +174,8 @@ public class TaipanShop {
silkPrice = (rand.nextInt(201) + 60)*10; silkPrice = (rand.nextInt(201) + 60)*10;
armsPrice = (rand.nextInt(21) + 6)*10; armsPrice = (rand.nextInt(21) + 6)*10;
generalPrice = rand.nextInt(17) + 4; generalPrice = rand.nextInt(17) + 4;
// there is a 10% chance that the price of an item is increased/decreased beyond its regular range.
if(value < 8){ if(value < 8){
if(value < 2){ if(value < 2){
if(value < 1){ if(value < 1){
@@ -149,12 +213,15 @@ public class TaipanShop {
} }
} }
private void printShop(){ /**
currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld(); * this method prints the shop UI and the player's inventory and status.
if(cargoSpace - currentCargo < 0){ */
public void printShop(){
int currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld();
if(player.getCargoSpace() - currentCargo < 0){
System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%"); System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%");
}else{ }else{
System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%"); System.out.println("Hold: " + (player.getCargoSpace()-currentCargo) + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%");
} }
System.out.println("-------------------------------------------------------------"); System.out.println("-------------------------------------------------------------");
System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld()); System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld());
@@ -166,7 +233,14 @@ public class TaipanShop {
System.out.println(" Arms: " + armsPrice + " General: " + generalPrice); System.out.println(" Arms: " + armsPrice + " General: " + generalPrice);
} }
public void atLocationOne(boolean notDone, Scanner input){ /**
* This method is evoked if the user is at the location one port.
*/
public void atLocationOne(){
boolean notDone = true;
Scanner input = new Scanner(System.in);
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){ while(notDone){
printShop(); printShop();
System.out.println("\nShall I Buy, Sell, Visit Bank, Get Loans, Transfer Cargo, or Quit Trading?"); System.out.println("\nShall I Buy, Sell, Visit Bank, Get Loans, Transfer Cargo, or Quit Trading?");
@@ -174,6 +248,8 @@ public class TaipanShop {
if (response.equalsIgnoreCase("B")) { if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true; boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?"); System.out.println("What do you wish me to buy, " + player.getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) { while (notDone2) {
response = input.nextLine(); response = input.nextLine();
if (response.equalsIgnoreCase("O")) { if (response.equalsIgnoreCase("O")) {
@@ -236,7 +312,8 @@ public class TaipanShop {
} }
} else if (response.equalsIgnoreCase("S")) { } // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true; boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?"); System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) { while (notDone2) {
@@ -307,14 +384,22 @@ public class TaipanShop {
warehouse(); warehouse();
}else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) { }else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) {
loan(); loan();
}else if (response.equalsIgnoreCase("Q")) { } // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q")) {
travel(); travel();
notDone = false; notDone = false;
} }
} }
} }
public void notAtLocationOne(boolean notDone, Scanner input){ /**
* This method is evoked when the user is at any port other than location one.
*/
public void notAtLocationOne(){
boolean notDone = true;
Scanner input = new Scanner(System.in);
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){ while(notDone){
printShop(); printShop();
System.out.println("\nShall I Buy, Sell, or Quit Trading?"); System.out.println("\nShall I Buy, Sell, or Quit Trading?");
@@ -322,6 +407,8 @@ public class TaipanShop {
if (response.equalsIgnoreCase("B")) { if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true; boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?"); System.out.println("What do you wish me to buy, " + player.getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) { while (notDone2) {
response = input.nextLine(); response = input.nextLine();
if (response.equalsIgnoreCase("O")) { if (response.equalsIgnoreCase("O")) {
@@ -384,7 +471,8 @@ public class TaipanShop {
} }
} else if (response.equalsIgnoreCase("S")) { } // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true; boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?"); System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) { while (notDone2) {
@@ -447,14 +535,22 @@ public class TaipanShop {
} }
} }
} }
} else if (response.equalsIgnoreCase("Q")) { } // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q")) {
travel(); travel();
notDone = false; notDone = false;
} }
} }
} }
public void retireAndLocationOne(boolean notDone, Scanner input){ /**
* this method is run if the user is eligible to win, and is at location one.
*/
public void retireAndLocationOne(){
boolean notDone = true;
Scanner input = new Scanner(System.in);
// as long as the user does not enter a valid input, the code will run in a loop forever.
while(notDone){ while(notDone){
printShop(); printShop();
System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, Get Loans, Retire, or Quit Trading?"); System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, Get Loans, Retire, or Quit Trading?");
@@ -462,6 +558,8 @@ public class TaipanShop {
if (response.equalsIgnoreCase("B")) { if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true; boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + player.getName() + "?"); System.out.println("What do you wish me to buy, " + player.getName() + "?");
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
while (notDone2) { while (notDone2) {
response = input.nextLine(); response = input.nextLine();
if (response.equalsIgnoreCase("O")) { if (response.equalsIgnoreCase("O")) {
@@ -523,7 +621,8 @@ public class TaipanShop {
} }
} }
} else if (response.equalsIgnoreCase("S")) { } // when selling, the user must enter a non-negative amount of items, and not more than what they have.
else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true; boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + player.getName() + "?"); System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) { while (notDone2) {
@@ -594,26 +693,34 @@ public class TaipanShop {
warehouse(); warehouse();
} else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) { } else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) {
loan(); loan();
}else if (response.equalsIgnoreCase("Q")) { } // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("Q")) {
travel(); travel();
notDone = false; notDone = false;
} else if (response.equalsIgnoreCase("R")) { } // if the user wishes to retire and win the game, they may do so. Doing this breaks them out of the loop.
else if (response.equalsIgnoreCase("R")) {
retire(); retire();
notDone = false; notDone = false;
} }
} }
} }
/**
* the general method that utilizes all the other methods to form a fully functioning shop.
*/
public void shop() { public void shop() {
updatePrices(); updatePrices();
Scanner input = new Scanner(System.in);
boolean notDone = true; // first case is triggered if the user is at location one, and has less than $1 million net worth
if (player.getLocation() == 1 && player.getBank()+player.getMoney()-player.getDebt() < 1000000) { if (player.getLocation() == 1 && player.getBank()+player.getMoney()-player.getDebt() < 1000000) {
atLocationOne(notDone, input); atLocationOne();
}else if(player.getLocation() != 1) { } // the second case is triggered if the user is at a location other than location one.
notAtLocationOne(notDone, input); else if(player.getLocation() != 1) {
}else{ notAtLocationOne();
retireAndLocationOne(notDone, input); } // the last case is triggered when the other conditions are not met; it is triggered when the user has a net
// worth that is greater than or equal to $1 million and is at location one.
else{
retireAndLocationOne();
} }
} }
} }

View File

@@ -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,6 +74,12 @@ 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(3) + 1;
@@ -60,15 +87,25 @@ public class Travel {
peasantFleet(); peasantFleet();
}else if (randGenNum == 2) { }else if (randGenNum == 2) {
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 {
@@ -82,26 +119,39 @@ 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.
* @throws Exception throws Exception so that we can use the time library to make the player if we want to.
**/
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();
} }
/**
*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;
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
while (true) { while (true) {
System.out.println("\n" + player.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?"); 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();
//Just in case the player types something that was not intended. It will refresh the question and ask it again
try { try {
tempInt = Integer.parseInt(response); tempInt = Integer.parseInt(response);
System.out.println(tempInt + " " + player.getLocation()); //Makes sure you can't travel to your own location.
if (tempInt != player.getLocation()) { if (tempInt != player.getLocation()) {
randomEventSea(tempInt); randomEventSea(tempInt);
seaAtlas(tempInt); seaAtlas(tempInt);
@@ -117,4 +167,8 @@ public class Travel {
} }
} }
} }
else{
System.out.println(player.getName() + " the cargo is too heavy! We can't set sail!");
}
}
} }

View File

@@ -1,5 +1,9 @@
import java.util.Scanner; import java.util.Scanner;
/**
* The purpose of this class is to create a warehouse where the goods
* can be safely stored without holing space on the ship!
*/
public class Warehouse { public class Warehouse {
/*private int wOpium = 0; /*private int wOpium = 0;
private int wSilk = 0; private int wSilk = 0;
@@ -7,43 +11,75 @@ public class Warehouse {
private int wArms = 0;*/ private int wArms = 0;*/
private Player player; private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
public void setPlayer(Player player) { public void setPlayer(Player player) {
Player playerDumy = new Player(player); Player playerDumy = new Player(player);
this.player = playerDumy; this.player = playerDumy;
} }
/**
* 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;
} }
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public Warehouse(Player player) { public Warehouse(Player player) {
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
/**
* This method adds an amount of a certain good
* the user is prompted to enter the amount they would like to
* add followed by the good they would like to add to the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
*
*/
public void addAmount() { public void addAmount() {
boolean askGood = false; boolean askGood = false;
String amount; String amount;
int finalAmount = 0; int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to ADD."); System.out.println("Please enter the amount of the good you would like to ADD.");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
amount = keyboard.nextLine(); amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add
/*The try function ensures that the program does not crash
due to any errors while giving the program an incorrect input*/
try { try {
//The if statement checks that you have enough resources to make the transfer
if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) { if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) {
finalAmount = Integer.parseInt(amount); finalAmount = Integer.parseInt(amount);
askGood = true; askGood = true;
} else { }
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
else {
System.out.println("Nice try but you don't have any items of that quantity!"); System.out.println("Nice try but you don't have any items of that quantity!");
askGood = false; askGood = false;
} }
//Ensures that goods are only transferred if they have the specified amount
//The user is prompted to enter which good they want to transfer
if (askGood == true) { if (askGood == true) {
String good; String good;
System.out.println("Please enter a good to transfer O, S, G, A :"); System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine(); good = keyboard.nextLine();
int held = 0; int held = 0;
//The following set of loops check to see which good the user has selected and makes the transfer
if (Integer.parseInt(amount) > 0) { if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) { if (good.equalsIgnoreCase("O")) {
if (player.getOpiumHeld() >= Integer.parseInt(amount)) { if (player.getOpiumHeld() >= Integer.parseInt(amount)) {
@@ -81,36 +117,57 @@ public class Warehouse {
System.out.println("You don't even have that much Arms!"); System.out.println("You don't even have that much Arms!");
} }
} }
} else { }
//Ensures no negative amounts are entered
else {
System.out.println("Sorry this transfer cannot be made"); System.out.println("Sorry this transfer cannot be made");
} }
} }
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
} catch (Exception e) { } catch (Exception e) {
System.out.println("Wait, that's not a valid input please try again"); System.out.println("Wait, that's not a valid input please try again");
} }
} }
/**
* This method removes an amount of a certain good
* the user is prompted to enter the amount they would like to
* remove followed by the good they would like to remove from the warehouse.
* the method checks if the player has sufficient goods to transfer, and if the player does
* then the method executes the transfer
*
*/
public void removeAmount() { public void removeAmount() {
String amount; String amount;
boolean askGood = false; boolean askGood = false;
int finalAmount = 0; int finalAmount = 0;
System.out.println("Please enter the amount of the good you would like to REMOVE"); System.out.println("Please enter the amount of the good you would like to REMOVE");
Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in);
//Prompts the user for the amount they would like to remove
amount = keyboard.nextLine(); amount = keyboard.nextLine();
//The if statement checks that you have enough resources to make the transfer
try { try {
//The if statement checks that you have enough resources to make the transfer
if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) { if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) {
finalAmount = Integer.parseInt(amount); finalAmount = Integer.parseInt(amount);
askGood = true; askGood = true;
} else { }
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
else {
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!"); System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
askGood = false; askGood = false;
} }
//Ensures that goods are only transferred if they have the specified amount
//The user is prompted to enter which good they want to transfer
if (askGood == true) { if (askGood == true) {
String good; String good;
System.out.println("Please enter a good to transfer O, S, G, A :"); System.out.println("Please enter a good to transfer O, S, G, A :");
good = keyboard.nextLine(); good = keyboard.nextLine();
int held = 0; int held = 0;
//The following set of loops check to see which good the user has selected and makes the transfer and amount > 0
if (Integer.parseInt(amount) > 0) { if (Integer.parseInt(amount) > 0) {
if (good.equalsIgnoreCase("O")) { if (good.equalsIgnoreCase("O")) {
if (player.getwOpium() >= Integer.parseInt(amount)) { if (player.getwOpium() >= Integer.parseInt(amount)) {
@@ -147,16 +204,24 @@ public class Warehouse {
} }
} }
} else { }
//Ensures the value entered is positive
else {
System.out.println("Sorry this transfer cannot be made"); System.out.println("Sorry this transfer cannot be made");
} }
} }
}catch (Exception e){ }
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
catch (Exception e){
System.out.println("Wait, that's not a valid input please try again"); System.out.println("Wait, that's not a valid input please try again");
} }
} }
/**
* This method prints the stock that is in the warehouse currently using the get and set
* methods from the player class. This is to allow the user to be able to know how much they have
* stored in the warehouse
*/
public void showWarehouse() { public void showWarehouse() {
System.out.println("--------------------\nWarehouse\n--------------------"); System.out.println("--------------------\nWarehouse\n--------------------");
System.out.println("Opium : " + player.getwOpium()); System.out.println("Opium : " + player.getwOpium());
@@ -165,7 +230,11 @@ public class Warehouse {
System.out.println("Arms : " + player.getwArms()); System.out.println("Arms : " + player.getwArms());
} }
/**
* This method combines the add and remove methods and prompts the user to
* enter what they would like to do. Add or remove and accordingly invokes
* the required methods
*/
public void changeWarehouse() { public void changeWarehouse() {
boolean keepGoing = true; boolean keepGoing = true;
while (keepGoing) { while (keepGoing) {
@@ -187,6 +256,7 @@ public class Warehouse {
} }
String check; String check;
//Check to see if the player wants to continue in the warehouse or they are done
System.out.println("Would you like to do any other business? Y / N?"); System.out.println("Would you like to do any other business? Y / N?");
check = keyboard.nextLine(); check = keyboard.nextLine();
check = keyboard.nextLine(); check = keyboard.nextLine();
@@ -199,7 +269,4 @@ public class Warehouse {
} }
} }
public static void main(String[] args) {
}
} }

View File

@@ -2,38 +2,86 @@ import java.util.Scanner;
public class loanShark { public class loanShark {
private Player player; private Player player;
/**
* setter method that takes in a Player object as an argument.
*
* @param player object of the class Player
*/
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;
} }
/**
* Class Constructor that takes in a type player as a parameter
*
* @param player object of the class Player
*/
public loanShark(Player player){ public loanShark(Player player){
Player playerDummy = new Player(player); Player playerDummy = new Player(player);
this.player = playerDummy; this.player = playerDummy;
} }
/**
* This methods purpose is to loan the player the funds it wants
* or pay its outstanding debts. The method prompts the user if they
* would like to borrow money or repay. depending on what the player chooses
* the corresponding loop is evoked. The player can only be loaned 2 times the
* money they have minus the debt id their debt exceeds the cash balance, the loan
* cannot be given.
*/
public void loanMoney() { public void loanMoney() {
boolean keepGoing = true; boolean keepGoing = true;
while(keepGoing) { while(keepGoing) {
String check;
Scanner keyboard = new Scanner(System.in);
System.out.println("Would you like to return money or borrow money?");
//Prompts the user or what they would like to do
check = keyboard.nextLine();
//If the user chooses to return money, the money is subtracted from the cash amount and debt
if(check.equalsIgnoreCase("r")){
int returnAsk = 0;
System.out.println("Please enter how much you would like to return?");
returnAsk = keyboard.nextInt();
if(returnAsk <= player.getDebt() && returnAsk >= 0) {
player.setDebt(player.getDebt() - returnAsk);
player.setMoney(player.getMoney() - returnAsk);
}
//if you try to return more money than you owe it wont allow you to
else if(returnAsk > player.getDebt()){
System.out.println("You don't need to return that much!");
}
//No negative amounts are allowed
else{
System.out.println("You can't return a negative amount.");
}
}
//If the user chooses to borrow, the money is added to cash and the debt is increased
else if(check.equalsIgnoreCase("b")){
int loanAsk = 0; int loanAsk = 0;
System.out.println("Please enter how much you would like to borrow"); System.out.println("Please enter how much you would like to borrow");
Scanner keyboard = new Scanner(System.in); //Prompts user for the amount they would like to borrow
loanAsk = keyboard.nextInt(); loanAsk = keyboard.nextInt();
if(loanAsk <= 2*(player.getMoney() - player.getDebt())) { if(loanAsk <= 2*(player.getMoney() - player.getDebt())&& loanAsk >= 0) {
player.setDebt(player.getDebt() + loanAsk); player.setDebt(player.getDebt() + loanAsk);
player.setMoney(player.getMoney() + loanAsk); player.setMoney(player.getMoney() + loanAsk);
} }
//updated //If the requested money exceeds 2*(cash - debt) then the loan cannot be given
else{ else{
System.out.println("Sorry you can't be loaned that much"); System.out.println("Sorry you can't be loaned that much");
break; break;
} }
String check; }
//Asks the player if they have any other things to do with the load shark
System.out.println("Would you like to do any other business? Y / N?"); System.out.println("Would you like to do any other business? Y / N?");
check = keyboard.nextLine(); check = keyboard.nextLine();
check = keyboard.nextLine(); check = keyboard.nextLine();

View File

@@ -2,23 +2,46 @@ public class main {
private Player player = new Player(); private Player player = new Player();
/**
* getter method for the Player object player.
*
* @return returns a copy of the object player
*/
public Player getPlayer(){ public Player getPlayer(){
Player copy = new Player(player); Player copy = new Player(player);
return copy; return copy;
} }
/**
* Initializes the Taipan shop with the players stats after the player finishes shopping, it updates the player object and returns it.
*
* @param shop player object from the main class used to update the shop class
*/
public void shop(TaipanShop shop){ public void shop(TaipanShop shop){
shop.setPlayer(player); shop.setPlayer(player);
shop.shop(); shop.shop();
player = shop.getPlayer(); player = shop.getPlayer();
} }
/**
* Initializes the player object with 5 guns or $400 and $5000 debt.
*
* @param start player object from the main class used to update the start class
*/
public void start(Start start){ public void start(Start start){
start.setPlayer(player); start.setPlayer(player);
start.intialize(); start.initialize();
player = start.getPlayer(); player = start.getPlayer();
} }
/**
* 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.
* @param args Just the console for the player to look at.
*/
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());