Example #1
0
 public void OnPlayMade(PlayMadeEvent e)
 {
     emptySpaces--;
     if (CheckForWin(e.tileSpace.coord))
     {
         Services.EventManager.Fire(new GameEndEvent(e.player));
     }
     else if (AllSpacesOccupied())
     {
         Services.EventManager.Fire(new GameEndEvent(null));
     }
     else
     {
     }
 }
 public void OnPlayMade(PlayMadeEvent e)
 {
     //  To optimize checking for empty spaces, I cache the value in a variable.
     //  If no has won and emptySpaces is 0, the game is a tie.
     //  Checking for ties this way saves me from checking each tile after a play is made
     emptySpaces--;
     if (CheckForWin(e.tileSpace.coord))
     {
         Services.EventManager.Fire(new GameEndEvent(e.player));
     }
     else if (AllSpacesOccupied())
     {
         Services.EventManager.Fire(new GameEndEvent(null));
     }
 }
    public void OnPlayMade(PlayMadeEvent e)
    {
        if (endGame)
        {
            return;
        }
        if (currentPlayerIndex == (int)PlayerNum.PLAYER1)
        {
            currentPlayerIndex        = (int)PlayerNum.PLAYER2;
            _turnIndicator.color      = Services.GameManager.Player2Color[0];
            _turnIndicatorIcon.sprite = players[(int)PlayerNum.PLAYER2].PlayerIcon;
            _turnIndicatorIcon.color  = Services.GameManager.Player2Color[0];
        }
        else
        {
            currentPlayerIndex        = (int)PlayerNum.PLAYER1;
            _turnIndicator.color      = Services.GameManager.Player1Color[0];
            _turnIndicatorIcon.sprite = players[(int)PlayerNum.PLAYER1].PlayerIcon;
            _turnIndicatorIcon.color  = Services.GameManager.Player1Color[0];
        }

        currentPlayer = players[currentPlayerIndex];
    }