Пример #1
0
        /// <summary>
        ///     The store state of game and add to undoredo stack
        /// </summary>
        private void StoreState()
        {
            var player1PiecesLocation = new List<Pair<int, int>>();

            var player2PiecesLocation = new List<Pair<int, int>>();

            foreach (var tile in this.boardTiles)
            {
                if (tile.Owner == Player.Player1)
                {
                    player1PiecesLocation.Add(new Pair<int, int>(tile.RowIndex, tile.ColumnIndex));
                }

                if (tile.Owner == Player.Player2)
                {
                    player2PiecesLocation.Add(new Pair<int, int>(tile.RowIndex, tile.ColumnIndex));
                }
            }

            var turn = new Turn
                           {
                               Player1State = this.PlayersList[(int)Player.Player1],
                               Player2State = this.PlayersList[(int)Player.Player2],
                               GameState = this.game.GameState,
                               CurrentPlayer = this.game.CurrentPlayer,
                               ArtificialPlayer = this.game.ArtificialPlayer,
                               Player1Pieces = this.game.Player1Pieces,
                               Player2Pieces = this.game.Player2Pieces,
                               InitialPieces = this.game.InitialPieces,
                               Player1PiecesLocation = player1PiecesLocation,
                               Player2PiecesLocation = player2PiecesLocation
                           };

            this.undoRedo.AddToStack = turn;
        }
Пример #2
0
        /// <summary>
        /// The set state for undo and redo
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        private void SetState(Turn state)
        {
            this.PlayersList[(int)Player.Player1] = state.Player1State;
            this.PlayersList[(int)Player.Player2] = state.Player2State;
            this.game.GameState = state.GameState;
            this.game.CurrentPlayer = state.CurrentPlayer;
            this.game.ArtificialPlayer = state.ArtificialPlayer;
            this.game.Player1Pieces = state.Player1Pieces;
            this.game.Player2Pieces = state.Player2Pieces;
            this.game.InitialPieces = state.InitialPieces;
            var player1PiecesLocation = state.Player1PiecesLocation;
            var player2PiecesLocation = state.Player2PiecesLocation;

            foreach (var tile in this.BoardTiles)
            {
                tile.Owner = null;
                tile.PlayerData = null;
            }

            // Piece locations
            foreach (var pair in player1PiecesLocation)
            {
                for (var i = 0; i < this.BoardTiles.Count; i++)
                {
                    if (this.BoardTiles.ElementAt(i).RowIndex != pair.First
                        || this.BoardTiles.ElementAt(i).ColumnIndex != pair.Second) continue;
                    this.BoardTiles.ElementAt(i).Owner = Player.Player1;
                    this.BoardTiles.ElementAt(i).PlayerData = this.PlayersList[(int)Player.Player1];
                }
            }

            foreach (var pair in player2PiecesLocation)
            {
                for (var i = 0; i < this.BoardTiles.Count; i++)
                {
                    if (this.BoardTiles.ElementAt(i).RowIndex != pair.First
                        || this.BoardTiles.ElementAt(i).ColumnIndex != pair.Second) continue;
                    this.BoardTiles.ElementAt(i).Owner = Player.Player2;
                    this.BoardTiles.ElementAt(i).PlayerData = this.PlayersList[(int)Player.Player2];
                }
            }
        }