50 lines
1.0 KiB
C#
50 lines
1.0 KiB
C#
namespace TicTacToe
|
|
{
|
|
public class Box
|
|
{
|
|
public Action<int>? Pressed;
|
|
public int Index;
|
|
public bool BotOwned = false;
|
|
private Button _button;
|
|
public bool Filled = false;
|
|
|
|
public Box(Button button, int index)
|
|
{
|
|
_button = button;
|
|
Index = index;
|
|
button.Click += Clicked;
|
|
_button.Text = "";
|
|
}
|
|
|
|
private void Clicked(object? sender, EventArgs e)
|
|
{
|
|
Pressed?.Invoke(Index);
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
_button.Text = "";
|
|
_button.Click -= Clicked;
|
|
}
|
|
|
|
public void SetEnabled(bool value)
|
|
{
|
|
_button.Enabled = value;
|
|
}
|
|
|
|
public void PlayerClaim(bool bot)
|
|
{
|
|
Filled = true;
|
|
BotOwned = bot;
|
|
if (bot)
|
|
{
|
|
_button.Text = "O";
|
|
}
|
|
else
|
|
{
|
|
_button.Text = "X";
|
|
}
|
|
}
|
|
}
|
|
}
|