コード例 #1
0
ファイル: Form1.cs プロジェクト: dronperminov/Gomoku
        void Game(GameMode mode)
        {
            gameBoard.Draw(grid, true);

            GameStatus status;

            if (mode == GameMode.career || mode == GameMode.certainLevel)
            {
                if ((status = isGameOver(huPlayer)) != GameStatus.notGameOver)
                {
                    GameOver(huPlayer, status, mode);
                    return;
                }

                playerPicture.Image = aiPlayer.image;
                playerPicture.Update();

                lastAIMove = ai.MakeMove(ref gameBoard, aiPlayer, huPlayer, aiPlayer, complexity);
                gameBoard.Draw(grid);

                if ((status = isGameOver(aiPlayer)) != GameStatus.notGameOver)
                {
                    GameOver(aiPlayer, status, mode);
                    return;
                }

                grid[lastAIMove.i, lastAIMove.j].button.BackColor = Settings.Default.AImoveBackColor;
                grid[lastAIMove.i, lastAIMove.j].button.Update();
                System.Threading.Thread.Sleep(150);
                grid[lastAIMove.i, lastAIMove.j].button.BackColor = Color.Transparent;
                grid[lastAIMove.i, lastAIMove.j].button.Update();
                System.Threading.Thread.Sleep(150);
                grid[lastAIMove.i, lastAIMove.j].button.BackColor = Settings.Default.AImoveBackColor;
                grid[lastAIMove.i, lastAIMove.j].button.Update();

                playerPicture.Image = huPlayer.image;
                playerPicture.Update();
            }
            else
            {
                if ((status = isGameOver(player)) != GameStatus.notGameOver)
                {
                    GameOver(player, status, mode);
                    return;
                }

                player = player == player1 ? player2 : player1;

                playerPicture.Image = player.image;
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: dronperminov/Gomoku
        void InitGame(GameMode mode)
        {
            gameBoard = new Board(Settings.Default.BoardHeight, Settings.Default.BoardWidth, player1, player2);
            grid.Reset();

            resetProgressMenuItem.Visible = (mode == GameMode.career);
            cancelMoveMenuItem.Visible    = (mode == GameMode.career || mode == GameMode.certainLevel);
            cancelMoveMenuItem.Enabled    = false;
            progressLabel.Visible         = (mode == GameMode.career);
            levelLabel.Visible            = (mode == GameMode.career || mode == GameMode.certainLevel);
            complexityLabel.Visible       = (mode == GameMode.career || mode == GameMode.certainLevel);
            winsPerLevelLabel.Visible     = (mode == GameMode.career);
            lossPerLevelLabel.Visible     = (mode == GameMode.career);

            selectLevelBox.SelectedIndexChanged -= selectLevelBox_SelectedIndexChanged;
            selectLevelBox.SelectedIndex         = Settings.Default.lastSelectedLevel - 1;
            selectLevelBox.SelectedIndexChanged += selectLevelBox_SelectedIndexChanged;

            careerModeMenuItem.Enabled         = mode != GameMode.career;
            certainLevelModeMenuItem.Enabled   = mode != GameMode.certainLevel;
            friendToFriendModeMenuItem.Enabled = mode != GameMode.friendWithFriend;

            if (mode == GameMode.career || mode == GameMode.certainLevel)
            {
                ai = new GomokuAI(Settings.Default.BoardHeight, Settings.Default.BoardWidth, isUserFirst);

                huPlayer = isUserFirst ? player1 : player2;
                aiPlayer = isUserFirst ? player2 : player1;

                if (!isUserFirst)
                {
                    gameBoard.SetStep(Settings.Default.BoardHeight / 2, Settings.Default.BoardWidth / 2, aiPlayer);
                }

                if (mode == GameMode.career)
                {
                    complexity = minComplexity + (Settings.Default.level - 1) * complexityStep;
                }
                else
                {
                    level      = Settings.Default.lastSelectedLevel;
                    complexity = minComplexity + (level - 1) * complexityStep;
                }
                playerPicture.Image = huPlayer.image;
            }
            else
            {
                player = isUserFirst ? player1 : player2;

                playerPicture.Image = player.image;
            }

            isUserFirst = !isUserFirst;

            showInfo(mode);

            gameBoard.Draw(grid);
        }
コード例 #3
0
 private void Screen_Paint(object sender, PaintEventArgs e)
 {
     b?.Draw(e.Graphics);
 }