Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created July 27, 2019 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMU-Verlag/a378aa512a6aafd71afe5cba508255f1 to your computer and use it in GitHub Desktop.
Save BMU-Verlag/a378aa512a6aafd71afe5cba508255f1 to your computer and use it in GitHub Desktop.
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)
{
currentSymbol = "X";
}
else
{
currentSymbol = "O";
}
button.Content = currentSymbol;
fields[column][row] = currentPlayer;
fieldsMarked++;
var playerWon = CheckForWinner();
if (playerWon)
{
GameInformation.Content = $"{currentSymbol} hat gewonnen!";
gameActive = false;
}
else
{
if (fieldsMarked >= 9)
{
GameInformation.Content = "Unentschieden!";
gameActive = false;
}
else if (currentPlayer == Player.Player1)
{
currentPlayer = Player.Player2;
GameInformation.Content = "O ist am Zug";
}
else
{
currentPlayer = Player.Player1;
GameInformation.Content = "X ist am Zug";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment