欢迎来到天天文库
浏览记录
ID:20536526
大小:103.00 KB
页数:18页
时间:2018-10-13
《30902382_高谦一-贪吃蛇游戏设计》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、浙江大学城市学院 实验报告纸实验名称 实验一C#实现贪吃蛇游戏指导老师刘泓 成绩___________专业 自动化 班级0901 姓名高谦一 学号 30902382 usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceWindowsFormsApplication3{publicenumSnakeDirection{Up,Down,Left,Right}publicenumSnakeState{Normal=50,Fast=20,Low=100}publi
2、cenumFoodType{Normal,Fast,Slow,Long,Short,LENGTH}}SnakeusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Drawing;namespaceWindowsFormsApplication3{classSnake{publicSnake(PointheadLocation,intsnakeLength,SnakeDirectiondirection){bodiesLocation=newList();bodiesLo
3、cation.Add(headLocation);for(inti=0;i向前移动一格publicvoidRun(){//从蛇尾开始,前面身体的位置替代后面的身体位置for(inti=bodiesLocation.Count-1;i>=1;i--){bodiesLocation[i]=bodiesLocat
4、ion[i-1];}//头部向前走一步Pointhead=bodiesLocation[0];switch(direction){caseSnakeDirection.Up:head=newPoint(head.X,head.Y-1);break;caseSnakeDirection.Down:head=newPoint(head.X,head.Y+1);break;caseSnakeDirection.Left:head=newPoint(head.X-1,head.Y);break;caseSnakeDirection.Right:head=newPoint(head.X
5、+1,head.Y);break;}bodiesLocation[0]=head;//因为Point是Struct,是值类型,所以要赋值过来}///移动方向publicSnakeDirectionDirection{get{returndirection;}set{direction=value;}}///状态publicSnakeStateState{get{returnstate;}set{state=value;speed=(int)state;//改变蛇的速度}}///头部位
6、置publicPointHeadLocation{get{returnbodiesLocation[0];}}///蛇身体publicListBodiesLocation{get{returnbodiesLocation;}}///蛇的速度publicintSpeed{get{returnspeed;}set{speed=value;}}///移动方向privateSnakeDirectiondirection;///7、ry>状态privateSnakeStatestate;///蛇身体的位置privateListbodiesLocation;///蛇的速度privateintspeed=(int)SnakeState.Normal;}}FoodusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Drawing;nam
7、ry>状态privateSnakeStatestate;///蛇身体的位置privateListbodiesLocation;///蛇的速度privateintspeed=(int)SnakeState.Normal;}}FoodusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Drawing;nam
此文档下载收益归作者所有