




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceSnakepublicpartialclassForm1:FormpublicForm1()InitializeComponent();IntPtrptr;Snakesnake;观察哨boolObservation=true;/开始游戏privatevoidbutton1_Cli
2、ck(objectsender,EventArgse)Start();/暂停游戏privatevoidbutton2_Click(objectsender,EventArgse)Suspension();/wasd方向控制protectedoverrideboolProcessDialogChar(charcharCode)switch(charCode)case'w':if(snake.Direction!=1)snake.Direction=3;break;case's':if(snake.Direction!=3)snake.Direction=1;bre
3、ak;case'a':if(snake.Direction!=0)snake.Direction=2;break;case'd':if(snake.Direction!=2)snake.Direction=0;break;returnfalse;/时钟控制移动privatevoidtimer1_Tick(objectsender,EventArgse)/产生食物snake.MakeFood();/吃食物snake.EatFood();snake.rule();/加分if(snake.boolfood=false)this.textFen.Text=(int.Pa
4、rse(this.textFen.Text)+1).ToString();/移动if(snake.State=true)snake.Move();elsesnake.Over();this.timer1.Stop();intfen=int.Parse(this.textFen.Text)-3;this.labelDeFen.Text=fen.ToString();this.labelDengJi.Text=this.textJi.Text;this.groupBox1.Visible=true;this.button1.Enabled=true;this.button2.Enabled=fal
5、se;boBoxDengJi.Enabled=true;/udlr方向控制protectedoverrideboolProcessDialogKey(KeyskeyData)switch(keyData)caseKeys.Down:if(snake.Direction!=3)snake.Direction=1;break;caseKeys.Up:if(snake.Direction!=1)snake.Direction=3;break;caseKeys.Left:if(snake.Direction!=0)snake.Direction=2;break;caseKeys.Right:if(sn
6、ake.Direction!=2)snake.Direction=0;break;returnfalse;/开始游戏voidStart()this.groupBox1.Visible=false;if(Observation=false)Speed(boBoxDengJi.Text);timer1.Start();this.button1.Enabled=false;this.button2.Enabled=true;boBoxDengJi.Enabled=false;elseSpeed(boBoxDengJi.Text);ptr=this.pictureBox1.Handle;snake=n
7、ewSnake(ptr);snake.Draw();timer1.Start();this.button1.Enabled=false;this.button2.Enabled=true;boBoxDengJi.Enabled=false;/暂停游戏voidSuspension()this.timer1.Stop();this.button1.Enabled=true;boBoxDengJi.Enabled=true;Observation=false;/设定速度voidSpeed(stringchr)switch(chr)case"1":this.timer1.Inter
8、val=500;break;case"2":this.timer1.Interval=400;break;case"3":this.timer1.Interval=300;break;case"4":this.timer1.Interval=250;break;case"5":this.timer1.Interval=200;break;case"6":this.timer1.Interval=150;break;case"7":this.timer1.Interval=10
9、0;break;case"8":this.timer1.Interval=75;break;case"9":this.timer1.Interval=65;break;case"10":this.timer1.Interval=50;break;usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceSnakepublicclassSnakepublicList<Square>list=newList<Square>();IntPtrptr;/食物变量publicboolboolfood=false;Randomran=newRandom();Squarefood=null;intdirection=0;/0:右1:下2:左3:上publicintDirection
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 网络技术升级服务支持协议
- 公司年度庆典仪式
- 教育培训行业师资力量保证合同协议
- 高二语文写作教学:新闻写作
- 通知申请书模板
- 建筑行业施工安全责任及免责条款协议
- 金融租赁业务合作协议
- 独家销售代理权转让协议
- 公司合作协议书版
- 三农行业标准化生产操作手册
- 雨污水工程施工组织设计方案
- sinamic变频器家族cu250s-操作手册
- 建筑垃圾回收利用统计台账
- 《不一样的你我他》(完美)课件
- 新苏教版科学六年级下册全册教案(含反思)
- 原油电脱盐电脱水技术
- 国考断面水站建设及运维技术要求参考
- Q∕GDW 10799.7-2020 国家电网有限公司电力安全工作规程 第7部分:调相机部分
- 热工学后题答案
- 不吸烟不喝酒课件
- 奥数知识点 间隔问题
评论
0/150
提交评论