Advertisement
Trankalinos

Action

Oct 23rd, 2011
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. public void act(int whichStock, Action action, int amount) {
  2. if (isStarted() == true){
  3. // checks if the game is started. If so, continue. If not, do nothing.
  4. if (whichStock == 1){
  5. // if the whichStock is equal to 1, do this for stock1. Otherwise, check if whichStock is equal to 2 or 3.
  6. switch(action){
  7. case UP:
  8. int splitValue1 = stock1.getValue() + amount;
  9. // this allows our parameters to be above 200. Recall in our Stock class, we restricted everything between 5 and 195.
  10. if (splitValue1 >= 200){
  11. stock1.setValue(100);
  12. // reset the value of stock to 100, then double the player's stock1 holding.
  13. player.setHolding1(player.getHolding1()*2);
  14. }
  15. else{
  16. stock1.setValue(splitValue1);
  17. // otherwise, just set the new value as normal, if the value is less than 195.
  18. }
  19. break;
  20. case DOWN:
  21. int delistValue1 = stock1.getValue() - amount;
  22. // same thing as above, except it allows our stock to be below 0. Remember, we restricted our values to 5 and 195.
  23. if (delistValue1 <= 0){
  24. // 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.
  25. stock1.setValue(100);
  26. player.setHolding1(0);
  27. }
  28. else {
  29. // otherwise, just minus the amount as usual.
  30. stock1.setValue(delistValue1);
  31. }
  32. //handle a delisting
  33. break;
  34. case DIV:
  35. // if stock is payable, which pretty much means, if the stock's value is greater than or equal to 100
  36. // in otherwords, this is where the player is getting paid.
  37. if (stock1.getValue() >= 100){
  38. // then have the player's cash value become a new value where the player's current cash is added with
  39. // the player's current stock1 holding multiplied by the amount.
  40. player.setCash(player.getCash() + player.getHolding1()*amount);
  41. }
  42. break;
  43. }
  44. }
  45. else if (whichStock == 2){
  46. // test if should be 2 or 3
  47. switch(action){
  48. case UP:
  49. int splitValue2 = stock2.getValue() + amount;
  50. if (splitValue2 >= 200){
  51. stock2.setValue(100);
  52. player.setHolding2(player.getHolding2()*2);
  53. }
  54. else {
  55. stock2.setValue(splitValue2);
  56. }
  57. break;
  58. case DOWN:
  59. int delistValue2 = stock2.getValue() - amount;
  60. if (delistValue2 <= 0){
  61. stock2.setValue(100);
  62. player.setHolding2(0);
  63. }
  64. else {
  65. stock2.setValue(delistValue2);
  66. }
  67. //handle a delisting
  68. break;
  69. case DIV:
  70. //... output
  71. // if stock is payable...
  72. if (stock2.getValue() >= 100){
  73. player.setCash(player.getCash() + player.getHolding2()*amount);
  74. }
  75. break;
  76. }
  77. }
  78. else if (whichStock == 3){
  79. // test if should be 2 or 3
  80. switch(action){
  81. case UP:
  82. int splitValue3 = stock3.getValue() + amount;
  83. if (splitValue3 >= 200){
  84. stock3.setValue(100);
  85. player.setHolding3(player.getHolding3()*2);
  86. }
  87. else {
  88. stock3.setValue(splitValue3);
  89. }
  90. break;
  91. case DOWN:
  92. int delistValue3 = stock3.getValue() - amount;
  93. if (delistValue3 <= 0){
  94. stock3.setValue(100);
  95. player.setHolding3(0);
  96. }
  97. else {
  98. stock3.setValue(delistValue3);
  99. }
  100. //handle a delisting
  101. break;
  102. case DIV:
  103. //... output
  104. // if stock is payable...
  105. if (stock3.getValue() >= 100){
  106. player.setCash(player.getCash() + player.getHolding3()*amount);
  107. }
  108. break;
  109. }
  110. }
  111. }
  112. else if (isOver() == true){
  113. return;
  114. }
  115. }
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement