c#贪吃蛇源码_第1页
c#贪吃蛇源码_第2页
c#贪吃蛇源码_第3页
c#贪吃蛇源码_第4页
c#贪吃蛇源码_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论