Exemple #1
0
        public void updateDisplay()
        {
            for (int rowIndex = 0; rowIndex < spaces.Count; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < spaces[rowIndex].Count; columnIndex++)
                {
                    var piece = game.getPieceAt(rowIndex, columnIndex);

                    if (piece == Piece.Red)
                    {
                        spaces[rowIndex][columnIndex].Fill = new SolidColorBrush(Colors.Red);
                    }
                    else if (piece == Piece.Green)
                    {
                        spaces[rowIndex][columnIndex].Fill = new SolidColorBrush(Colors.Green);
                    }
                }
            }
            if (game.getCurrentPlayer() == Piece.Red)
            {
                currentPlayerLabel.Content = nameof(Piece.Red);
            }
            else
            {
                currentPlayerLabel.Content = nameof(Piece.Green);
            }

            if (game.isTie())
            {
                errorLabel.Content = "TIE!";
                return;
            }
            if (game.isGameOver())
            {
                errorLabel.Content = game.getCurrentPlayer() == Piece.Red ? "Green wins!" : "Red Wins!";
                return;
            }
        }