コード例 #1
0
ファイル: MainForm.cs プロジェクト: stunt-cat/GameTimer
        // 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();
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: stunt-cat/GameTimer
        // 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();
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: stunt-cat/GameTimer
 string DisplayTimeLeft(Player player)
 {
     return player.timeRemaining.ToString();
 }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: stunt-cat/GameTimer
 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;
     }
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: stunt-cat/GameTimer
        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;
        }