Beispiel #1
0
        /// <summary>
        /// Initialize All Game Comonents
        /// </summary>
        private void InitializeGameComponents()
        {
            // Hold All picture box reference to an Array
            PictureBox[] pictures = { picture1, picture2, picture3, picture4 };

            // Initialize the scooters array
            scooters = new Scooter[pictures.Length];
            // Prepare Scooter Object for storing details of Scooter
            for (int index = 0; index < scooters.Length; index++)
            {
                scooters[index]      = new Scooter();
                scooters[index].Name = "Scooter " + (index + 1);
                scooters[index].ScooterPictureBox = pictures[index];
                scooters[index].TrackLength       = 710;
            }

            // Hold All Text Box reference to an Arrays
            TextBox[] textBoxes = { text1, text2, text3 };
            // Hold All Radio Button reference to an Arrays
            RadioButton[] radioButtons = { radio1, radio2, radio3 };

            // Initialize the players array
            players = new Player[textBoxes.Length];
            for (int index = 0; index < players.Length; index++)
            {
                players[index] = PlayerFactory.GetPlayer(index + 1);
                players[index].PlayerRadioButton      = radioButtons[index];
                players[index].PlayerTextBox          = textBoxes[index];
                players[index].Amount                 = 50;
                players[index].PlayerRadioButton.Text = players[index].Name;
            }

            // Set the Number for Scooter
            npScooterNo.Minimum = 1;
            npScooterNo.Maximum = scooters.Length;
            npScooterNo.Value   = 1;

            // Disable the Begin Race Button...
            btnBegin.Enabled = false;
        }
Beispiel #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            // Event Sender is Timer
            if (sender is Timer)
            {
                Timer timer = (Timer)sender;
                int   index = -1;
                for (int i = 0; i < timers.Length; i++)
                {
                    if (timer == timers[i])
                    {
                        index = i;
                        break;
                    }
                }
                if (index != -1)
                {
                    PictureBox picture = scooters[index].ScooterPictureBox;
                    if (picture.Location.X + picture.Width > scooters[index].TrackLength)
                    {
                        if (winner == null)
                        {
                            winner = scooters[index];
                        }
                        foreach (Timer tim in timers)
                        {
                            tim.Stop();
                        }
                    }
                    else
                    {
                        int step = new Random().Next(1, 25);
                        picture.Location = new Point(picture.Location.X + step, picture.Location.Y);
                    }
                }
            }

            // Check is There any Winner
            if (winner != null)
            {
                MessageBox.Show(string.Format("{0} is won the Race!!!", winner.Name));
                SetupPlayerDetails();
                // Update The Winner Status of Player
                for (int index = 0; index < players.Length; index++)
                {
                    // Check Player is involved in Betting
                    if (players[index].PlayerBet != null)
                    {
                        int amount = players[index].PlayerBet.Amount;
                        // Check Player Scooter win
                        if (players[index].PlayerBet.Scooter == winner)
                        {
                            players[index].Amount            += amount;
                            players[index].PlayerTextBox.Text = string.Format("{0} won the Race and Now, has ${1} Amount in Hand", players[index].Name, players[index].Amount);
                            players[index].Winner             = true;
                        }
                        else
                        {
                            players[index].Amount -= amount;
                            if (players[index].Amount == 0)
                            {
                                players[index].PlayerTextBox.Text        = "Player Lost all Amount So BUSTED";
                                players[index].Busted                    = true;
                                players[index].PlayerRadioButton.Enabled = false;
                            }
                            else
                            {
                                players[index].PlayerTextBox.Text = string.Format("{0} Lost ${1} Amount in the Race and Now, has ${1} Amount in Hand", players[index].Name, amount, players[index].Amount);
                            }
                        }
                    }
                }

                // Reset the Game components
                winner = null;
                timers = null;
                int inactive_count = 0;
                for (int index = 0; index < players.Length; index++)
                {
                    // Check Player is Busted
                    if (players[index].Busted)
                    {
                        inactive_count++;
                    }
                    else
                    {
                        // Check Radio of Player is Selected or Not
                        RadioButton radioButton = players[index].PlayerRadioButton;
                        if (radioButton.Enabled && radioButton.Checked)
                        {
                            lblMax.Text         = string.Format("{0} Max Bet Amount Limit is ${1}", players[index].Name, players[index].Amount);
                            btnPlace.Text       = string.Format("Place A BET For Player {0}", players[index].Name);
                            lblBet.Text         = string.Format("Bet Amount of {0} is $", players[index].Name);
                            lblScooter.Text     = string.Format("{0} Place Bet on Scooter No", players[index].Name);
                            npBetAmount.Maximum = players[index].Amount;
                            npBetAmount.Minimum = 1;
                        }
                    }
                    players[index].PlayerBet = null;
                    players[index].Winner    = false;
                }
                // Check All Player are Busted
                if (inactive_count == players.Length)
                {
                    MessageBox.Show("GAME OVER!!!!");
                    Application.Exit();
                }
                else // Enable the Game for Restart
                {
                    panelGame.Enabled = true;
                    btnPlace.Enabled  = true;
                    MessageBox.Show("You Can Place More Bet...");
                    SetupPlayerDetails();
                }
                // Reset the Scooter Picture at Original Position
                for (int index = 0; index < scooters.Length; index++)
                {
                    PictureBox picture = scooters[index].ScooterPictureBox;
                    picture.Location = new Point(2, picture.Location.Y);
                }
            }
        }