コード例 #1
0
        /// <summary>
        /// Routine that changes the owner of a tile based on indices stored in TilesToTurn list.
        /// </summary>
        private void DoTurnTiles()
        {
            PlayerModel player      = null;;
            bool        playerFound = false;

            foreach (KeyValuePair <int, ClientModel> model in CurrentPlayersList)
            {
                ReversiClientModel reversiClientModel = (ReversiClientModel)model.Value;

                if (reversiClientModel.ClientPlayer.IdType == CurrentPlayer)
                {
                    player      = reversiClientModel.ClientPlayer;
                    playerFound = true;
                }
            }

            // If we didnt find the player, return
            if (!playerFound)
            {
                return;
            }

            foreach (int index in TilesToTurn)
            {
                Gameboard.Squares[index].Piece.Owner = player;

                //// TODO: For each tile being flipped...play a sounds
                //ReversiSounds.PlaySounds(GameSounds.SOUND_FLIPTILE);
            }

            // Now clear the tiles to turn array since all the moves have been made
            TilesToTurn.Clear();
        }
コード例 #2
0
        public override bool PlayTurn()
        {
            // Clear the tiles to turn array
            AvailableMovesList.Clear();
            TilesToTurn.Clear();

            return(MakePlayerMove(CurrentMoveIndex));
        }
コード例 #3
0
        /// <summary>
        /// Primary routine for a player to make a move
        /// </summary>
        /// <param name="index">the index of the move being made</param>
        internal bool MakePlayerMove(int index)
        {
            PlayerModel player      = null;;
            bool        playerFound = false;

            foreach (KeyValuePair <int, ClientModel> model in CurrentPlayersList)
            {
                ReversiClientModel reversiClientModel = (ReversiClientModel)model.Value;

                if (reversiClientModel.ClientPlayer.IdType == CurrentPlayer)
                {
                    player      = reversiClientModel.ClientPlayer;
                    playerFound = true;
                    break;
                }
            }

            if ((player == null) || (playerFound == false))
            {
                return(false);
            }

            bool placementIsValid = ValidateTilePlacement(index, CurrentPlayer);

            if (placementIsValid)
            {
                // Add a new game piece at the location
                GamePieceModel piece = new GamePieceModel(Pieceshapes.Ellipse, player);
                Gameboard.AddPiece(index, piece);

                // Capture the opponents tiles
                DoTurnTiles();

                // Reset the tiles to be turned array
                TilesToTurn.Clear();
                return(true);
            }

            return(false);
            //MessageBox.Show(Gameboard.DrawGameboard() + "\nCurrent Player: " + CurrentPlayer.IDType + " : " + CurrentPlayer.Name);
        }