怎么实现重新开始

问题描述

怎么在button里实现重新开始游戏,

解决方案

解决方案二:
先判断游戏是不是在运行中,如果是,就结束游戏(关闭游戏进程)再重新运行privatevoidGameRun_Click(objectsender,System.EventArgse){System.Diagnostics.Process.Start(@"d:\game.exe");}是不是这样情况
解决方案三:
直接用重启算了。
解决方案四:
这问的没有意义,这取决于你怎么设计的游戏流程
解决方案五:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Drawing.Drawing2D;namespacecaomin20140718dazi{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}Randomr=newRandom();intwrong=0;intright=0;floatrightRate=0;privatevoidForm1_Load(objectsender,EventArgse){WindowState=FormWindowState.Maximized;panel1.Width=this.Width-button1.Width-50;panel1.Height=this.Height*4/5;button1.Left=this.Width-button1.Width-30;button2.Left=button1.Left;button3.Left=button2.Left;}privatevoidtimer1_Tick(objectsender,EventArgse){foreach(Controlainthis.panel1.Controls){if(a.GetType().Name=="Label"){if(a.Tag.ToString().Contains("aa")){a.Top++;if(a.Top>this.panel1.Height){a.Dispose();wrong++;this.label4.Text=this.wrong.ToString();}}elseif(a.Tag.ToString()=="zidan"){a.Top-=7;foreach(Controldinthis.panel1.Controls){if(d.GetType().Name=="Label"&&d.Text==a.Text&&d.Tag.ToString()=="aab"){if(a.Top<=d.Bottom){a.Dispose();d.Dispose();right++;this.label2.Text=this.right.ToString();}}}}if((this.right+this.wrong)==0){}else{this.rightRate=this.right*100/(this.right+this.wrong);this.label6.Text=this.rightRate.ToString()+"%";}}}}privatevoidtimer2_Tick(objectsender,EventArgse){Labela=newLabel();a.AutoSize=true;a.Text=((char)r.Next(97,123)).ToString();a.Font=newFont("华文彩云",r.Next(15,40));a.ForeColor=Color.FromArgb(r.Next(0,256),r.Next(0,256),r.Next(0,256));a.Location=newPoint(r.Next(pictureBox1.Width/2,this.panel1.Width-a.Width),0);a.Tag="aa";this.panel1.Controls.Add(a);}privatevoidForm1_KeyPress(objectsender,KeyPressEventArgse){foreach(Controlainthis.panel1.Controls){if(a.GetType().Name=="Label"&&a.Tag.ToString()=="aa"){if(e.KeyChar.ToString()==a.Text){a.Tag+="b";Labelb=newLabel();b.Text=a.Text;b.Font=a.Font;b.ForeColor=a.ForeColor;b.BackColor=a.ForeColor;b.Location=newPoint(a.Left,this.panel1.Height-b.Height);b.Size=newSize(20,25);b.Tag="zidan";this.panel1.Controls.Add(b);GraphicsPathg=newGraphicsPath();g.AddEllipse(0,0,b.Width,b.Height);b.Region=newSystem.Drawing.Region(g);pictureBox1.Location=newPoint(a.Left-pictureBox1.Width/2+a.Width/2-10,panel1.Height-pictureBox1.Height);break;}}}}privatevoidbutton1_Click(objectsender,EventArgse){}privatevoidbutton2_Click(objectsender,EventArgse){}privatevoidbutton3_Click(objectsender,EventArgse){this.Close();}privatevoidbutton1_MouseClick(objectsender,MouseEventArgse){if(button1.Text=="开始游戏"){timer1.Start();timer2.Start();button1.Text="暂停游戏";}elseif(button1.Text=="暂停游戏"){timer1.Stop();timer2.Stop();button1.Text="开始游戏";}}}}求大神在button写下重新开始游戏,就是游戏在运行,把panel里面的label控件清除,还有label2,label4,label6里的数字清空,谢了
解决方案六:
//停止计时器timer1.Stop();timer2.Stop();//清空标签值label2.Text="";label4="";label6="";//清空panel1中的所有控件//panel1.Controls.Clear();//清空panel1中的所有Labelforeach(Controliteminpanel1.Controls.OfType<Label>()){panel1.Controls.Remove(item);}

时间: 2024-10-26 21:35:03