Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.8 kB
1
Indexable
Never
using System;
using System.Windows.Forms;
using TicTacToe;

public class GameModeForm : Form
{
    private Button localGameButton;
    private Button aiGameButton;
    private Button easyButton;
    private Button mediumButton;
    private Button hardButton;
    public AIPlayer aiPlayer { get; private set; }
    public GameMode gameMode { get; private set; }
    private Game game;

    public GameModeForm(Game game)
    {
        this.game = game;
        this.Text = "Select Game Mode";
        this.Size = new Size(200, 200);

        localGameButton = new Button() { Text = "Local Game", Location = new Point(50, 30), Size = new Size(100, 30) };
        aiGameButton = new Button() { Text = "AI Game", Location = new Point(50, 70), Size = new Size(100, 30) };
        easyButton = new Button() { Text = "Easy", Location = new Point(50, 110), Size = new Size(100, 30), Visible = false };
        mediumButton = new Button() { Text = "Medium", Location = new Point(50, 150), Size = new Size(100, 30), Visible = false };
        hardButton = new Button() { Text = "Hard", Location = new Point(50, 190), Size = new Size(100, 30), Visible = false };

        localGameButton.Click += LocalGameButton_Click;
        aiGameButton.Click += AIGameButton_Click;
        easyButton.Click += EasyButton_Click;
        mediumButton.Click += MediumButton_Click;
        hardButton.Click += HardButton_Click;

        Controls.Add(localGameButton);
        Controls.Add(aiGameButton);
        Controls.Add(easyButton);
        Controls.Add(mediumButton);
        Controls.Add(hardButton);
    }

    private void LocalGameButton_Click(object sender, EventArgs e)
    {
        game.SetGameMode(GameMode.Local);
        gameMode = GameMode.Local;
        this.Close();
    }

    private void AIGameButton_Click(object sender, EventArgs e)
    {
        localGameButton.Visible = false;
        aiGameButton.Visible = false;
        easyButton.Visible = true;
        mediumButton.Visible = true;
        hardButton.Visible = true;
    }

    private void EasyButton_Click(object sender, EventArgs e)
    {
        game.SetGameMode(GameMode.AI);
         aiPlayer = new AIPlayer(AIPlayer.Difficulty.Easy);
        game.SetAIPlayer(aiPlayer);
        this.Close();
    }

    private void MediumButton_Click(object sender, EventArgs e)
    {
        game.SetGameMode(GameMode.AI);
         aiPlayer = new AIPlayer(AIPlayer.Difficulty.Medium);
        game.SetAIPlayer(aiPlayer);
        this.Close();
    }

    private void HardButton_Click(object sender, EventArgs e)
    {
        game.SetGameMode(GameMode.AI);
         aiPlayer = new AIPlayer(AIPlayer.Difficulty.Hard);
        game.SetAIPlayer(aiPlayer);
        this.Close();
    }

}