Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ActionMaster {
- public enum Action { Tidy, Reset, EndTurn, EndGame } ;
- public int[] bowls = new int[21] ;
- public int bowl = 1 ;
- public Action Bowl (int pins) {
- if (pins < 0 || pins > 10) {throw new UnityException ("Invalid Pins !");}
- if (bowl == 21) {
- return Action.EndGame ;
- }
- bowls [ bowl -1] = pins ;
- if (bowl == 19 && Bowl21StrikeAt19()) { //
- // if scored a strike in bowl 19 reset
- bowl +=1 ;
- return Action.Reset ;
- }
- if (bowl == 20 && Bowl21StrikeAt19()) { // T11PaulRequireResetAt20()
- if (Bowl21StrikeAt20()) { // if a strike was scored in bowl 19
- bowl +=1 ; // And another strike was scored in 20 do a reset
- return Action.Reset ;
- }
- }
- if (bowl == 19 && Bowl21StrikeAt19() ) { // T09DarylRequireTidyAt20()
- if (!Bowl21StrikeAt20()) { // if a strike was scored in bowl 19
- bowl +=1 ; // and 0-9 was scored in bowl 20 do a tidy
- return Action.Tidy ;
- }
- }
- if (bowl == 20 && Bowl21StrikeAt19()) {
- bowl +=1 ; // if its bowl 20 and a strike was scored
- return Action.Tidy ; // in bowl 19 do a tidy
- }
- if (bowl == 20 && Bowl21SpareAt20()) { // T05CheckResetAtSpareInLastFrame()
- // play one more ball
- bowl +=1 ; // because of spare with final ball
- return Action.Reset ;
- }
- if (bowl == 20 && ( !Bowl21StrikeAt19()
- ||!Bowl21StrikeAt20()
- ||!Bowl21SpareAt20 () )) {//T08GameEndsAtBowl20()
- //at bowl 20 if no ball awarded endgame
- bowl += 1 ;
- return Action.EndGame ;
- }
- if (bowl %2 != 0) { //first bowl of frame , uses Mod (remainder)
- if (pins == 10) {
- bowl += 2 ;
- return Action.EndTurn ;
- }else { // second bowl of frame
- bowl += 1 ;
- return Action.Tidy ;
- }
- } else if (bowl % 2 == 0) { //end of frame
- bowl += 1 ;
- return Action.EndTurn ;
- }
- throw new UnityException ("Not sure what action to return!") ;
- }
- private bool Bowl21StrikeAt20() {
- // arrays start counting at 0
- return ( bowls [20-1] >= 10) ;
- }
- private bool Bowl21SpareAt20() {
- // arrays start counting at 0
- return ( bowls [19-1] + bowls [20-1] >= 10) ;
- }
- private bool Bowl21StrikeAt19() {
- // arrays start counting at 0
- return (bowls [19-1] >= 10) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement