Advertisement
Guest User

ActionMaster Script

a guest
Sep 3rd, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ActionMaster {
  5.  
  6. public enum Action { Tidy, Reset, EndTurn, EndGame } ;
  7. public int[] bowls = new int[21] ;
  8. public int bowl = 1 ;
  9.  
  10.  
  11. public Action Bowl (int pins) {
  12. if (pins < 0 || pins > 10) {throw new UnityException ("Invalid Pins !");}
  13.  
  14.  
  15. if (bowl == 21) {
  16.  
  17. return Action.EndGame ;
  18. }
  19.  
  20.  
  21. bowls [ bowl -1] = pins ;
  22.  
  23.  
  24. if (bowl == 19 && Bowl21StrikeAt19()) { //
  25. // if scored a strike in bowl 19 reset
  26. bowl +=1 ;
  27. return Action.Reset ;
  28. }
  29.  
  30. if (bowl == 20 && Bowl21StrikeAt19()) { // T11PaulRequireResetAt20()
  31. if (Bowl21StrikeAt20()) { // if a strike was scored in bowl 19
  32. bowl +=1 ; // And another strike was scored in 20 do a reset
  33. return Action.Reset ;
  34. }
  35. }
  36.  
  37. if (bowl == 19 && Bowl21StrikeAt19() ) { // T09DarylRequireTidyAt20()
  38. if (!Bowl21StrikeAt20()) { // if a strike was scored in bowl 19
  39. bowl +=1 ; // and 0-9 was scored in bowl 20 do a tidy
  40. return Action.Tidy ;
  41.  
  42. }
  43. }
  44.  
  45. if (bowl == 20 && Bowl21StrikeAt19()) {
  46. bowl +=1 ; // if its bowl 20 and a strike was scored
  47. return Action.Tidy ; // in bowl 19 do a tidy
  48.  
  49. }
  50.  
  51.  
  52. if (bowl == 20 && Bowl21SpareAt20()) { // T05CheckResetAtSpareInLastFrame()
  53. // play one more ball
  54. bowl +=1 ; // because of spare with final ball
  55. return Action.Reset ;
  56. }
  57.  
  58. if (bowl == 20 && ( !Bowl21StrikeAt19()
  59. ||!Bowl21StrikeAt20()
  60. ||!Bowl21SpareAt20 () )) {//T08GameEndsAtBowl20()
  61. //at bowl 20 if no ball awarded endgame
  62. bowl += 1 ;
  63. return Action.EndGame ;
  64. }
  65.  
  66.  
  67. if (bowl %2 != 0) { //first bowl of frame , uses Mod (remainder)
  68. if (pins == 10) {
  69. bowl += 2 ;
  70. return Action.EndTurn ;
  71. }else { // second bowl of frame
  72. bowl += 1 ;
  73. return Action.Tidy ;
  74. }
  75.  
  76. } else if (bowl % 2 == 0) { //end of frame
  77. bowl += 1 ;
  78. return Action.EndTurn ;
  79. }
  80.  
  81.  
  82. throw new UnityException ("Not sure what action to return!") ;
  83. }
  84.  
  85. private bool Bowl21StrikeAt20() {
  86. // arrays start counting at 0
  87. return ( bowls [20-1] >= 10) ;
  88.  
  89. }
  90.  
  91. private bool Bowl21SpareAt20() {
  92. // arrays start counting at 0
  93. return ( bowls [19-1] + bowls [20-1] >= 10) ;
  94.  
  95. }
  96. private bool Bowl21StrikeAt19() {
  97. // arrays start counting at 0
  98. return (bowls [19-1] >= 10) ;
  99.  
  100.  
  101.  
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement