/
Form1.cs
184 lines (174 loc) · 6.13 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DayAtTheRaces
{
public partial class Form1 : Form
{
Person[] People = new Person[3];
Greyhound[] racers = new Greyhound[4];
public Form1()
{
InitializeComponent();
//Create an array for the three people and the four dogs
for (int i = 0; i < 3; i++)
{
if (i == 0)
{
People[i] = new Person()
{
Name = "Joe",
MyLabel = label5,
MyRadiobutton = radioButton1,
MyBet = new Bet{Amount = 0, Dog = -1, Bettor = People[i]},
cash = 50
};
}
else if (i == 1)
{
People[i] = new Person()
{
Name = "Bob",
MyLabel = label6,
MyRadiobutton = radioButton2,
MyBet = new Bet{Amount = 0, Dog = -1, Bettor = People[i]},
cash = 75
};
}
else if (i == 2)
{
People[i] = new Person()
{
Name = "Al",
MyLabel = label7,
MyRadiobutton = radioButton3,
MyBet = new Bet{Amount = 0, Dog = -1, Bettor = People[i]},
cash = 45
};
}
else MessageBox.Show("Loading error in people array creation");
}
for (int i = 0; i < 4; i++)
{
System.Threading.Thread.Sleep(2);
if (i == 0)
{
racers[i] = new Greyhound()
{
MyPictureBox = pictureBox2,
StartingLocation = pictureBox2.Location.X,
RacetrackLength = pictureBox1.Size.Width,
Location = pictureBox2.Location.X,
MyRandom = new Random()
};
}
else if (i == 1)
{
racers[i] = new Greyhound()
{
MyPictureBox = pictureBox3,
StartingLocation = pictureBox3.Location.X,
RacetrackLength = pictureBox1.Size.Width,
Location = pictureBox2.Location.X,
MyRandom = new Random()
};
}
else if (i == 2)
{
racers[i] = new Greyhound()
{
MyPictureBox = pictureBox4,
StartingLocation = pictureBox4.Location.X,
RacetrackLength = pictureBox1.Size.Width,
Location = pictureBox2.Location.X,
MyRandom = new Random()
};
}
else if (i == 3)
{
racers[i] = new Greyhound()
{
MyPictureBox = pictureBox5,
StartingLocation = pictureBox5.Location.X,
RacetrackLength = pictureBox1.Size.Width,
Location = pictureBox2.Location.X,
MyRandom = new Random()
};
}
else MessageBox.Show("Error in racers array creation");
}
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
label2.Text = "Joe";
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
label2.Text = "Bob";
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
label2.Text = "Al";
}
private void button1_Click(object sender, EventArgs e)
{
int amount = (int)numericUpDown1.Value;
int dog = (int)numericUpDown2.Value;
MessageBox.Show(label2.Text + " bets $" + amount + " on dog #" + dog);
if (label2.Text == "Joe")
{
People[0].PlaceBet(amount, dog-1);
}
else if (label2.Text == "Bob")
{
People[1].PlaceBet(amount, dog-1);
}
else if (label2.Text == "Al")
{
People[2].PlaceBet(amount, dog-1);
}
else MessageBox.Show("Bet setting error");
}
private void button2_Click(object sender, EventArgs e)
{
bool raceWon = false;
int dogWinner = -1;
MessageBox.Show("The race is now starting!");
while(!raceWon)
{
for (int i = 0; i < 4; i++)
{
raceWon = racers[i].Run();
System.Threading.Thread.Sleep(1);
if (raceWon)
{
dogWinner = i;
break;
}
}
}
MessageBox.Show("Dog #" + (dogWinner+1) + " has won!");
for (int i = 0; i < 3; i++)
{
People[i].Collect(dogWinner);
People[i].UpdateLabels();
}
for (int i = 0; i < 4; i++)
{
racers[i].TakeStartingPosition();
}
}
}
}