Esempio n. 1
0
        /// <summary>
        /// Saves the stuff that is stored in the players' settings.
        /// </summary>
        private void SavePlayersValues(Player southPlayer, Player northPlayer)
        {
            ApplicationDataCompositeValue playersGroup_GameStorage = new ApplicationDataCompositeValue();

            // Save the human player's names:
            playersGroup_GameStorage[_playersKey_humanNameSouth] = southPlayer.GetHumansName();
            playersGroup_GameStorage[_playersKey_humanNameNorth] = northPlayer.GetHumansName();

            // Save the currently set species:
            playersGroup_GameStorage[_playersKey_speciesSouth] = (int)southPlayer.GetSpecies();
            playersGroup_GameStorage[_playersKey_speciesNorth] = (int)northPlayer.GetSpecies();

            // Save the currently set computer's strength:
            playersGroup_GameStorage[_playersKey_computerStrengthSouth] = (int)southPlayer.GetComputerStrength();
            playersGroup_GameStorage[_playersKey_computerStrengthNorth] = (int)northPlayer.GetComputerStrength();

            // Save all stuff at once now:
            _roamingSettings.Values[_playersStorageName] = playersGroup_GameStorage;
        }
Esempio n. 2
0
        /// <summary>
        /// "Undoes" the last move by revoking the gameboard of the previous status.
        /// This is only possible for the last move. A multiple "undo" is not implemented.
        /// </summary>
        public void UndoLastMove()
        {
            if (_view == null)
            {
                throw new PSTException("Presenter.UndoLastMove: View is undefined");
            }

            if (_undoManager.HasAnUndoMoveLeft())
            {
                // There is at least one "undo" move left.

                if (GetGameStatus() == GameStatus.Ended)
                {
                    // The game was completely over when the undo button was pressed. We need to revive it a bit.

            //DEBUG             Logging.I.LogMessage("Presenter.UndoLastMove: Game had ended. Need to revive it.\n");

                    // Set the game status back to running:
                    SetGameStatus(GameStatus.Running);

                    // Empty the fixed message area on the game page:
                    _view.ClearFixedMsg();

                    // No "play again" button available anymore:
                    _view.DisablePlayAgainButton();
                }

                // Do not allow any button clicking during the undo moves:
                _view.DisableButtonsOnPage();

                // Get the next undo move from the UndoManager. Also get the player whose turn it is after the move:
                Move undoMove = null;
                Player playerAfterUndoMove = null;
                _undoManager.GetNextUndoMove(ref undoMove, ref playerAfterUndoMove);

                // Perform the undo move on the Model's game board:
                _modelGameBoard.PerformMove(undoMove);

                // Set the current player according to what the UndoManager told us:
                _currentPlayer = playerAfterUndoMove;
                _playerMayMoveAgain = true;  // This is because in "DecideWhoIsNext()" the players would be toggled if the value was false.

                // Set all houses to "unselected" as a selection does not make sense anymore:
                _viewModelGameBoard.UnselectAllHouses();

                // Set visual indicators correctly:
                _view.SwitchVisualIndicators(_currentPlayer);

                if (_currentPlayer.GetSpecies() == Player.Species.Computer)
                {
                    // The player whose turn it is after the undo move is a computer. Therefore, we have to call the undo method
                    // recursively to undo the next move after the visualization of the current undo move:
                    _viewModelGameBoard.VisualizeMove(undoMove, UndoLastMove, true);

                }
                else
                {
                    // Visualize the undo move on the ViewModel's game board and stop undoing by deciding who is next:
                    _viewModelGameBoard.VisualizeMove(undoMove, DecideWhoIsNext, true);
                }
            }
            else
            {
                // There is no undo move left (we may end up here because of a recursive call for this method before).

                // Decide which player has to continue. It may be the computer who immediately starts in this special case.yy
                DecideWhoIsNext();
            }

            _view.PrintFadingMsg("LastMoveUndone", _currentPlayer);
        }