C# Course design assignment , It took two days , It took more than half a day to dig and find the picture ( I regret not going to school before PS, too late to regret , So in the end, I can't see the roughness , But that's the only way )
First morning : Conceive the general framework of the whole , Functions to be implemented
First day afternoon : Map finding , Matting , Find resources , Mapping
The next morning : It is difficult to eliminate the search connection blocks and blocks , Later, we refer to some to solve the main core problems , Including judging adjacent , Perform exchange , eliminate , Execute drop , Used 3 individual Timer assembly
The next afternoon : Skill system , Recharge system , Modification , Barely made it
( one ) Course assignment :C# Complete implementation of Xiaole
utilize C#winform The production of Xiaole game is realized development environment VS2015,SQL sever 2008,
Realize function :
1. Sign in , Registration window
2. Implementation of main interface Xiaole
3. Skill system :3 Skills
4. Recharge system
5. Realization of knapsack function
6. Realization of the function of breaking through customs
( two ) Main form
1. Sign in , register
2. main interface
3. Recharge interface , Teaching interface
( three ) Core code of each form
1. Sign in , register
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)// Sign in { if(checkBox1 .Checked ==true) {
if (textBox1.Text.Trim() == "123456" && textBox2.Text.Trim() == "123456") {
string sname = " teacher "; startProgress(progressBar1); this.Hide(); Game game = new
KillGame.Game(sname); game.Show(); } else { MessageBox.Show(
" Login failed , Super user accounts and passwords are 123456, Try again "); } } else { string id = textBox1.Text.Trim().
ToString(); string pwd = textBox2.Text.Trim().ToString(); if (textBox1.Text.Trim
() == "" || textBox2.Text.Trim() == "") { MessageBox.Show(" Please enter your account or password !"); 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(" Login failed !"); } } } private void button2_Click(object sender,
EventArgs e)// cancel { this.Close(); } private void button3_Click(object sender,
EventArgs e)// register { Logon logon = new Logon(); logon.Show(); } public void
SetCursor(Bitmap cursor, Point hotPoint)// Custom cursor { 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;// Show progress bar controls . pBar1.Minimum = 1;//
Set progress bar minimum . pBar1.Maximum = 15;// Set maximum value of progress bar . pBar1.Value = 1;// Set initial value of progress bar pBar1.Step
= 1;// Sets the step size for each increment // establish Graphics object Graphics g = pBar1.CreateGraphics(); for (int x
= 1; x <= 15; x++) { // implement PerformStep() function 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
); // Let the program sleep each cycle 300 millisecond System.Threading.Thread.Sleep(300); } pBar1.Visible = false;
//MessageBox.Show("success!"); } private void Login_Load(object sender,
EventArgs e)// Form loading { SoundPlayer bm = new SoundPlayer("Music\\bj.wav");// background music 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)// register { if (textBox1.Text.Trim() ==
"" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.
Trim()=="") { MessageBox.Show(" Please enter complete information !"); 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(" login was successful , Go to war , Sao Nian !");
} else { MessageBox.Show(" login has failed !"); } } else { MessageBox.Show(" Inconsistent passwords , login has failed !");
} } public void SetCursor(Bitmap cursor, Point hotPoint)// Custom cursor { 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)// cancel { this.Close(); }
private void Logon_Load(object sender, EventArgs e)// load { Bitmap a = (Bitmap)
Bitmap.FromFile("Image\\mouse.png"); SetCursor(a, new Point(0, 0)); } } }
2. Main interface window
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];// Map information Point topleft = new Point(60, 5);// coordinate int gamestart = 0;
// The game begins int gamestop = 0; int ispic = 0;// Record whether the box is selected int pickRow = 0;// Record the selected row int
pickCol= 0;// Record the selected column int dropRow = 0; int dropCol = 0; int changeFlag = 0;
// Whether records are exchanged successfully int size = 60;// Block size string news;// Message list int height = 10;// Map size int
width= 10; int time = 60;// time int money = 0;// Gold coins int score = 0;// integral int gnum = 1
;// Number of levels int step = 60; int skill1num = 0;// skill 1 Usage times int skill2num = 0;// skill 2 Usage times
int skill3num = 0;// skill 3 Usage times Star s1 = new Star(starcolor. nothing , 60, 0, new Point(0,
0));// Two variables for temporary exchange Star s2 = new Star(starcolor. nothing , 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)// Constructor { InitializeComponent();
Name= name; } public void SkillReload()// Refresh skills { } public void GetMap()// Randomly generated map {
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)// draw a map { 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)// Determine whether the click is valid , And output the row and column coordinates of clicks { 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;// Click valid , Out of map range } else { row = -1; clo = -1; return false;
// Click invalid , Out of map range } } public void SwapStar(int x1,int y1,int x2,int y2)
// Exchange stars , Just exchanged the colors of the two stars { 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; // Initialize elimination flag for (int i = 1; i <=
height; i++) for (int j = 1; j <= width; j++) { getmap[i, j].Killed = 0; }
// Traverse each square , Each search right and down for (int i = 1; i <= height; i++) for (int j = 1; j <= width;
j++) { if (getmap[i, j].Color != starcolor. nothing )// Search if there are colors { // Longitudinal search int cnt = 1;
// Record the number of connected blocks of the same color int x = i + 1; while (x <= height) { if (getmap[x, j].Color ==
getmap[i, j].Color)// If the colors are the same, record the number { x++; cnt++; } else break; } if (cnt >= 3)
// If greater than or equal to 3 individual , The mark will be eliminated { isclean = true; for (int k = i; k < i + cnt; k++) getmap[k, j
].Killed = 1; a += cnt; } // Horizontal search cnt = 1; int y = j + 1; while (y <= width) { if
(getmap[i, y].Color == getmap[i, j].Color)// If the colors are the same, record the number { y++; cnt++; } else
break; } if (cnt >= 3)// If greater than or equal to 3 individual , The mark will be eliminated { isclean = true; for (int k = j; k < j +
cnt; k++) getmap[i, k].Killed = 1; a += cnt; } } }
// Note that you must mark here before you agree to eliminate it , If you eliminate it directly , Will cause the cross to be irresistible for (int i = 1; i <= height; i++)
// Eliminate the blocks to be eliminated for (int j = 1; j <= width; j++) { if (getmap[i, j].Killed == 1)
getmap[i, j].Color = starcolor. nothing ; } time += a /= 3;// Reward time time = Math.Min(time,
40);// The time cannot exceed the maximum 40 score += a * 10;// Reward score money += a ;// Reward money timelable .Text =
time.ToString() + "s";// Update label moneylable.Text = money.ToString(); scorelable.Text
= score .ToString(); if(money >money ) Music("Music\\1.wav"); if (score >=500+
gnum* 250)// Promotion successful { timer1.Enabled = false; time +=30;// Reward time time = Math.Min(time
, 40);// The time cannot exceed the maximum 40 timelable.Text = time.ToString() + "s";// Update label money += gnum
* 40; moneylable.Text = money.ToString();// Bonus gold coins score = 0;// Integral clearing scorelable.Text
= score.ToString(); gnum++; snumlable.Text = gnum.ToString(); textBox1.Text =
" news : Congratulations on your promotion ," + Name + " your excellency "; Music("Music\\12902.wav"); GetMap(); timer3.Enabled
= true; timer1.Enabled = true; pictureBox4.Invalidate(); } return isclean;
// Returns whether it can be cancelled } private void button4_Click(object sender, EventArgs e)// Start the game { 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(" news : Welcome to KillGame!" + Name + " your excellency !"); pictureBox4.Invalidate(
);// Redraw picture timer3.Enabled = true; timer1.Enabled = true;// Start timing } private void
button1_Click(object sender, EventArgs e)// skill 1 purchase { if (gamestart == 1 &&gamestop
== 0) { timer1.Enabled = false; timelable.Text = " suspend "; if (MessageBox.Show(
" Whether to spend 30 Gold coins to buy Fire Dance whirlwind ?", " purchase ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) ==
DialogResult.OK) { if (money >= 30) { money -= 30; skill1num += 1; s1lable.Text
= skill1num.ToString(); } else { MessageBox.Show(
" Insufficient gold coins , Sao Nian , Turn on the cash ability ! Click the recharge system in the lower left corner , You deserve it !", " Purchase failed ", MessageBoxButtons.OK, MessageBoxIcon.
Warning); } } moneylable .Text = money.ToString(); timer1.Enabled = true; } }
private void button2_Click(object sender, EventArgs e)// skill 2 purchase { if (gamestart ==
1 && gamestop == 0) { timer1.Enabled = false; timelable.Text = " suspend "; if (
MessageBox.Show(" Whether to spend 30 Buy gold coins for Wanren Fusheng ?", " purchase ", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK) { if (money >= 30) { money -= 30;
skill2num+= 1; s2lable.Text = skill2num.ToString(); } else { MessageBox.Show(
" Insufficient gold coins , Sao Nian , Turn on the cash ability ! Click the recharge system in the lower left corner , You deserve it !", " Purchase failed ", MessageBoxButtons.OK, MessageBoxIcon.
Warning); } } moneylable.Text = money.ToString(); timer1.Enabled = true; } }
private void button3_Click(object sender, EventArgs e)// skill 3 purchase { if (gamestart ==
1 && gamestop == 0) { timer1.Enabled = false; timelable.Text = " suspend "; if (
MessageBox.Show(" Whether to spend 30 Gold coin purchase time control ?", " purchase ", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK) { if (money >= 30) { money -= 30;
skill3num+= 1; s3lable.Text = skill3num.ToString(); } else { MessageBox.Show(
" Insufficient gold coins , Sao Nian , Turn on the cash ability ! Click the recharge system in the lower left corner , You deserve it !", " Purchase failed ", MessageBoxButtons.OK, MessageBoxIcon.
Warning); } } moneylable.Text = money.ToString(); timer1.Enabled = true; } }
private void button5_Click(object sender, EventArgs e)// Exit the game { Application.Exit(
); } private void button6_Click(object sender, EventArgs e)// Novice Teaching { About about
= new About(); about.Show(); } private void pictureBox1_Click(object sender,
EventArgs e)// skill 1 Fire Dance whirlwind release { if(gamestart ==1&&gamestop == 0) { if(skill1num > 0) {
skill1num--; s1lable.Text = skill1num.ToString(); textBox1.Text = " news : great "+Name
+" your excellency , You used fire dance whirlwind !"; Music("Music\\skill.wav"); Random myRand = new Random(DateTime.
Now.Second);// Select a color at random int x = myRand.Next(1, 7); for (int i = 1; i <= height; i
++)// Search all boxes , If it is the selected color, it is eliminated for (int j = 1; j <= width; j++) { if ((int)getmap[i, j].
Color== x) getmap[i, j].Color = starcolor. nothing ; } timer3.Enabled = true;
pictureBox4.Invalidate(); } else { timer1.Enabled = false; timelable .Text =
" suspend "; MessageBox.Show(" Sao Nian , You don't have enough magic , No, how does krypton get stronger , Try your money skills ", " Use failed ", MessageBoxButtons.OK
, MessageBoxIcon.Warning); timer1.Enabled = true; } } } private void
pictureBox2_Click(object sender, EventArgs e)// skill 2 Wanren floating release { if (gamestart == 1 &&
gamestop== 0) { if (skill2num > 0) { timer1.Enabled = false; skill2num--;
s2lable.Text = skill2num.ToString(); textBox1.Text = " news : great " + Name +
" your excellency , You used the floating life of all things !"; Music("Music\\skill.wav"); GetMap(); // Refresh map timer3.Enabled =
true; timer1.Enabled = true; pictureBox4.Invalidate(); } else { timer1.Enabled =
false; timelable.Text = " suspend "; MessageBox.Show(" Sao Nian , You don't have enough magic , No, how does krypton get stronger , Try your money skills ",
" Use failed ", MessageBoxButtons.OK, MessageBoxIcon.Warning); timer1.Enabled = true; }
} } private void pictureBox3_Click(object sender, EventArgs e)// skill 3 Time controlled release { if (
gamestart== 1 && gamestop == 0) { if (skill3num > 0) { skill3num--; s3lable.Text
= skill3num.ToString(); time += 10; // Time increase timelable.Text = time.ToString() +
"s"; // Update label textBox1.Text =" news : great " + Name + " your excellency , You used time control !"; Music(
"Music\\skill.wav"); } else { timer1.Enabled = false; timelable.Text = " suspend ";
MessageBox.Show(" Sao Nian , You don't have enough magic , No, how does krypton get stronger , Try your money skills ", " Use failed ", 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)// Record time { if(time == 0) { gamestart = 0; timer1.Enabled = false;
MessageBox.Show(" game over !"); } timelable.Text = time.ToString() + "s"; time--; }
private void pictureBox4_MouseDown(object sender, MouseEventArgs e)// Mouse click { 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);// First click , Get the row and column of click position if (value == true) { if
(getmap[row, col].Color != starcolor. nothing ) { 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)
;// Second click , Get the row and column of click position if (value == true) { if (getmap[row, col].Color != starcolor.
nothing ) { if (row == pickRow && Math.Abs(col - pickCol) == 1 || col == pickCol &&
Math.Abs(row - pickRow) == 1)// Judge whether adjacent { 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. nothing ; getmap[dropRow, dropCol].Color =
starcolor. nothing ; 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
;// Perform exchange } else// Relabel { 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)
// exchange { 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;// The timer continues to work getmap[pickRow,
pickCol].Color = s2.Color; getmap[dropRow, dropCol].Color = s1.Color;// Exchange colors
pictureBox4.Invalidate(); if(changeFlag == 0) { if (!KillStar())// Determine whether it can be eliminated {
// Continue to exchange back 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. nothing ; getmap[dropRow, dropCol].Color = starcolor. nothing ; pictureBox4
.Invalidate(); timer1.Enabled = false; timer2.Enabled = true;// Re exchange getmap[
pickRow, pickCol].Select = 0; ispic = 0; changeFlag = 1;// This is a successful exchange } else {
timer3.Enabled = true;// Execute drop pickRow = 0; pickCol = 1; ispic = 0; } } } }
private void timer3_Tick(object sender, EventArgs e)// whereabouts { for (int j=1; j<=
width;j++) { for (int i = height; i >= 2; i--) { if (getmap[i, j].Color ==
starcolor. nothing ) { 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. nothing ) 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. nothing ) { 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)// Custom cursor { 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)// Draw map function { 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)// knapsack { } private void
pictureBox6_Click(object sender, EventArgs e)// Shopping Mall { Money m = new Money();
//m.Show(); if(m.ShowDialog()==DialogResult.OK) { this.money += m.Num;
moneylable.Text = money.ToString(); } } } }
3. Recharge , knapsack , Teaching interface
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(" Do you want to spend 20 Yuan purchase 200 Gold coins ?", " Recharge reminder ", MessageBoxButtons.OKCancel);
// if(reult ==DialogResult.OK) // { // num = 200; // MessageBox.Show(" Recharge succeeded !");
// } // 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(" Do you want to spend 20 Yuan purchase 200 Gold coins ?", " Recharge reminder ",
MessageBoxButtons.OKCancel); if (reult == DialogResult.OK) { num = 200;
MessageBox.Show(" Recharge succeeded !"); } else { this.Close(); } } } }
Time compact , Slightly rough , Welcome to point out the error !
Technology