Example #1
0
        private void SetupRaceTrack()
        {
            Dogs.startline1 = Dog1.Right - racetrack.Left;
            Dogs.rtlength1  = racetrack.Size.Width - 60; //fixing length of race - till finish line

            Dogss[0] = new Dogs()
            {
                DogsPictureBox = Dog1
            };
            Dogss[1] = new Dogs()
            {
                DogsPictureBox = Dog2
            };
            Dogss[2] = new Dogs()
            {
                DogsPictureBox = Dog3
            };
            Dogss[3] = new Dogs()
            {
                DogsPictureBox = Dog4
            };

            Racers[0] = pFactory.getRacer("Player1", MaximumBet, P1Bet); //getting player 1 object from factory class
            Racers[1] = pFactory.getRacer("Player2", MaximumBet, P2Bet); //getting player 2 object from factory class
            Racers[2] = pFactory.getRacer("Player3", MaximumBet, P3Bet); //getting player 3 object from factory class


            foreach (Racer Racer in Racers)
            {
                Racer.UpdateLabels();
            }
        }
Example #2
0
        private void race_Click(object sender, EventArgs e)
        {
            bool NoWinner = true;
            int  winningDogs;

            race.Enabled = false; //disable start race button

            while (NoWinner)
            { // loop until we have a winner
                Application.DoEvents();
                for (int i = 0; i < Dogss.Length; i++)
                {
                    if (Dogs.Run(Dogss[i]))
                    {
                        winningDogs = i + 1;
                        NoWinner    = false;
                        MessageBox.Show("winner of the race is - Dogs #" + winningDogs);
                        foreach (Racer Racer in Racers)
                        {
                            if (Racer.bet != null)
                            {
                                Racer.Collect(winningDogs); //give double amount to all who've won or deduce betted amount
                                Racer.bet = null;
                                Racer.UpdateLabels();
                            }
                        }
                        foreach (Dogs Dogs in Dogss)
                        {
                            Dogs.TakeStartingPosition();
                        }
                        break;
                    }
                }
            }
            if (Racers[0].busted && Racers[1].busted && Racers[2].busted)
            {  //stop Racers from betting if they run out of cash
                String            message = "Do you want to Play Again?";
                String            title   = "GAME OVER!";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show(message, title, buttons);
                if (result == DialogResult.Yes)
                {
                    SetupRaceTrack(); //restart game
                }
                else
                {
                    this.Close();
                }
            }
            race.Enabled = true; //enable race button
        }
Example #3
0
        public Race()
        {
            InitializeComponent();

            dogsArray[0] = new Dogs()
            {
                MyPictureBox = pbDog, Name = "Dog 1", RaceTrackLength = pbRaceTrack.Width - pbDog.Width, StartingPosition = pbDog.Left, Randomizer = Randomizer
            };
            dogsArray[1] = new Dogs()
            {
                MyPictureBox = pbDog1, Name = "Dog 2", RaceTrackLength = pbRaceTrack.Width - pbDog.Width, StartingPosition = pbDog1.Left, Randomizer = Randomizer
            };
            dogsArray[2] = new Dogs()
            {
                MyPictureBox = pbDog2, Name = "Dog 3", RaceTrackLength = pbRaceTrack.Width - pbDog.Width, StartingPosition = pbDog2.Left, Randomizer = Randomizer
            };
            dogsArray[3] = new Dogs()
            {
                MyPictureBox = pbDog3, Name = "Dog 4", RaceTrackLength = pbRaceTrack.Width - pbDog.Width, StartingPosition = pbDog3.Left, Randomizer = Randomizer
            };
        }