Advertisement
Guest User

New way to save bowl number

a guest
May 1st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ActionMaster {
  5.     public enum Action{Tidy, Reset, EndFrame, EndGame}
  6.     private int roll =0;
  7.     private int frame =0;
  8.  
  9.     private int[,] frameList = new int[10,3];
  10.  
  11.     public Action Bowl (int pins)
  12.     {
  13.         frameList [frame, roll] = pins;
  14.  
  15.         //For the error input;
  16.         if (pins < 0 || pins > 10) {
  17.             throw new UnityException ("Invaild pins number!");
  18.         }
  19.  
  20.         //Handle last frame situation.
  21.         if (frame == 10 - 1) {
  22.  
  23.             if (roll == 0) {//Last frame first roll;
  24.                 if (pins == 10) {
  25.                     roll++;
  26.                     return Action.Reset;
  27.                 }
  28.             }
  29.  
  30.             if (roll == 1) {// Last frame second roll;
  31.                 if (isSpare () || frameList[frame,roll] == 10) {
  32.                     roll++;
  33.                     return Action.Reset;
  34.                 } else if (frameList [9, 0] == 10) {
  35.                     roll++;
  36.                     return Action.Tidy;
  37.                 } else {
  38.                     return Action.EndGame;
  39.                 }
  40.             }
  41.  
  42.             if (roll == 2) {// Last frame last roll;
  43.                 return Action.EndGame;
  44.             }
  45.  
  46.         }
  47.  
  48.         //Handle the strike situation.
  49.         if (pins == 10) {
  50.             NextFrame ();
  51.             return Action.EndFrame;
  52.         }
  53.  
  54.         //Gneral situation.
  55.         if (roll == 0) {
  56.             roll =1;
  57.             return Action.Tidy;
  58.         } else {
  59.             NextFrame ();
  60.             return Action.EndFrame;
  61.         }
  62.     }
  63.  
  64.     void NextFrame ()
  65.     {
  66.         roll = 0;
  67.         frame++;
  68.     }
  69.  
  70.     bool isSpare ()
  71.     {
  72.         return (frameList[10-1,1-1] + frameList[10-1,2-1] >=10 && frameList[10-1,1-1] !=10);
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement