Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void act(int whichStock, Action action, int amount) {
- if (isStarted() == true){
- // checks if the game is started. If so, continue. If not, do nothing.
- if (whichStock == 1){
- // if the whichStock is equal to 1, do this for stock1. Otherwise, check if whichStock is equal to 2 or 3.
- switch(action){
- case UP:
- int splitValue1 = stock1.getValue() + amount;
- // this allows our parameters to be above 200. Recall in our Stock class, we restricted everything between 5 and 195.
- if (splitValue1 >= 200){
- stock1.setValue(100);
- // reset the value of stock to 100, then double the player's stock1 holding.
- player.setHolding1(player.getHolding1()*2);
- }
- else{
- stock1.setValue(splitValue1);
- // otherwise, just set the new value as normal, if the value is less than 195.
- }
- break;
- case DOWN:
- int delistValue1 = stock1.getValue() - amount;
- // same thing as above, except it allows our stock to be below 0. Remember, we restricted our values to 5 and 195.
- if (delistValue1 <= 0){
- // if the value is less than or equal to 0, then set the value to 100 again, but set the player's stock1 holding to 0.
- stock1.setValue(100);
- player.setHolding1(0);
- }
- else {
- // otherwise, just minus the amount as usual.
- stock1.setValue(delistValue1);
- }
- //handle a delisting
- break;
- case DIV:
- // if stock is payable, which pretty much means, if the stock's value is greater than or equal to 100
- // in otherwords, this is where the player is getting paid.
- if (stock1.getValue() >= 100){
- // then have the player's cash value become a new value where the player's current cash is added with
- // the player's current stock1 holding multiplied by the amount.
- player.setCash(player.getCash() + player.getHolding1()*amount);
- }
- break;
- }
- }
- else if (whichStock == 2){
- // test if should be 2 or 3
- switch(action){
- case UP:
- int splitValue2 = stock2.getValue() + amount;
- if (splitValue2 >= 200){
- stock2.setValue(100);
- player.setHolding2(player.getHolding2()*2);
- }
- else {
- stock2.setValue(splitValue2);
- }
- break;
- case DOWN:
- int delistValue2 = stock2.getValue() - amount;
- if (delistValue2 <= 0){
- stock2.setValue(100);
- player.setHolding2(0);
- }
- else {
- stock2.setValue(delistValue2);
- }
- //handle a delisting
- break;
- case DIV:
- //... output
- // if stock is payable...
- if (stock2.getValue() >= 100){
- player.setCash(player.getCash() + player.getHolding2()*amount);
- }
- break;
- }
- }
- else if (whichStock == 3){
- // test if should be 2 or 3
- switch(action){
- case UP:
- int splitValue3 = stock3.getValue() + amount;
- if (splitValue3 >= 200){
- stock3.setValue(100);
- player.setHolding3(player.getHolding3()*2);
- }
- else {
- stock3.setValue(splitValue3);
- }
- break;
- case DOWN:
- int delistValue3 = stock3.getValue() - amount;
- if (delistValue3 <= 0){
- stock3.setValue(100);
- player.setHolding3(0);
- }
- else {
- stock3.setValue(delistValue3);
- }
- //handle a delisting
- break;
- case DIV:
- //... output
- // if stock is payable...
- if (stock3.getValue() >= 100){
- player.setCash(player.getCash() + player.getHolding3()*amount);
- }
- break;
- }
- }
- }
- else if (isOver() == true){
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement