Пример #1
0
        /// <summary>
        /// Called by the OnPerformMove event on players every time a player is about to perform a move
        /// </summary>
        /// <param name="move"></param>
        private void player_OnPerformMove(IPlayer sender, IMove move)
        {
            if (isValidMove(sender,move))
            {
                //Make the move
                PerformMove(move);

                //Inform all player that this player perfomed a move suscefully
                foreach(IPlayer player in PlayersList)
                {
                    if (!player.Equals(sender))
                    {
                        try
                        {
                            player.MovedPerformed(sender,move);
                        }
                        catch(Exception ex)
                        {
                            HaltGame(ex);
                        }
                    }
                }

                if (isGameFinished()) GameOver();

                //Increase the values of next player
                _NextPlayerIndex = AdvanceIndex(_NextPlayerIndex);

                //Call the current player Play method
                this.InvokePlayMethod(this.NextPlayer);

            }
            else
            {
                ///Comunicate the player that the move was not valid
                sender.InvalidMove(move);
            }
        }