Skip to content

Instantly share code, notes, and snippets.

public MainWindow()
{
InitializeComponent();
}
namespace TicTacToe
{
class Player
{
}
}
public enum Player
{
None,
Player1,
Player2
}
private List> fields = new List>()
{
new List() {Player.None, Player.None, Player.None},
new List() {Player.None, Player.None, Player.None},
new List() {Player.None, Player.None, Player.None},
};
private Player currentPlayer = Player.Player1;
private bool gameActive = true;
public MainWindow()
{
InitializeComponent();
GameInformation.Content = "X ist am Zug";
}
private void Button_Click(object sender, EventArgs e)
{
}
var button = (Button)sender;
int column = Grid.GetColumn(button);
int row = Grid.GetRow(button);
private void Button_Click(object sender, EventArgs e)
{
var button = (Button)sender;
int column = Grid.GetColumn(button);
int row = Grid.GetRow(button);
if (gameActive && fields[column][row] == Player.None)
{
var currentSymbol = "";
if (currentPlayer == Player.Player1)
{
<Button Click="Button_Click" Name="Button0_0" Grid.Column="0" Grid.Row="0" Style="{StaticResource CellStyle}" />
<Button Click="Button_Click" Name="Button0_1" Grid.Column="0" Grid.Row="1" Style="{StaticResource CellStyle}" />
<Button Click="Button_Click" Name="Button0_2" Grid.Column="0" Grid.Row="2" Style="{StaticResource CellStyle}" />
...
private bool CheckForWinner()
{
// Check rows
foreach (List row in fields)
{
if (row[0] != Player.None && row[0] == row[1] && row[1] == row[2])
{
return true;
}
}