Guest User

actionmaster script

a guest
Apr 11th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. public Action Bowl(int pins)
  2.     {
  3.         if (pins < 0 || pins > 10)
  4.             throw new UnityException("Invalid pin count");
  5.         bowls[bowl - 1] = pins;     //assigns the pins knocked for each bowl
  6.         //other cases will be added here
  7.         if (bowl == 21)        //end gme at bowl 21
  8.         {
  9.             return Action.EndGame;
  10.         }
  11.         if(bowl>=19 && Bowl21Awarded())     //last frame special cases
  12.         {
  13.             bowl++;
  14.             if (((bowls[20 - 1] + bowls[19-1])%10)==0)
  15.             {
  16.                 return Action.Reset;
  17.             }
  18.                  return Action.Tidy;
  19.         }
  20.         else if (bowl == 20 && !Bowl21Awarded())
  21.         {
  22.             return Action.EndGame;
  23.         }
  24.  
  25.         if (pins == 10)    //ends turn at strike
  26.         {
  27.             bowl += 2;
  28.             return Action.EndTurn;
  29.         }
  30.  
  31.         if (bowl % 2 != 0) //if we are in middle frame
  32.         {
  33.             bowl++;
  34.             return Action.Tidy;
  35.         }
  36.         else if(bowl % 2 == 0) //if we are in end of frame
  37.         {
  38.             bowl++;
  39.             return Action.EndTurn;
  40.         }
  41.         if (pins == 0)    
  42.         {
  43.             bowl++;
  44.             return Action.EndTurn;
  45.         }
  46.         //other cases will be added here
  47.  
  48.         throw new UnityException("Cant decide what action to perform");
  49.     }
  50.     public bool Bowl21Awarded()     //bowl 21 awarded only if sum of pins knocked down in bowls 19 and 20 >10
  51.     {
  52.         return (bowls[19 - 1] + bowls[20 - 1] >= 10);     //array index starts at 0
  53.     }
  54. }
Add Comment
Please, Sign In to add comment