Created
July 27, 2019 11:17
-
-
Save BMU-Verlag/434dd9611cf1f200f01270303cd899b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
var playerWon = CheckForWinner(); | |
if (playerWon) | |
{ | |
GameInformation.Content = $"{currentSymbol} hat gewonnen!"; | |
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