snake-process-diagram 蛇形snake流程图模板
- 格式:pptx
- 大小:88.02 KB
- 文档页数:2


c语⾔贪吃蛇详解3.让蛇动起来c语⾔贪吃蛇详解3.让蛇动起来前⼏天的实验室培训课后作业我布置了贪吃蛇,今天有时间就来写⼀下题解。
我将分⼏步来教⼤家写⼀个贪吃蛇⼩游戏。
由于⼤家c语⾔未学完,这个教程只涉及数组和函数等知识点。
上次我已经教⼤家画出蛇了,现在我就教⼤家让蛇动起来。
为了让⼤家更好理解,蛇的移动就⽤最简单的办法,这⾥就不⽤链表,顺序队列什么的了。
蛇的移动就是头往前移动,然后后⾯的⾝体移动到前⼀节⾝体原来的位置上。
就像这样: int i;for(i=sLength-1;i<1;i--) //从尾巴开始,每⼀个点的位置等于它前⾯⼀个点的位置{s[i][0]=s[i-1][0];s[i][1]=s[i-1][1];}那蛇头怎么办呢?为了确定蛇头的位置,我们定义⼀个变量原来存储蛇现在的⽅向。
int direction; //蛇的⽅向我们可以通过direction的值来标记现在蛇的⽅向。
⽐如0代表上,1代表下。
为了⽅便,我们定义⼀些常量//定义direction的每个值代表的⽅向#define UP 0#define DOWN 1#define LEFT 2#define RIGHT 3这样,我们就可以这样写switch(direction){case UP:s[0][0]--;break;case DOWN:s[0][0]++;break;case LEFT:s[0][1]--;break;case RIGHT:s[0][1]++;break;}写好的move函数如下void move(){int i;for(i=sLength-1;i>0;i--) //从尾巴开始,每⼀个点的位置等于它前⾯⼀个点的位置{s[i][0]=s[i-1][0];s[i][1]=s[i-1][1];}switch(direction){case UP:s[0][0]--;break;case DOWN:s[0][0]++;break;case LEFT:s[0][1]--;break;case RIGHT:s[0][1]++;break;}}然后move写好了,我们还要写个循环,这样就可以让蛇⼀直动了。
PROCESS宏模型图Model templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 1Conceptual DiagramStatistical DiagramConditional effect of X on Y = b1 + b3MModel templates for PROCESS for SPSS and SAS c ?2013-2016Andrew F.Hayes and The Guilford PressConceptual DiagramStatistical DiagramModel 1Multicategorical M with k categories(PROCESS v2.14 or later)Conditional effect of X on Y = b 1 + b k +1D 1 + + b 2k-1D 2k -1 ...Model templates for PROCESS for SPSS and SAS c ?2013-2016Andrew F.Hayes and The Guilford PressModel 1Multicategorical X with k categories(PROCESS v2.14 or later)Conceptual DiagramStatistical Diagramb 1 + b k +1M b k -1 + b 2k-1MConditional effect of X on Y =...{Model templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 2Conceptual DiagramStatistical DiagramConditional effect of X on Y = b1 + b4M + b5WModel templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 3Conceptual DiagramStatistical DiagramConditional effect of X on Y = b1 + b4M + b5W+ b7MWModel templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 4Conceptual DiagramStatistical DiagramIndirect effect of X on Y through M i = a i b iDirect effect of X on Y = c'Note: Model 4 allows up to 10 mediators operating in parallel.Model templates for PROCESS for SPSS and SAS c ?2013-2016Andrew F.Hayes and The Guilford PressConceptual DiagramStatistical DiagramRelative indirect effect of X on Y through M i = Relative direct effect of X on Y = Model 4Multicategorical X with k categories(PROCESS v2.15 or later)i Note: Model 4 allows up to 10 mediators operating in parallel.1 i...a k -1b ic'1 ...{c'k -1Model templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 5Conceptual DiagramStatistical DiagramIndirect effect of X on Y through M i = a i b iConditional direct effect of X on Y = c1'+ c3'W*Model 5 allows up to 10 mediators operating in parallelModel templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 6(2 mediators)Conceptual DiagramStatistical DiagramIndirect effect of X on Y through M i only = a i b iIndirect effect of X on Y through M1 and M2 in serial = a1d21 b2 Direct effect of X on Y = c' Note: Model 6 allows up to 4 mediators operating in serial.Model templates for PROCESS for SPSS and SASc?2013-2016Andrew F.Hayes and The Guilford PressModel 6(3 mediators)Conceptual DiagramStatistical DiagramIndirect effect of X on Y through M i only = a i b iIndirect effect of X on Y through M1 and M2 in serial = a1 d21 b2Indirect effect of X on Y through M1 and M3 in serial = a1d31 b3Indirect effect of X on Y through M2 and M3 in serial = a2d32 b3Indirect effect of X on Y through M1, M2, and M3 in serial = a1 d21 d32 b3 Direct effect of X on Y = c' Model templates for PROCESS for SPSS and SASc?2013-2016Andrew F.Hayes and The Guilford PressModel 6(4 mediators)Conceptual DiagramStatistical DiagramIndirect effect of X on Y through M i only = a i b iIndirect effect of X on Y through M1 and M2 in serial = a1 d21 b2Indirect effect of X on Y through M1 and M3 in serial = a1d31 b3Indirect effect of X on Y through M1 and M4 in serial = a1d41 b4Indirect effect of X on Y through M2 and M3 in serial = a2d32 b3Indirect effect of X on Y through M2 and M4 in serial = a2d42 b4Indirect effect of X on Y through M3 and M4 in serial = a3d43 b4Indirect effect of X on Y through M1, M2, and M3 in serial = a1 d21 d32 b3 Indirect effect of X on Y through M1, M2, and M4 in serial = a1 d21 d42 b4 Indirect effect of X on Y through M1, M3, and M4 in serial = a1 d31 d43 b4 Indirect effect of X on Y through M2, M3, and M4 in serial = a2 d32 d43 b4 Indirect effect of X on Y through M1, M2, M3, and M4 in serial = a1 d21 d32 d43 b4 Direct effect of X on Y = c'Model templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford PressModel 7Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a3i W)b i Direct effect of X on Y = c'Note: Model 7 allows up to 10 mediators operating in parallel.Model templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 8Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a3i W)b i Conditional direct effect of X on Y = c1'+ c3'WNote: Model 8 allows up to 10 mediators operating in parallel.Model templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 9Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a4i W + a5i Z) b i Direct effect of X on Y = c'*Model 9 allows up to 10 mediators operating in parallelModel templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford Press Model 10Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a4i W + a5i Z) b i Conditional direct effect of X on Y = c1'+ c4'W + c5'Z*Model 10 allows up to 10 mediators operating in parallelModel templates for PROCESS for SPSS and SASc?2013-2016Andrew F.Hayes and The Guilford PressModel 11Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a4i W + a5i Z + a7i WZ) b i Direct effect of X on Y = c' *Model 11 allows up to 10 mediators operating in parallelModel templates for PROCESS for SPSS and SASc?2013-2016Andrew F.Hayes and The Guilford PressModel 12Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a4i W + a5i Z + a7i WZ) b i Conditional direct effect of X on Y = c1'+ c4'W + c5'Z + c7'WZNote: Model 12 allows up to 10 mediators operating in parallel.Model templates for PROCESS for SPSS and SASc?2013-2016Andrew F.Hayes and The Guilford PressModel 13Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = (a1i + a4i W + a5i Z + a7i WZ) b i Conditional direct effect of X on Y = c1'+ c3'W*Model 13 allows up to 10 mediators operating in parallelModel templates for PROCESS for SPSS and SAS c?2013-2016Andrew F.Hayes and The Guilford PressModel 14Conceptual DiagramStatistical DiagramConditional indirect effect of X on Y through M i = a i (b1i + b3i V) Direct effect of X on Y = c' Note: Model 14 allows up to 10 mediators operating in parallel.。
1系统设计要求1.1需求分析本系统为一个用C#实现, 用类和GDI+完成一个贪吃蛇游戏软件,该系统的具体功能如下:(1).控制蛇的运动方向:用键盘上的↑.↓.←.→控制蛇的运动方向。
若在游戏中,蛇头碰墙或是自己的身体,则游戏结束。
(2).蛇吃食物:蛇每吃一个食物就增长一节,并且得分,加相应的分值,达到一定的分值游戏上升一个级别。
(3).游戏结束:如果在游戏过程中,蛇头碰墙或是碰到了自己的身体,则游戏结束。
速度:玩家可以自己选择游戏速度1.2界面要求+要求界面简洁美观,简单易用。
1.3设计环境本程序选择Visual Studio 2005作为实验环境。
2设计思路2.1系统分析(1). 明确贪吃蛇的游戏规则(2). 将panel控件设为游戏背景。
(3). 场地.贪吃蛇及食物都是在panel 控件的重绘中绘制。
绘制蛇身的好处是在贪吃蛇进行移动时,不需要重绘制背景。
(4).用Timer组件来实现贪吃蛇的移动,并且该组件的Interval属性来控制移动速度。
2.2概要设计2.根据设计思路,可以为系统设计,.四个类,一个豆类,一个块类,一个蛇类,和一个场地类。
豆(Bean)类的作用:是在特定的位置生成一个豆,豆要不断被吃掉,当豆被吃掉后,原豆消失,又在新的位置出现新的豆。
块(Block)类的作用:用来构成蛇,在蛇出现时,要把构成蛇的块一个个输出(显示),在蛇消失时,要把块消除掉。
蛇(Snack)类作用:组成蛇,如果蛇吃了豆就增长一块,蛇死亡后要消除块。
在蛇运行过程中,判断是否碰到自身,判断是否死亡。
场地(Floor)类作用:游戏的主场地,豆要在此范围出现,蛇要在此范围运行。
3系统功能模块图3.1功能模块图3.2程序流程图定义新块bb定义并实例化点P(vertex.X+25,vertex.Y+25)实例化blockList[count]定义i=0i<=count是否成立块添加到blockList中i=i+1HeadNumber=count3.3类的结构图4调试过程生成块和豆的调试过程:运行程序,在画布上随机生成块和豆,如果无法生成块和豆就应该检查其随机生成函数,调整其相关函数.运行程序,生成不同大小和颜色的豆和块.蛇类的调试过程:运行程序在画布上随机生成蛇,如果无法随机生成蛇应查看生成蛇的相关函数,如随机生成函数,如果蛇只增不减少应查看显示蛇的方法里的移出函数.更该相关的函数后运行函数,控制蛇的运行方向以及测试蛇类的各项功能.场地类的调试过程:运行程序,初始化场地,如果无法生成场地,检查显示场地的方法,然后运行程序,测试蛇类的各项功能.主游戏的调试过程:运行程序,如果"级别"菜单的级别无法生效,就应该检查属性的click事件,是否把级别控制添加到click事件中。
最近老有人问我那个俄罗斯方块游戏的代码,解释了半天,觉得麻烦,干脆再做一个更简单的小游戏,贪吃蛇,和俄罗斯方块是一样的思路,只不过游戏相对俄罗斯方块来说简单了很多,把这个小游戏给大伙讲一下,希望对一些C#的初学者有帮助。
游戏很简单,通过WASD或上下左右几个按键控制贪吃蛇的前进方向,这个估计全世界都知道,先看一下游戏运行效果吧其中黑色的事物,红色是贪吃蛇,由于考虑到越简单越好,就没有追求过多的美化和修饰看一下程序结构吧程序结构很简单,一个Form,两个ClassFormMain是程序主界面,里面就一个PictureBox控件Block类是“蛇块”类,我不知道怎么换个词来描述,这个类就是用于描述蛇身子一节一节的信息,从运行效果图上可以看到就是那一个一个小方块的信息,等价于俄罗斯方块里的砖块信息类Palette类就是主画布,是游戏的主要代码,和俄罗斯方块里的画布是一样的作用。
从结构上可以看出,整个工程很简单,应该还算比较好理解吧。
下一篇给大伙从头到尾的把整个工程重现一遍。
呵呵,如果是高手的话,请勿见笑,初学者的话大可以“拿来主义”一下。
上一篇我们简单介绍了一下程序结构,接下来我们从头到尾把整个游戏重现一下1.新建一个Windows 应用程序,起名Snake吧2.重命名Form1,改为FormMain。
这是我的个人偏好,不改也行。
3.从工具栏里拖放一个picturebox到FormMain上面,设置属性picturebox1的BorderStyle属性选择为FixedSingle,这样能显示边框FormMain的KeyPreview属性设定为True,这样整个窗体可以响应键盘按键事件,这个在俄罗斯方块那个里面讲过了设定完以后大概应该是整个样子需要补充一下的是,这里面form的大小和picturebox的大小是不用刻意设置的,因为我们程序里面会根据设定贪吃蛇的大小和贪吃蛇的活动空间自动变大变小的,所以大致是整个样子就行了。