Beispiel #1
0
        private void SetupdograceTrack()
        {
            Dogs.StartingPosition1   = Dog1.Right - dogracetrack.Left;
            Dogs.dogracetrackLength1 = dogracetrack.Size.Width - 70;  //fixing length of dograce - 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
            };

            DogRacers[0] = pFactory.getDogRacer("Kom", MaximumBet, KomBet);     //getting Kom object from factory class
            DogRacers[1] = pFactory.getDogRacer("Marry", MaximumBet, MarryBet); //getting Marry object from factory class
            DogRacers[2] = pFactory.getDogRacer("Bob", MaximumBet, BobBet);     //getting Bob object from factory class


            foreach (DogRacer DogRacer in DogRacers)
            {
                DogRacer.UpdateLabels();
            }
        }
Beispiel #2
0
        private void dograce_Click(object sender, EventArgs e)
        {
            bool NoWinner = true;
            int  winningDogs;

            dograce.Enabled = false; //disable start dograce 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 dograce is - Dogs #" + winningDogs);
                        foreach (DogRacer DogRacer in DogRacers)
                        {
                            if (DogRacer.bet != null)
                            {
                                DogRacer.Collect(winningDogs); //give double amount to all who've won or deduce betted amount
                                DogRacer.bet = null;
                                DogRacer.UpdateLabels();
                            }
                        }
                        foreach (Dogs Dogs in Dogss)
                        {
                            Dogs.TakeStartingPosition();
                        }
                        break;
                    }
                }
            }
            if (DogRacers[0].busted && DogRacers[1].busted && DogRacers[2].busted)   //stop DogRacers 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)
                {
                    SetupdograceTrack(); //restart game
                }
                else
                {
                    this.Close();
                }
            }
            dograce.Enabled = true; //enable dograce button
        }
Beispiel #3
0
 public void DogsRace() // Instantiate the Dogs
 {
     DogsArray[0] = new Dogs {
         MyPictureBox = pbDog1, StartingPosition = pbDog1.Left, DogName = "#1", RaceTrackLength = pbRaceTrack.Width - pbDog1.Width, Randomiser = new Random()
     };
     DogsArray[1] = new Dogs {
         MyPictureBox = pbDog2, StartingPosition = pbDog2.Left, DogName = "#2", RaceTrackLength = pbRaceTrack.Width - pbDog2.Width, Randomiser = DogsArray[0].Randomiser
     };
     DogsArray[2] = new Dogs {
         MyPictureBox = pbDog3, StartingPosition = pbDog3.Left, DogName = "#3", RaceTrackLength = pbRaceTrack.Width - pbDog3.Width, Randomiser = DogsArray[0].Randomiser
     };
     DogsArray[3] = new Dogs {
         MyPictureBox = pbDog4, StartingPosition = pbDog4.Left, DogName = "#4", RaceTrackLength = pbRaceTrack.Width - pbDog4.Width, Randomiser = DogsArray[0].Randomiser
     };
 }