C#课程设计作业,花了两天时间,其中抠图找图都花了大半天(后悔以前没去学PS,后悔莫及,所以最后做出来自己都看不下去的粗糙,不过只能这样了)
第一天上午:构思整个的大体框架,要实现的功能
第一天下午:找图,抠图,找资源,地图的绘制
第二天上午:被搜索联通块以及方块的消除难住了,后面参考了一些才解决主要核心的,包括判断相邻,执行交换,消除,执行下落,利用了3个Timer组件
第二天下午:技能体系,充值体系,修修改改,勉强做出来了

(一)课程作业:C#消消乐完整实现
利用 C#winform 实现了消消乐游戏的制作 开发环境 VS2015,SQL sever 2008,
实现功能:
1.登录,注册窗口
2.主界面消消乐的实现
3.技能体系:3个技能
4.充值体系
5.背包功能的实现
6.闯关功能的实现
(二)主要窗体
1.登录,注册

2.主界面

3.充值界面,教学界面

(三)各窗体核心代码
1.登录,注册
using System; using System.Collections.Generic; using System.ComponentModel;
using System.Data; using System.Data.SqlClient; using System.Drawing; using
System.Linq; using System.Text; using System.Threading.Tasks; using System.
Windows.Forms; using System.Media; namespace KillGame { public partial class
Login : Form { public Login() { InitializeComponent(); } private void
button1_Click(object sender, EventArgs e)//登录 { if(checkBox1 .Checked ==true) {
if (textBox1.Text.Trim() == "123456" && textBox2.Text.Trim() == "123456") {
string sname = "老师"; startProgress(progressBar1); this.Hide(); Game game = new
KillGame.Game(sname); game.Show(); } else { MessageBox.Show(
"登录失败,超级用户账号密码都是123456,再试试"); } } else { string id = textBox1.Text.Trim().
ToString(); string pwd = textBox2.Text.Trim().ToString(); if (textBox1.Text.Trim
() == "" || textBox2.Text.Trim() == "") { MessageBox.Show("请输入账号或密码!"); return;
} SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial
Catalog=MBook;Persist Security Info=True;User ID=sa;Password='zdllxf211215'");
string strselect = "select Name from TUser where id='" + textBox1.Text.Trim().
ToString() + "'and pwd='" + textBox2.Text.Trim().ToString() + "'"; SqlCommand
cmd= new SqlCommand(strselect, conn); conn.Open(); string name = cmd.
ExecuteScalar().ToString(); if (name != null) { startProgress(progressBar1);
this.Hide(); Game game = new KillGame.Game(name); game.Show(); } else {
MessageBox.Show("登录失败!"); } } } private void button2_Click(object sender,
EventArgs e)//取消 { this.Close(); } private void button3_Click(object sender,
EventArgs e)//注册 { Logon logon = new Logon(); logon.Show(); } public void
SetCursor(Bitmap cursor, Point hotPoint)//自定义光标 { int hotX = hotPoint.X; int
hotY= hotPoint.Y; Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX,
cursor.Height * 2 - hotY); Graphics g = Graphics.FromImage(myNewCursor); g.Clear
(Color.FromArgb(0, 0, 0, 0)); g.DrawImage(cursor, cursor.Width - hotX, cursor.
Height- hotY, cursor.Width, cursor.Height); this.Cursor = new Cursor(myNewCursor
.GetHicon()); g.Dispose(); myNewCursor.Dispose(); } private void startProgress(
ProgressBar pBar1) { pBar1.Visible = true;// 显示进度条控件. pBar1.Minimum = 1;//
设置进度条最小值. pBar1.Maximum = 15;// 设置进度条最大值. pBar1.Value = 1;// 设置进度条初始值 pBar1.Step
= 1;// 设置每次增加的步长 //创建Graphics对象 Graphics g = pBar1.CreateGraphics(); for (int x
= 1; x <= 15; x++) { //执行PerformStep()函数 pBar1.PerformStep(); string str = Math.
Round((100 * x / 15.0), 2).ToString("#0.00 ") + "%"; Font font = new Font(
"Times New Roman", (float)10, FontStyle.Regular); PointF pt = new PointF(pBar1.
Width/ 2 - 17, pBar1.Height / 2 - 7); g.DrawString(str, font, Brushes.Black , pt
); //每次循环让程序休眠300毫秒 System.Threading.Thread.Sleep(300); } pBar1.Visible = false;
//MessageBox.Show("success!"); } private void Login_Load(object sender,
EventArgs e)//窗体加载 { SoundPlayer bm = new SoundPlayer("Music\\bj.wav");//背景音乐 bm
.PlayLooping(); Bitmap a = (Bitmap)Bitmap.FromFile("Image\\mouse.png");
SetCursor(a, new Point(0, 0)); } } } using System; using System.Collections.
Generic; using System.ComponentModel; using System.Data; using System.Data.
SqlClient; using System.Drawing; using System.Linq; using System.Text; using
System.Threading.Tasks; using System.Windows.Forms; namespace KillGame { public
partial class Logon : Form { public Logon() { InitializeComponent(); } private
void button1_Click(object sender, EventArgs e)//注册 { if (textBox1.Text.Trim() ==
"" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.
Trim()=="") { MessageBox.Show("请输入完整信息!"); return; } if(textBox2 .Text .Trim ()
==textBox3 .Text .Trim()) { SqlConnection conn = new SqlConnection(@"Data
Source=(local);Initial Catalog=MBook;Persist Security Info=True;User
ID=sa;Password='zdllxf211215'"); string strselect = "insert into TUser values('"
+ textBox1.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox2.Text.
Trim() + "')"; SqlCommand cmd = new SqlCommand(strselect, conn); conn.Open();
int a = cmd.ExecuteNonQuery(); if (a == 1) { MessageBox.Show("注册成功,快去征战吧,骚年!");
} else { MessageBox.Show("注册失败!"); } } else { MessageBox.Show("密码前后不一致,注册失败!");
} } public void SetCursor(Bitmap cursor, Point hotPoint)//自定义光标 { int hotX =
hotPoint.X; int hotY = hotPoint.Y; Bitmap myNewCursor = new Bitmap(cursor.Width
* 2 - hotX, cursor.Height * 2 - hotY); Graphics g = Graphics.FromImage(
myNewCursor); g.Clear(Color.FromArgb(0, 0, 0, 0)); g.DrawImage(cursor, cursor.
Width- hotX, cursor.Height - hotY, cursor.Width, cursor.Height); this.Cursor =
new Cursor(myNewCursor.GetHicon()); g.Dispose(); myNewCursor.Dispose(); }
private void button2_Click(object sender, EventArgs e)//取消 { this.Close(); }
private void Logon_Load(object sender, EventArgs e)//加载 { Bitmap a = (Bitmap)
Bitmap.FromFile("Image\\mouse.png"); SetCursor(a, new Point(0, 0)); } } }
2.主界面窗口
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; using System.Media;
namespace KillGame { public partial class Game : Form { Star[,] getmap = new
Star[15, 12];//地图信息 Point topleft = new Point(60, 5);//坐标 int gamestart = 0;
//游戏开始 int gamestop = 0; int ispic = 0;//记录是否选中方块 int pickRow = 0;//记录选中的行 int
pickCol= 0;//记录选中的列 int dropRow = 0; int dropCol = 0; int changeFlag = 0;
//记录是否交换成功 int size = 60;//方块的大小 string news;//消息列表 int height = 10;//地图大小 int
width= 10; int time = 60;//时间 int money = 0;//金币 int score = 0;//积分 int gnum = 1
;//关卡数 int step = 60; int skill1num = 0;//技能1使用次数 int skill2num = 0;//技能2使用次数
int skill3num = 0;//技能3使用次数 Star s1 = new Star(starcolor.无, 60, 0, new Point(0,
0));//用于临时交换的两个变量 Star s2 = new Star(starcolor.无, 60, 0, new Point(0, 0)); int
x1= 0; int x2 = 0; int y1 = 0; int y2 = 0; public Game() { InitializeComponent()
; SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.
DoubleBuffer, true); } public Game (string name)//构造函数 { InitializeComponent();
Name= name; } public void SkillReload()//刷新技能 { } public void GetMap()//随机生成地图 {
Random rnd = new Random(DateTime.Now.Second); for (int i=1;i<=height ;i++) for(
int j=1;j<=width ; j++) { getmap[i, j] = new KillGame.Star((starcolor)rnd.Next(1
, 7), size, 0, new Point(topleft.X + (j - 1) * size, topleft.Y + (i - 1) * size)
); } } public void ReGetMap(Graphics g)//绘制地图 { for (int i = 1; i <= height ; i
++) for (int j = 1; j <= width ; j++) { getmap[i, j].Drawing(g); } } public bool
GetRowandClo(Point point,out int row,out int clo)//判断点击是否有效,并且输出点击的行列坐标 { int
srow= (point.Y - topleft.Y) / size + 1; int sclo = (point.X - topleft.X) / size
+ 1; if (srow <=10&&srow >=1&&sclo <=10&&sclo >= 1) { row = srow; clo = sclo;
return true;//点击有效,超出地图范围 } else { row = -1; clo = -1; return false;
//点击无效,超出地图范围 } } public void SwapStar(int x1,int y1,int x2,int y2)
//交换星星,只是交换了两个星星的颜色 { starcolor scolor = getmap[x1, y1].Color; getmap[x1, y1].
Color= getmap[x2, y2].Color; getmap[x2, y2].Color = scolor; } public bool
KillStar() { int a = 0; bool isclean = false; //初始化消除标记 for (int i = 1; i <=
height; i++) for (int j = 1; j <= width; j++) { getmap[i, j].Killed = 0; }
//遍历每个方格,每个都向右向下搜索 for (int i = 1; i <= height; i++) for (int j = 1; j <= width;
j++) { if (getmap[i, j].Color != starcolor.无)//如果有颜色则搜索 { //纵向搜 int cnt = 1;
//记录相连的同色方块个数 int x = i + 1; while (x <= height) { if (getmap[x, j].Color ==
getmap[i, j].Color)//如果颜色相同记录个数 { x++; cnt++; } else break; } if (cnt >= 3)
//如果大于等于3个,标记将消除 { isclean = true; for (int k = i; k < i + cnt; k++) getmap[k, j
].Killed = 1; a += cnt; } //横向搜 cnt = 1; int y = j + 1; while (y <= width) { if
(getmap[i, y].Color == getmap[i, j].Color)//如果颜色相同记录个数 { y++; cnt++; } else
break; } if (cnt >= 3)//如果大于等于3个,标记将消除 { isclean = true; for (int k = j; k < j +
cnt; k++) getmap[i, k].Killed = 1; a += cnt; } } }
//注意这里一定要先标记再同意消除,如果直接在上面消除,会导致十字不可消 for (int i = 1; i <= height; i++)
//将待消除的方块消除 for (int j = 1; j <= width; j++) { if (getmap[i, j].Killed == 1)
getmap[i, j].Color = starcolor.无; } time += a /= 3;//奖励时间 time = Math.Min(time,
40);//时间不能超过最大的40 score += a * 10;//奖励分数 money += a ;//奖励金钱 timelable .Text =
time.ToString() + "s";//更新标签 moneylable.Text = money.ToString(); scorelable.Text
= score .ToString(); if(money >money ) Music("Music\\1.wav"); if (score >=500+
gnum* 250)//晋级成功 { timer1.Enabled = false; time +=30;//奖励时间 time = Math.Min(time
, 40);//时间不能超过最大的40 timelable.Text = time.ToString() + "s";//更新标签 money += gnum
* 40; moneylable.Text = money.ToString();//奖励金币 score = 0;//积分清零 scorelable.Text
= score.ToString(); gnum++; snumlable.Text = gnum.ToString(); textBox1.Text =
"消息:恭喜您晋级成功," + Name + "阁下"; Music("Music\\12902.wav"); GetMap(); timer3.Enabled
= true; timer1.Enabled = true; pictureBox4.Invalidate(); } return isclean;
//返回是否可消 } private void button4_Click(object sender, EventArgs e)//开始游戏 { Bitmap
a= (Bitmap)Bitmap.FromFile("Image\\mouse.png"); SetCursor(a, new Point(0, 0));
GetMap(); gamestart = 1; gamestop = 0; time = 60; score = 0; money = 0; gnum = 1
; snumlable.Text = gnum.ToString(); namelable.Text = Name; textBox1.Text = "";
textBox1.AppendText("消息:欢迎您来到KillGame!" + Name + "阁下!"); pictureBox4.Invalidate(
);//重绘图片 timer3.Enabled = true; timer1.Enabled = true;//开始计时 } private void
button1_Click(object sender, EventArgs e)//技能1购买 { if (gamestart == 1 &&gamestop
== 0) { timer1.Enabled = false; timelable.Text = "暂停"; if (MessageBox.Show(
"是否花费30金币购买火舞旋风?", "购买", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) ==
DialogResult.OK) { if (money >= 30) { money -= 30; skill1num += 1; s1lable.Text
= skill1num.ToString(); } else { MessageBox.Show(
"金币不足,骚年,开启钞能力吧!点击左下角充值系统,你值得拥有!", "购买失败", MessageBoxButtons.OK, MessageBoxIcon.
Warning); } } moneylable .Text = money.ToString(); timer1.Enabled = true; } }
private void button2_Click(object sender, EventArgs e)//技能2购买 { if (gamestart ==
1 && gamestop == 0) { timer1.Enabled = false; timelable.Text = "暂停"; if (
MessageBox.Show("是否花费30金币购买万仞浮生?", "购买", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK) { if (money >= 30) { money -= 30;
skill2num+= 1; s2lable.Text = skill2num.ToString(); } else { MessageBox.Show(
"金币不足,骚年,开启钞能力吧!点击左下角充值系统,你值得拥有!", "购买失败", MessageBoxButtons.OK, MessageBoxIcon.
Warning); } } moneylable.Text = money.ToString(); timer1.Enabled = true; } }
private void button3_Click(object sender, EventArgs e)//技能3购买 { if (gamestart ==
1 && gamestop == 0) { timer1.Enabled = false; timelable.Text = "暂停"; if (
MessageBox.Show("是否花费30金币购买时间掌控?", "购买", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK) { if (money >= 30) { money -= 30;
skill3num+= 1; s3lable.Text = skill3num.ToString(); } else { MessageBox.Show(
"金币不足,骚年,开启钞能力吧!点击左下角充值系统,你值得拥有!", "购买失败", MessageBoxButtons.OK, MessageBoxIcon.
Warning); } } moneylable.Text = money.ToString(); timer1.Enabled = true; } }
private void button5_Click(object sender, EventArgs e)//退出游戏 { Application.Exit(
); } private void button6_Click(object sender, EventArgs e)//新手教学 { About about
= new About(); about.Show(); } private void pictureBox1_Click(object sender,
EventArgs e)//技能1火舞旋风释放 { if(gamestart ==1&&gamestop == 0) { if(skill1num > 0) {
skill1num--; s1lable.Text = skill1num.ToString(); textBox1.Text = "消息:伟大的"+Name
+"阁下,您使用了火舞旋风!"; Music("Music\\skill.wav"); Random myRand = new Random(DateTime.
Now.Second);//随机选择一种颜色 int x = myRand.Next(1, 7); for (int i = 1; i <= height; i
++)//搜索所有方块,若是选择的颜色则消除 for (int j = 1; j <= width; j++) { if ((int)getmap[i, j].
Color== x) getmap[i, j].Color = starcolor.无; } timer3.Enabled = true;
pictureBox4.Invalidate(); } else { timer1.Enabled = false; timelable .Text =
"暂停"; MessageBox.Show("骚年,你的魔法不足,不氪金怎么变强,试试你的钞能力吧", "使用失败", MessageBoxButtons.OK
, MessageBoxIcon.Warning); timer1.Enabled = true; } } } private void
pictureBox2_Click(object sender, EventArgs e)//技能2万仞浮生释放 { if (gamestart == 1 &&
gamestop== 0) { if (skill2num > 0) { timer1.Enabled = false; skill2num--;
s2lable.Text = skill2num.ToString(); textBox1.Text = "消息:伟大的" + Name +
"阁下,您使用了万物浮生!"; Music("Music\\skill.wav"); GetMap(); //重新刷新地图 timer3.Enabled =
true; timer1.Enabled = true; pictureBox4.Invalidate(); } else { timer1.Enabled =
false; timelable.Text = "暂停"; MessageBox.Show("骚年,你的魔法不足,不氪金怎么变强,试试你的钞能力吧",
"使用失败", MessageBoxButtons.OK, MessageBoxIcon.Warning); timer1.Enabled = true; }
} } private void pictureBox3_Click(object sender, EventArgs e)//技能3时间掌控释放 { if (
gamestart== 1 && gamestop == 0) { if (skill3num > 0) { skill3num--; s3lable.Text
= skill3num.ToString(); time += 10; //时间增加 timelable.Text = time.ToString() +
"s"; //更新标签 textBox1.Text ="消息:伟大的" + Name + "阁下,您使用了时间掌控!"; Music(
"Music\\skill.wav"); } else { timer1.Enabled = false; timelable.Text = "暂停";
MessageBox.Show("骚年,你的魔法不足,不氪金怎么变强,试试你的钞能力吧", "使用失败", MessageBoxButtons.OK,
MessageBoxIcon.Warning); timer1.Enabled = true; } } } private void Music(string
path) { SoundPlayer player = new SoundPlayer(); player.SoundLocation = path;
player.Load(); player.Play(); } private void timer1_Tick(object sender,
EventArgs e)//记录时间 { if(time == 0) { gamestart = 0; timer1.Enabled = false;
MessageBox.Show("游戏结束!"); } timelable.Text = time.ToString() + "s"; time--; }
private void pictureBox4_MouseDown(object sender, MouseEventArgs e)//鼠标点击 { if (
timer3.Enabled == false && gamestart == 1 && gamestop == 0) { Music(
"Music\\click.wav"); if (ispic == 0) { int row, col; bool value = GetRowandClo(
new Point(e.X, e.Y), out row, out col);//第一次点击,得到点击位置的行列 if (value == true) { if
(getmap[row, col].Color != starcolor.无) { pickRow = row; pickCol = col; ispic =
1; getmap[pickRow, pickCol].Selected(); //Music("Music\\12596.wav"); } } } else
{ int row, col; bool value = GetRowandClo(new Point(e.X, e.Y), out row, out col)
;//第二次点击,得到点击位置的行列 if (value == true) { if (getmap[row, col].Color != starcolor.
无) { if (row == pickRow && Math.Abs(col - pickCol) == 1 || col == pickCol &&
Math.Abs(row - pickRow) == 1)//判断是否相邻 { dropCol = col; dropRow = row; getmap[
pickRow, pickCol].Select = 0; s1 = new Star(getmap[pickRow, pickCol].Color,
getmap[pickRow, pickCol].Size, getmap[pickRow, pickCol].Select, getmap[pickRow,
pickCol].Top); s2 = new Star(getmap[dropRow, dropCol].Color, getmap[dropRow,
dropCol].Size, getmap[dropRow, dropCol].Select, getmap[dropRow, dropCol].Top);
getmap[pickRow, pickCol].Color = starcolor.无; getmap[dropRow, dropCol].Color =
starcolor.无; pictureBox4.Invalidate(); x1 = s1.Top.X; y1 = s1.Top.Y; x2 = s2.Top
.X; y2 = s2.Top.Y; changeFlag = 0; timer1.Enabled = false; timer2.Enabled = true
;//执行交换 } else//重新标记 { getmap[pickRow, pickCol].Select = 0; pickRow = row;
pickCol= col; getmap[pickRow, pickCol].Selected(); ispic = 1; } } } } }
pictureBox4.Invalidate(); } private void timer2_Tick(object sender, EventArgs e)
//交换 { pictureBox4.Invalidate(); int tax = 0; if (x1 == x2) { if(y1<y2) { s1.Top
= new Point(s1.Top.X, s1.Top.Y + step); s2.Top = new Point(s2.Top.X, s2.Top.Y -
step); if (s1.Top.Y >= y2) tax = 1; } else { s1.Top = new Point(s1.Top.X, s1.Top
.Y - step); s2.Top = new Point(s2.Top.X, s2.Top.Y + step); if (s1.Top.Y <= y2)
tax= 1; } } else if (y1 == y2) { if(x1<x2) { s1.Top = new Point(s1.Top.X + step,
s1.Top.Y); s2.Top = new Point(s2.Top.X - step, s2.Top.Y); if (s1.Top.X >= x2)
tax= 1; } else { s1.Top = new Point(s1.Top.X - step, s1.Top.Y); s2.Top = new
Point(s2.Top.X + step, s2.Top.Y); if (s1.Top.X <= x2) tax = 1; } } if(tax == 1)
{ timer2.Enabled = false;// timer1.Enabled = true;//计时器继续工作 getmap[pickRow,
pickCol].Color = s2.Color; getmap[dropRow, dropCol].Color = s1.Color;//交换颜色
pictureBox4.Invalidate(); if(changeFlag == 0) { if (!KillStar())//判断是否可以消除 {
//继续交换回来 s1 = new Star(getmap[pickRow, pickCol].Color, getmap[pickRow, pickCol].
Size, getmap[pickRow, pickCol].Select, getmap[pickRow, pickCol].Top); s2 = new
Star(getmap[dropRow, dropCol].Color, getmap[dropRow, dropCol].Size, getmap[
dropRow, dropCol].Select, getmap[dropRow, dropCol].Top); getmap[pickRow, pickCol
].Color = starcolor.无; getmap[dropRow, dropCol].Color = starcolor.无; pictureBox4
.Invalidate(); timer1.Enabled = false; timer2.Enabled = true;//重新交换 getmap[
pickRow, pickCol].Select = 0; ispic = 0; changeFlag = 1;//这次是交换成功了 } else {
timer3.Enabled = true;//执行下落 pickRow = 0; pickCol = 1; ispic = 0; } } } }
private void timer3_Tick(object sender, EventArgs e)//下落 { for (int j=1; j<=
width;j++) { for (int i = height; i >= 2; i--) { if (getmap[i, j].Color ==
starcolor.无) { for (int c = i; c >= 2; c--) SwapStar(c, j, c - 1, j); break; } }
} Random myRand = new Random(); for (int j = 1; j <= width; j++) { if (getmap[1,
j].Color == starcolor.无) getmap[1, j].Color = (starcolor)myRand.Next(1, 7); }
pictureBox4.Invalidate(); int tax = 0; for (int i = 1; i <= height; i++) { for (
int j = 1; j <= width; j++) { if(getmap [i,j].Color ==starcolor.无) { tax = 1;
break; } } if (tax == 1) break; } if(tax == 0) { if(!KillStar ()) { timer3.
Enabled= false; } } } private void s3lable_Click(object sender, EventArgs e) { }
public void SetCursor(Bitmap cursor, Point hotPoint)//自定义光标 { int hotX =
hotPoint.X; int hotY = hotPoint.Y; Bitmap myNewCursor = new Bitmap(cursor.Width
* 2 - hotX, cursor.Height * 2 - hotY); Graphics g = Graphics.FromImage(
myNewCursor); g.Clear(Color.FromArgb(0, 0, 0, 0)); g.DrawImage(cursor, cursor.
Width- hotX, cursor.Height - hotY, cursor.Width, cursor.Height); this.Cursor =
new Cursor(myNewCursor.GetHicon()); g.Dispose(); myNewCursor.Dispose(); }
private void pictureBox4_Paint(object sender, PaintEventArgs e)//绘制地图函数 { if(
gamestart== 1) { ReGetMap(e.Graphics); if(timer2 .Enabled ==true) { s1.Drawing(e
.Graphics); s2.Drawing(e.Graphics); } } } private void Game_Load(object sender,
EventArgs e) { Music("Music\\bj.wav"); time = 0; score = 0; money = 0; gnum = 0;
moneylable.Text = money.ToString(); scorelable.Text = score.ToString();
timelable.Text = time.ToString(); snumlable.Text = gnum.ToString(); } private
void pictureBox5_Click(object sender, EventArgs e)//背包 { } private void
pictureBox6_Click(object sender, EventArgs e)//商城 { Money m = new Money();
//m.Show(); if(m.ShowDialog()==DialogResult.OK) { this.money += m.Num;
moneylable.Text = money.ToString(); } } } }
3.充值,背包,教学界面
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 KillGame {
public partial class Money : Form { public Money() { InitializeComponent(); }
private int num; public int Num { get { return num; } set { num = value; } }
//private void label1_Click(object sender, EventArgs e) //{ // DialogResult
reult=MessageBox.Show("是否要花费20元购买200枚金币?", "充值提醒", MessageBoxButtons.OKCancel);
// if(reult ==DialogResult.OK) // { // num = 200; // MessageBox.Show("充值成功!");
// } // else // { // this.Close(); // } //} private void button1_Click(object
sender, EventArgs e) { this.Close(); } private void button2_Click(object sender,
EventArgs e) { DialogResult reult = MessageBox.Show("是否要花费20元购买200枚金币?", "充值提醒",
MessageBoxButtons.OKCancel); if (reult == DialogResult.OK) { num = 200;
MessageBox.Show("充值成功!"); } else { this.Close(); } } } }
时间紧凑,略显粗糙,欢迎指出错误!

技术
下载桌面版
GitHub
Gitee
SourceForge
百度网盘(提取码:draw)
云服务器优惠
华为云优惠券
腾讯云优惠券
阿里云优惠券
Vultr优惠券
站点信息
问题反馈
邮箱:[email protected]
吐槽一下
QQ群:766591547
关注微信