Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void act(int whichStock, Action action, int amount) {
- Stock stock01 = stock1;
- Stock stock02 = stock2;
- Stock stock03 = stock3;
- //test if should be 2 or 3
- if (isStarted() == true) {
- switch (action) {
- case UP:
- //handle a stock split
- if (stock01.getValue() + amount >= 200) {
- player.setHolding1(player.getHolding1() * 2);
- stock01.setValue(100);
- log("SPLIT: Set player " + player.getName() + "'s " + stock01.getName() + " to " + player.getHolding1() + " and reset stock to 100");
- } else if (stock02.getValue() + amount >= 200) {
- player.setHolding2(player.getHolding2() * 2);
- stock02.setValue(100);
- log("SPLIT: Set player " + player.getName() + "'s " + stock02.getName() + " to " + player.getHolding2() + " and reset stock to 100");
- } else if (stock03.getValue() + amount >= 200) {
- player.setHolding3(player.getHolding3() * 2);
- stock03.setValue(100);
- log("SPLIT: Set player " + player.getName() + "'s " + stock03.getName() + " to " + player.getHolding3() + " and reset stock to 100");
- } else {
- //handle a stock increase
- switch (whichStock) {
- case 1:
- stock01.setValue(stock01.getValue() + amount);
- log("Increased " + stock01.getName() + " by " + amount);
- break;
- case 2:
- stock02.setValue(stock02.getValue() + amount);
- log("Increased " + stock02.getName() + " by " + amount);
- break;
- case 3:
- stock03.setValue(stock03.getValue() + amount);
- log("Increased " + stock03.getName() + " by " + amount);
- break;
- }
- }
- break;
- case DOWN:
- //handle a stock delist
- if (stock01.getValue() - amount <= 0) {
- player.setHolding1(0);
- stock01.setValue(100);
- log("DELIST: Set player " + player.getName() + "'s " + stock01.getName() + " to " + player.getHolding1() + " and reset stock to 100");
- } else if (stock02.getValue() - amount <= 0) {
- player.setHolding2(0);
- stock02.setValue(100);
- log("DELIST: Set player " + player.getName() + "'s " + stock02.getName() + " to " + player.getHolding2() + " and reset stock to 100");
- } else if (stock03.getValue() - amount <= 0) {
- player.setHolding3(0);
- stock03.setValue(100);
- log("DELIST: Set player " + player.getName() + "'s " + stock03.getName() + " to " + player.getHolding3() + " and reset stock to 100");
- } else {
- switch (whichStock) {
- case 1:
- stock01.setValue(stock01.getValue() - amount);
- log("Decreased " + stock01.getName() + " by " + amount);
- break;
- case 2:
- stock02.setValue(stock02.getValue() - amount);
- log("Decreased " + stock01.getName() + " by " + amount);
- break;
- case 3:
- stock03.setValue(stock03.getValue() - amount);
- log("Decreased " + stock01.getName() + " by " + amount);
- break;
- }
- }
- break;
- case DIV:
- switch (whichStock) {
- case 1:
- if (stock01.getValue() >= 100) {
- player.setCash(player.getCash() + (player.getHolding1() * amount));
- log("Payed dividend of " + (player.getHolding1() * amount) + " to stock " + stock01.getName());
- break;
- } else {
- break;
- }
- case 2:
- if (stock02.getValue() >= 100) {
- player.setCash(player.getCash() + (player.getHolding2() * amount));
- log("Payed dividend of " + (player.getHolding2() * amount) + " to stock " + stock02.getName());
- break;
- } else {
- break;
- }
- case 3:
- if (stock03.getValue() >= 100) {
- player.setCash(player.getCash() + (player.getHolding3() * amount));
- log("Payed dividend of " + (player.getHolding3() * amount) + " to stock " + stock03.getName());
- break;
- } else {
- break;
- }
- }
- break;
- }
- } else if (isOver() == true) {
- return;
- }
- }
Add Comment
Please, Sign In to add comment