Exemplo n.º 1
0
        public Winner(Battle game)
        {
            InitializeComponent();
            int    highscore = 0;
            String winner    = "";

            //for every player in the battle find out their score
            GenericPlayer[] genericPlayers = new GenericPlayer[game.NumPlayers()];

            for (int i = 0; i < genericPlayers.Length; i++)
            {
                GenericPlayer gp = game.GetPlayerNumber(i + 1);
                if (gp.GetScore() > highscore)
                {
                    highscore = gp.GetScore();
                    winner    = String.Format("{0} won!", gp.PlayerName());
                }
                else if (gp.GetScore() == highscore)
                {
                    winner = "Tie!";
                }
                playerWon.Text = winner;
                listBox.Items.Add(String.Format("{0} ({1} Wins)", gp.PlayerName(), gp.GetScore()));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// shows a scoreboard to the player , before continuing or ending the fight.
 /// </summary>
 /// <param name="currentGame"></param>
 public Scoreboard(Battle currentGame)
 {
     InitializeComponent();       // make form
     continueFight = currentGame; // store game
     scores        = new int[continueFight.NumPlayers()];
     names         = new string[continueFight.NumPlayers()];
     for (int i = 1; i <= continueFight.NumPlayers(); i++)
     {
         scores[i - 1] = continueFight.GetPlayerNumber(i).GetVictories(); // gets the score of a player
         names[i - 1]  = continueFight.GetPlayerNumber(i).Name();         // gets the player's name
         // add each entry into a textbox
         playerScores.Items.Add(string.Format("{0} current score is {1}\n", names[i - 1], scores[i - 1]));
         // check if player has highest score
         if (scores[i - 1] > leader)
         {
             // set highscore to players score
             leaderIndex = i - 1;         // get players name index
             leader      = scores[i - 1]; // get their score for testing
         }
     }
     // set label to show leader of battle
     currentLeader.Text = string.Format("{0}", names[leaderIndex]);
 }