Exemplo n.º 1
0
        void RenderBoard(byte[,] board)
        {
            if (animationPaused)
            {
                animationPending = true;
                return;
            }
            bool changesOccurred = false;

            for (int index = 0; index < 64; index++)
            {
                Tuple <int, int> index2D = Game.ToIndex2D(index);
                int  x     = index2D.Item1;
                int  y     = index2D.Item2;
                byte value = board[x, y];

                if (value == Game.White || value == Game.Black || value == Game.Empty)
                {
                    Button cellButton = BoardUniformGrid.Children[index] as Button;
                    cellButton.Tag  = Game.ValueAsString(value);
                    changesOccurred = true;
                }
            }
            if (changesOccurred)
            {
                animationPaused = true;
                animationTimer.Start();
            }
            Player currentPlayer = Player.GetPlayerFromTurn(turn, player1, player2);

            if (currentPlayer == player1)
            {
                Player1Display.IsEnabled = true;
                Player2Display.IsEnabled = false;
            }
            else
            {
                Player1Display.IsEnabled = false;
                Player2Display.IsEnabled = true;
            }
            Player1Score.Text = Game.GetScore(board, Game.White).ToString();
            Player2Score.Text = Game.GetScore(board, Game.Black).ToString();

            //Trace.WriteLine(Game.GenerateString(board));
        }
Exemplo n.º 2
0
        void HandleWinner()
        {
            byte       winnerTile     = Game.GetWinner(board);
            Storyboard winnerBannerIn = this.FindResource("WinnerBannerIn") as Storyboard;
            Storyboard gameOptionsOut = this.FindResource("GameOptionsOut") as Storyboard;

            winnerBannerIn.Begin();
            gameOptionsOut.Begin();
            string player1Text;
            string player2Text;
            string winType = "beat";
            string scoreText;

            if (winnerTile == Game.White || winnerTile == Game.Tie)
            {
                player1Text = Player1Name.Text;
                player2Text = Player2Name.Text;
                scoreText   = Game.GetScore(board, Game.White).ToString() + "-" + Game.GetScore(board, Game.Black).ToString();
            }
            else // winner == Game.Black
            {
                player1Text = Player2Name.Text;
                player2Text = Player1Name.Text;
                scoreText   = Game.GetScore(board, Game.Black).ToString() + "-" + Game.GetScore(board, Game.White).ToString();
            }
            WinnerBannerScore.Text = scoreText;
            if (winnerTile == Game.Tie)
            {
                WinnerBannerHeading.Text = "It's a tie!";
                winType = "tied with";
            }
            WinnerBannerPlayer1.Text = player1Text;
            WinnerBannerPlayer2.Text = player2Text;
            WinnerBannerWinType.Text = winType;
            WinnerBannerScore.Text   = scoreText;
            // Write highscores.
            using (StreamWriter writer = new StreamWriter("highscores.txt", append: true))
            {
                string[] gameInfo = { player1Text, winType, player2Text, scoreText };
                writer.WriteLine(string.Join(",", gameInfo));
            }
        }