예제 #1
0
        /// <summary>
        /// This method checks the game status. If it is end of game, the selection panel is shown with the players' scores and winners. Human player will have option to play another game.
        /// </summary>

        private void CheckGameStatus()
        {
            try
            {
                if (aDeck.Count == 0 || player1.PlayHand.Count == 0 || player2.PlayHand.Count == 0 || player2.PlayHand.Count == 0)
                {
                    timerP1.Stop();

                    //Make all controls invisible except selection panel and score elements
                    foreach (Control c in this.Controls)
                    {
                        c.Visible = false;
                    }

                    PanelSelection.Visible    = true;
                    lblPutInYourAlias.Visible = false;
                    lblSelectHero.Visible     = false;
                    lblStatNewGame.Visible    = false;
                    cmbHeroes.Visible         = false;
                    txtPlayerAlias.Visible    = false;
                    picAvatar.Visible         = false;
                    PanelEndGame.Visible      = true;
                    picExitStart.Visible      = true;
                    lblStatNewGame.Visible    = true;
                    lblStatNewGame.Text       = "Play Again";

                    game.GameEnd();

                    lblPlayerScoreFinal.Text = game.DisplayScore();
                    game.GameNumber         += 1;

                    //update player one win score
                    if (game.Winner.Contains(player1))
                    {
                        player1Wins   += 1;
                        lblWinner.Text = $"AWESOME! YOU WIN!";
                    }
                    else
                    {
                        if (game.Winner.Count == 1)
                        {
                            lblWinner.Text = $"SORRY, {game.Winner[0].Name} WINS!";
                        }
                        else
                        {
                            lblWinner.Text = $"SORRY, Better luck next time!";
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);;
            }
        }