Exemple #1
0
		//
		// Creates a new Statistics object by copying and existing one.
		//
		public Statistics(Statistics statistics)
		{
			this.BlackWins          = statistics.BlackWins;
			this.WhiteWins          = statistics.WhiteWins;
			this.OverallDraws       = statistics.OverallDraws;
			this.BlackTotalScore    = statistics.BlackTotalScore;
			this.WhiteTotalScore    = statistics.WhiteTotalScore;
			this.ComputerWins       = statistics.ComputerWins;
			this.UserWins           = statistics.UserWins;
			this.VsComputerDraws    = statistics.VsComputerDraws;
			this.ComputerTotalScore = statistics.ComputerTotalScore;
			this.UserTotalScore     = statistics.UserTotalScore;
		}
		public StatisticsDialog(Statistics statistics)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//

			// Create a copy of the given game statistics.
			this.statistics = statistics;

			// Set the form controls based on those statistics.
			this.MapStatisticsToControls();

			// Activate the "Close" button.
			this.closeButton.Select();
		}
Exemple #3
0
        //
        // Ends the current game, optionally by player resignation.
        //
        private void EndGame(bool isResignation)
        {
            // Set the game state.
            this.gameState = ReversiForm.GameState.GameOver;

            // Stop the game timer.
            this.animationTimer.Stop();

            // Enable/disable the menu items and tool bar buttons as
            // appropriate.
            this.newGameMenuItem.Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.NewGame].Enabled      = true;
            this.resignGameMenuItem.Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.ResignGame].Enabled   = false;
            this.undoMoveMenuItem.Enabled =
                this.undoAllMovesMenuItem.Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.UndoMove].Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.UndoAllMoves].Enabled = false;
            this.redoMoveMenuItem.Enabled =
                this.redoAllMovesMenuItem.Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.RedoMove].Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.RedoAllMoves].Enabled = false;
            this.resumePlayMenuItem.Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.ResumePlay].Enabled   = false;

            // Clear the current player indicator display.
            this.currentColorTextLabel.Visible = false;
            this.currentColorPanel.BackColor   = Color.Empty;
            this.currentColorPanel.Visible     = false;

            // Hide the status progress bar.
            this.statusProgressBar.Visible = false;
            this.statusPanel.Refresh();

            // For a computer vs. user game, determine who played what color.
            int computerColor = Board.Empty;
            int userColor     = Board.Empty;
            if (this.IsComputerPlayer(Board.Black) && !this.IsComputerPlayer(Board.White))
            {
                computerColor = Board.Black;
                userColor = Board.White;
            }
            if (this.IsComputerPlayer(Board.White) && !this.IsComputerPlayer(Board.Black))
            {
                computerColor = Board.White;
                userColor = Board.Black;
            }

            // Save the current statistics, in case the game is restarted.
            this.oldStatistics = new Statistics(this.statistics);

            // Handle a resignation.
            if (isResignation)
            {
                // For computer vs. computer game, just update the status
                // message.
                if (this.IsComputerPlayer(Board.Black) && this.IsComputerPlayer(Board.White))
                    this.statusLabel.Text = "Game aborted.";
                else
                {
                    // Determine which player is resigning. In a computer vs.
                    // user game, the computer will never resign so it must be
                    // the user. In a user vs. user game we'll assume it is
                    // the current player.
                    int resigningColor = this.currentColor;
                    if (this.IsComputerPlayer(Board.Black) || this.IsComputerPlayer(Board.White))
                        resigningColor = userColor;

                    // Update the status message and record the game as a 64-0
                    // loss for the resigning player.
                    if (resigningColor == Board.Black)
                    {
                        this.statusLabel.Text = "Black resigns.";
                        this.statistics.Update(0, 64, computerColor, userColor);
                    }
                    else
                    {
                        this.statusLabel.Text = "White resigns.";
                        this.statistics.Update(64, 0, computerColor, userColor);
                    }
                }
            }

            // Handle an end game.
            else
            {
                // Update the status message.
                if (this.board.BlackCount > this.board.WhiteCount)
                    this.statusLabel.Text = "Black wins.";
                else if (this.board.WhiteCount > this.board.BlackCount)
                    this.statusLabel.Text = "White wins.";
                else
                    this.statusLabel.Text = "Draw.";

                // Record the result.
                this.statistics.Update(this.board.BlackCount, this.board.WhiteCount, computerColor, userColor);
            }

            // Update the status display.
            this.statusPanel.Refresh();

            // Re-enable the undo move-related menu items and tool bar
            // buttons.
            this.undoMoveMenuItem.Enabled =
                this.undoAllMovesMenuItem.Enabled =
                this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.UndoMove].Enabled =
                this.undoAllMovesMenuItem.Enabled = this.playToolBar.Buttons[(int) ReversiForm.ToolBarButton.UndoAllMoves].Enabled = true;
        }
Exemple #4
0
        //
        // Undoes the previous move or all moves.
        //
        private void UndoMove(bool undoAll)
        {
            // Save the current game state so we'll know if we need to perform
            // a restart.
            GameState oldGameState = this.gameState;

            // Stop the computer move thread, if active.
            this.KillComputerMoveThread();

            // Lock the board to prevent any changes by an active computer
            // move.
            lock (this.board)
            {
                // When undoing the last move, we need to save the current
                // board and player color in the move history so that it can
                // be restored if the move is redone.
                if (this.moveHistory.Count < this.moveNumber)
                {
                    // Add the data to the move history.
                    this.moveHistory.Add(new MoveRecord(this.board, -this.lastMoveColor, new ListViewItem()));
                }

                // Undo either the previous move or all moves.
                this.RestoreGameAt((undoAll ? 0 : this.moveNumber - 2));
            }

            // If the game was over, restore the statistics and restart it.
            if (oldGameState == ReversiForm.GameState.GameOver)
            {
                this.statistics = new Statistics(this.oldStatistics);
                this.StartGame(true);
            }

            // Otherwise, start play at that move.
            else
                this.StartTurn();
        }