Exemplo n.º 1
0
        /// <summary>
        /// Checks All Conditions to See if Player Who Played Last Has Won
        /// </summary>
        /// <param name="LastPlayed">The Space Last Played.</param>
        public void CheckVictory(GridSpace LastPlayed)
        {
            Debug.Log("Checking Victory");

            //Get Grid Parent For Future Checks
            Grid.Grid Parent = LastPlayed.GetComponentInParent <Grid.Grid>();

            Debug.Log(string.Format("Grid to Check: {0}", Parent.name));
            Debug.Log(string.Format("Space to Check: {0}", LastPlayed.DisplayStr));

            bool PlayerWin = Parent.CheckRow(LastPlayed);

            if (!PlayerWin)
            {
                PlayerWin = Parent.CheckColumn(LastPlayed);

                if (!PlayerWin)
                {
                    PlayerWin = Parent.CheckDiagonal(LastPlayed);
                }
            }

            //After All Needed Checks, If Player Won
            if (PlayerWin)
            {
                //End Game
                EndGame(TurnManager.instance.CurrentPlayer);
            }
            else
            {
                //Check to See if Grid is Full
                if (Parent.CheckFull())
                {
                    //If So, End in Draw
                    EndGame(0);
                }
                else
                {
                    //Move to the Next Turn
                    TurnManager.instance.NextTurn();
                }
            }
        }