// Cleans up all data leftovers after a shot is finished // GLOBAL protected void ShotCleanUp() { // clean up shotBallsPut.Clear(); shotBallsPut.TrimExcess(); shotBallsHit.Clear(); shotBallsHit.TrimExcess(); shotBallsOnTable.Clear(); shotBallsOnTable.TrimExcess(); shotScore = 0; foul = FoulEnum.Clear; }
// Will be called when balls are stopped after a shot. When playing multiplayer this will be activated only by the active player. Passive player will call ShotShort method // GLOBAL protected virtual void ShotLong() { if (galaxyManagerActive) { shotsTaken++; GalaxyManager.Instance.StatsAndAchievements.SetStatInt("shotsTaken", shotsTaken); } CountBallsOnTable(); shotScore = ScoreCounter(); foul = FoulDecider(); ballOn = BallOnDecider(); Respot(); ShotDecider(); StartCoroutine(DisplayShotStats()); PlayingNext(); GameEnd(); ShotCleanUp(); }
// To be called at the end of each shot, in shot method, decides wheter foul was committed during the shot // GLOBAL protected FoulEnum FoulDecider() { FoulEnum foul = FoulEnum.Clear; // check if any ball was hit... if (shotBallsHit.Count == 0) { foul = FoulEnum.NoHit; Debug.Log("Foul, balls hit: No hit"); // if not, no wrong ball was hit first } else if (shotBallsHit[0] != ballOn && !(ballOn == BallColorEnum.Color && shotBallsHit[0] != BallColorEnum.Red)) { foul = FoulEnum.HitWrong; Debug.Log("Foul, balls hit: Hit wrong"); } // check if all balls where put according to the ballOn if (shotBallsPut.Count != 0) { foreach (BallColorEnum ball in shotBallsPut) { if (ball != ballOn && !(ballOn == BallColorEnum.Color && ball != BallColorEnum.Red)) { foul = FoulEnum.PutWrong; Debug.Log("Foul, balls put: Put wrong"); } } } // check if white ended up in hole if (shotBallsPut.Contains(BallColorEnum.White)) { foul = FoulEnum.WhiteInHole; Debug.Log("Foul: white in hole"); } return(foul); }