Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Action Bowl(int pins)
- {
- if (pins < 0 || pins > 10)
- throw new UnityException("Invalid pin count");
- bowls[bowl - 1] = pins; //assigns the pins knocked for each bowl
- //other cases will be added here
- if (bowl == 21) //end gme at bowl 21
- {
- return Action.EndGame;
- }
- if(bowl>=19 && Bowl21Awarded()) //last frame special cases
- {
- bowl++;
- if (((bowls[20 - 1] + bowls[19-1])%10)==0)
- {
- return Action.Reset;
- }
- return Action.Tidy;
- }
- else if (bowl == 20 && !Bowl21Awarded())
- {
- return Action.EndGame;
- }
- if (pins == 10) //ends turn at strike
- {
- bowl += 2;
- return Action.EndTurn;
- }
- if (bowl % 2 != 0) //if we are in middle frame
- {
- bowl++;
- return Action.Tidy;
- }
- else if(bowl % 2 == 0) //if we are in end of frame
- {
- bowl++;
- return Action.EndTurn;
- }
- if (pins == 0)
- {
- bowl++;
- return Action.EndTurn;
- }
- //other cases will be added here
- throw new UnityException("Cant decide what action to perform");
- }
- public bool Bowl21Awarded() //bowl 21 awarded only if sum of pins knocked down in bowls 19 and 20 >10
- {
- return (bowls[19 - 1] + bowls[20 - 1] >= 10); //array index starts at 0
- }
- }
Add Comment
Please, Sign In to add comment