Ejemplo n.º 1
0
        //
        // Events
        //

        // clicking a cell (if it's not owned by anyone and it's not the computer's turn) will set the cell's owner to the
        // current player and then raise a TurnCompleted event if parent panel has the event registered
        protected void CellButton_OnClick(object sender, EventArgs e)
        {
            if (IsCellAvailable())
            {
                // set this cell's Owner to the current turn (setter will set BackColor)
                Owner = TileTacToe.CurrentTurn;

                // play a "pop" sound when a cell is chosen
                soundCellPick.Play();

                // invoking TurnCompleted separate from an OnClick to make sure only valid completed turn events happen,
                // and not just any click to any cell
                TurnCompleted?.Invoke(this, new EventArgs());
            }
        }
Ejemplo n.º 2
0
        private void HandleTurnEnd()
        {
            // All turn command are finished
            var turn = GetCurrentTurn();

            turn.Complete();

            TurnCompleted?.Invoke();

            if (!_playerEntity.IsActive)
            {
                SwitchState(GameState.PlayerDied);
                StopCoroutine("SkipTurn");
            }
            else if (CatGirl != null && !CatGirl.IsActive)
            {
                SwitchState(GameState.CatGirlDied);
                StopCoroutine("SkipTurn");
            }
            else if (turn.Number >= MaxTurns - 1)
            {
                // If it was the last turn and everyone is alive
                SwitchState(GameState.Win);
                //One star given for complete level
                CollectStar();

                //TODO test give some rollback
                PlayerStats.Instance.AddRollbackNumber(25);
                AddCollectedStars();

                SaveLevelState();
                StopCoroutine("SkipTurn");
            }
            else if (_state != GameState.SkipTurn)
            {
                SwitchState(GameState.WaitingForPlayerCommand);
            }
            else
            {
                SwitchState(GameState.SkipTurn);
            }

            // Starting new turn
            var newTurnNumber = turn.Number + 1;

            _history.Push(new Turn(newTurnNumber));
        }
Ejemplo n.º 3
0
 // event raised by an unowned cell being clicked, raise an event up to MainForm to handle turn completing
 private void GamePanel_TurnCompleted(object sender, EventArgs e)
 {
     // sending up the same sender and event args of the cell that was clicked
     TurnCompleted?.Invoke(sender, e);
 }