-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameForm.cs
289 lines (236 loc) · 8.71 KB
/
GameForm.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Assign_final
{
public partial class GameForm : Form
{
//全局变量
private PictureBox[] banker_card;
private PictureBox[] player_card;
BasePlayer player;
BasePlayer banker;
public int bet;
public Card banker_hidden = new Card();
public Deck deck;
//构造函数
public GameForm()
{
InitializeComponent();
}
public GameForm(string name)
{
InitializeComponent();
player_name.Text = name;
player_name.Show();
banker_card = new PictureBox[5];
player_card = new PictureBox[5];
banker = new Banker("CPU");
player = new Player(name);
deck = new Deck();
bet = 50;
InitBankerBox(banker_card, new Point(670, 120), new Size(85, 110));
InitPlayerBox(player_card, new Point(93, 352), new Size(85, 110));
}
//初始化庄家牌位置
public void InitBankerBox(PictureBox[] pcs, Point p, Size s)
{
for (int i = 0; i < pcs.Length; i++)
{
pcs[i] = new PictureBox();
pcs[i].Location = new Point(p.X - i * 40, p.Y);
pcs[i].Size = s;
this.Controls.Add(pcs[i]);
}
}
//初始化玩家牌位置
public void InitPlayerBox(PictureBox[] pcs, Point p, Size s)
{
for (int i = 0; i < pcs.Length; i++)
{
pcs[i] = new PictureBox();
pcs[i].Location = new Point(p.X + i * 40, p.Y);
pcs[i].Size = s;
this.Controls.Add(pcs[i]);
}
}
//赌注
private void button1_Click(object sender, EventArgs e)
{
bet = 50;
}
private void button2_Click(object sender, EventArgs e)
{
bet = 100;
}
private void button3_Click(object sender, EventArgs e)
{
bet = 150;
}
//游戏函数:newround
private void NewRound()
{
player.StartNextRound();
banker.StartNextRound();
deck = new Deck();
bet = 0;
for (int i = 0; i < 5; i++)
{
banker_card[i].Image = null;
player_card[i].Image = null;
}
}
//游戏函数:比较大小
private void ComparedTo()
{
if (player.TotalRanks < banker.TotalRanks)
RoundOverAndWin(banker.Name, bet);
if (player.TotalRanks > banker.TotalRanks)
RoundOverAndWin(player.Name, bet);
if (player.TotalRanks == banker.TotalRanks)
RoundOverAndTie();
}
private void RoundOverAndWin(string wonName, int bet)
{
if (wonName == player.Name)
{
player.Points += bet;
banker.Points -= bet;
string pp = player.Points.ToString();
string bp = banker.Points.ToString();
CPU_point.Text = pp;
player_point.Text = bp;
}
if (wonName == banker.Name)
{
banker.Points += bet;
player.Points -= bet;
string pp = player.Points.ToString();
string bp = banker.Points.ToString();
CPU_point.Text = pp;
player_point.Text =bp;
}
DialogResult dr = MessageBox.Show(wonName + " wins!是否继续游戏", "游戏结束", MessageBoxButtons.YesNoCancel);
if (dr == DialogResult.Yes)
{
Begin_btn_pic.Show();
}
if (dr == DialogResult.No)
{
this.Close();
}
}
private void RoundOverAndTie()
{
MessageBox.Show("平局","游戏结束");
}
private void Calling_Click(object sender, EventArgs e)
{
Card c = new Card();
c = deck.nextCard();
player.GetACard(c);
player_card[player.Card_count - 1].Image = card_list.Images[c.CardIndex];
player_ranks.Text = player.TotalRanks.ToString();
if (player.WinOrNot() == 1)
RoundOverAndWin(player.Name, bet);
if (player.WinOrNot() == -1)
RoundOverAndWin(banker.Name, bet);
}
private void label7_Click(object sender, EventArgs e)
{
}
private void Stop_Click(object sender, EventArgs e)
{
banker_card[1].Image = card_list.Images[banker_hidden.CardIndex];
if (!banker.GetNextCard() && banker.WinOrNot() == 0)
{
ComparedTo();
}
else
{
while (banker.GetNextCard() && player.WinOrNot() == 0)
{
MessageBox.Show("庄家不够16点,补牌中");
if (banker.WinOrNot() == 0)
{
Card c=new Card();
c=deck.nextCard();
banker.GetACard(c);
banker_card[banker.Card_count - 1].Image = card_list.Images[c.CardIndex];
banker_ranks.Text = banker.TotalRanks.ToString();
if (banker.WinOrNot() == 1)
RoundOverAndWin(banker.Name, bet);
if (banker.WinOrNot() == -1)
RoundOverAndWin(player.Name, bet);
}
else
{
break;
}
}
if (banker.WinOrNot() == 0 && player.WinOrNot() == 0)
{
ComparedTo();
}
}
}
private void pictureBox14_Click(object sender, EventArgs e)
{
}
private void GameForm_Load(object sender, EventArgs e)
{
}
private void begin_game_MouseMove(object sender, MouseEventArgs e)
{
}
private void begin_game_MouseEnter(object sender, EventArgs e)
{
}
private void Begin_btn_pic_MouseEnter(object sender, EventArgs e)
{
Begin_btn_pic.Image = changing_list.Images[1];
}
private void Begin_btn_pic_MouseMove(object sender, MouseEventArgs e)
{
}
private void Begin_btn_pic_MouseLeave(object sender, EventArgs e)
{
Begin_btn_pic.Image = changing_list.Images[0];
}
private void Begin_btn_pic_Click(object sender, EventArgs e)
{
if (player.Points >= bet && banker.Points >= bet)
{
pictureBox1.Show();
pictureBox2.Show();
pictureBox3.Show();
pictureBox4.Show();
pictureBox5.Show();
Begin_btn_pic.Hide();
NewRound();
//开局每人人分两张牌
Card c = new Card();
c = deck.nextCard();
player.GetACard(c);
player_card[0].Image = card_list.Images[c.CardIndex];
c = deck.nextCard();
banker.GetACard(c);
banker_card[0].Image = card_list.Images[c.CardIndex];
c = deck.nextCard();
player.GetACard(c);
player_card[1].Image = card_list.Images[c.CardIndex];
banker_hidden = deck.nextCard();
banker.GetACard(banker_hidden);
//banker_card[1].Image = card_list.Images[c.CardIndex];
banker_card[1].Image = card_list.Images[52];
player_ranks.Text = player.TotalRanks.ToString();
banker_ranks.Text = "未知";
}
else
MessageBox.Show("游戏结束", "点数不足,游戏结束", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
private void 关于游戏ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}//end form
}//end namespace