Exemplo n.º 1
0
        // Gets user input values and starts initial player clock
        void ButtonStartClick(object sender, System.EventArgs e)
        {
            if(numericUpDownH.Value == 0 && numericUpDownM.Value == 0 && numericUpDownS.Value == 0){
                buttonZeroInitialTime.Visible = true;
            } else {

                // Hide setup panel
            groupBoxSetup.Visible = false;
            groupBoxActive.Visible = true;

            // Set max value of NumericUpDownStartPlayer and reveal correct number of Player Name entry areas
            numberOfPlayers = (int)numericUpDownPlayers.Value;
            numericUpDownStartPlayer.Maximum = (decimal)numberOfPlayers;

            // Populate List<Player> according to user specified number of players, using user specified initial time
            for (int i=0; i<numberOfPlayers; i++){
                players.Add(new Player((int)numericUpDownH.Value, (int)numericUpDownM.Value, (int)numericUpDownS.Value));
            }

            // Setup active panel to display player names (or assign standard names if none are entered) and remaining time.
            // Also give each player a reference to their labelPxTimeLeft
            switch (numberOfPlayers){
                case 1 : if(textBoxP1.Text == "") players[0].name = "Player 1";
                        else players[0].name = textBoxP1.Text;
                        labelP1Timer.Text = players[0].name;
                        players[0].timeLeftLabel = labelP1TimeLeft;
                        goto default;
                case 2 : if(textBoxP2.Text == "") players[1].name = "Player 2";
                        else players[1].name = textBoxP2.Text;
                        labelP2Timer.Text = players[1].name;
                        players[1].timeLeftLabel = labelP2TimeLeft;
                        goto case 1;
                case 3 : if(textBoxP3.Text == "") players[2].name = "Player 3";
                        else players[2].name = textBoxP3.Text;
                        labelP3Timer.Text = players[2].name;
                        players[2].timeLeftLabel = labelP3TimeLeft;
                        goto case 2;
                case 4 : if(textBoxP4.Text == "") players[3].name = "Player 4";
                        else players[3].name = textBoxP4.Text;
                        labelP4Timer.Text = players[3].name;
                        players[3].timeLeftLabel = labelP4TimeLeft;
                        goto case 3;
                default:
                        for(int i=0; i<numberOfPlayers; i++){
                            players[i].timeLeftLabel.Text = DisplayTimeLeft(players[i]);
                        }
                        break;
            }

            // Make non-existant player data invisible in active panel
            switch (numberOfPlayers){
                case 1:	labelP2Timer.Visible = false;
                        labelP3Timer.Visible = false;
                        labelP4Timer.Visible = false;
                        labelP2TimeLeft.Visible = false;
                        labelP3TimeLeft.Visible = false;
                        labelP4TimeLeft.Visible = false;
                        break;
                case 2: labelP3Timer.Visible = false;
                        labelP4Timer.Visible = false;
                        labelP3TimeLeft.Visible = false;
                        labelP4TimeLeft.Visible = false;
                        break;
                case 3: labelP4Timer.Visible = false;
                        labelP4TimeLeft.Visible = false;
                        break;
                case 4: break;
            }

            // Set active player and assign correct colours to labelPxTimeLeft
            activePlayer = players[(int)numericUpDownStartPlayer.Value - 1];
            ColourIn();

            // Begin timer
            timer.Start();
            }
        }
Exemplo n.º 2
0
        // Selects next player in play order who is still active
        void SwitchPlayer()
        {
            List<Player> playOrder = new List<Player>();

            // Populate playOrder with all players in the order they will play (regardless of if they are active or not)
            // Add all players after activePlayer
            for(int i=players.IndexOf(activePlayer)+1; i<players.Count; i++){
                playOrder.Add(players[i]);
            }
            // Append all players before and including activePlayer
            for(int i=0; i<players.IndexOf(activePlayer); i++){
                playOrder.Add(players[i]);
            }

            // Choose next Player in playOrder who is active to be activePlayer
            foreach(Player checkMe in playOrder){
                if(checkMe.active){
                    activePlayer = checkMe;
                    break;
                }
            }

            ColourIn();
        }
Exemplo n.º 3
0
 string DisplayTimeLeft(Player player)
 {
     return player.timeRemaining.ToString();
 }
Exemplo n.º 4
0
 void PlayerTimeUpStatus(Player knockedOut)
 {
     // If everyone is out of time end timer.
     Boolean someoneLeft = false;
     foreach(Player checkMe in players){
         if(checkMe.active){
             someoneLeft = true;
         }
     }
     if(someoneLeft){
         buttonTimerUp.Text = string.Format("{0} is out of time!",knockedOut.name);
         SwitchPlayer();
         buttonTimerUp.Visible = true;
     } else {
         buttonTimerUp.Visible = false;
         buttonAllTimersUp.Visible = true;
     }
 }
Exemplo n.º 5
0
        void DecrementTimer(Player player)
        {
            // When a players' time runs out, show message, highlight player time red, switch to next player.
            // Otherwise decrement player time remaining.
            TimeSpan decrement = new TimeSpan(1000000);
            if(player.timeRemaining.Ticks == 0){
                player.active = false;
                PlayerTimeUpStatus(player);
            } else {
                player.timeRemaining = player.timeRemaining.Subtract(decrement);
            }

            for(int i=0; i<numberOfPlayers; i++){
                players[i].timeLeftLabel.Text = DisplayTimeLeft(players[i]);
            }
            return;
        }