private void SetupRaceTrack() { randomizer = new Random(); Dog[0] = new Greyhound { Name = "Toby", DogNummer = 1, MyPictureBox = PictureBox1, StartingPosition = PictureBox1.Left, RacetrackLength = racetrackPictureBox.Width - PictureBox1.Width, Randomizer = randomizer }; Dog[1] = new Greyhound { DogNummer = 2, Name = "Balou", MyPictureBox = PictureBox2, StartingPosition = PictureBox2.Left, RacetrackLength = racetrackPictureBox.Width - PictureBox2.Width, Randomizer = randomizer }; Dog[2] = new Greyhound { Name = "Happy", DogNummer = 3, MyPictureBox = PictureBox3, StartingPosition = PictureBox3.Left, RacetrackLength = racetrackPictureBox.Width - PictureBox3.Width, Randomizer = randomizer }; Dog[3] = new Greyhound { Name = "Caran", DogNummer = 4, MyPictureBox = PictureBox4, StartingPosition = PictureBox4.Left, RacetrackLength = racetrackPictureBox.Width - PictureBox4.Width, Randomizer = randomizer }; label3.Text = Dog[0].Name + ", dog " + Dog[0].DogNummer; label4.Text = Dog[1].Name + ", dog " + Dog[1].DogNummer; label5.Text = Dog[2].Name + ", dog " + Dog[2].DogNummer; label6.Text = Dog[3].Name + ", dog " + Dog[3].DogNummer; NewGuy[0] = new Guy() { Name = "Joe", Cash = 50, MyLabel = joeBetLabel, MyRadioButton = joeRadioButton }; NewGuy[1] = new Guy() { Name = "Bob", Cash = 75, MyLabel = bobBetLabel, MyRadioButton = bobRadioButton }; NewGuy[2] = new Guy() { Name = "Al", Cash = 45, MyLabel = alBetLabel, MyRadioButton = alRadiobutton, }; foreach (Guy guy in NewGuy) { guy.UpdateLabels(); } }
public Form1() { InitializeComponent(); minimumBetLabel.Text = "Minimum Bet : " + numericUpDown1.Minimum.ToString() + " pounds"; //初始化四个Greyhound对象 GreyhoundArray[0] = new Greyhound() { MyPictureBox = pictureBox1, StartingPosition = pictureBox1.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox1.Width, Randmizer = MyRandomizer }; GreyhoundArray[1] = new Greyhound() { MyPictureBox = pictureBox2, StartingPosition = pictureBox2.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox2.Width, Randmizer = MyRandomizer }; GreyhoundArray[2] = new Greyhound() { MyPictureBox = pictureBox3, StartingPosition = pictureBox3.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox3.Width, Randmizer = MyRandomizer }; GreyhoundArray[3] = new Greyhound() { MyPictureBox = pictureBox4, StartingPosition = pictureBox4.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox4.Width, Randmizer = MyRandomizer }; //初始化三个Guy对象 GuysArray[0] = new Guy() { Name = "Joe", MyBet = null, Cash = 50, MyRadionButton = JoeRadioButton, MyLabel = joebetlabel }; GuysArray[1] = new Guy() { Name = "Bob", MyBet = null, Cash = 75, MyRadionButton = BobRadioButton, MyLabel = bobbetlabel }; GuysArray[2] = new Guy() { Name = "Al", MyBet = null, Cash = 45, MyRadionButton = AlRadioButton, MyLabel = albetlabel }; for (int i = 0; i < 3; i++) { GuysArray[i].UpdateLabels(); //GuysArray[i].MyBet = new Bet(); } }