简单分析一个猜拳的小游戏 |
| 作者:佚名 来源:闪吧 作者: 龙族酷少 更新:2007-1-13 20:43:31 错误报告 我要投稿 |
前几天在别的论坛看到了这个猜拳小游戏,觉得蛮好玩,关键是比较好理解,
点击浏览该文件
今天有时间来对这个游戏分析一下,和大家共享。其实原理很简单,我们小时侯 可能都玩过这样的游戏,剪刀遇到锤子的时候,锤子获胜,剪刀遇到布的时候,剪刀获胜…… 现在把主要代码写出来,并做注释,希望对大家有所帮助 第一桢代码:
pla = 0; com = 0; totalplay = 0; //以上是初始化变量
第五桢代码:
if (pla>com) {//当玩家获胜次数多于电脑的时候,跳到第六桢,下面两句解释类似 gotoAndStop(6); } else if (pla<com) { gotoAndStop(7); } if (pla == com) { gotoAndStop(8); }
下面是按钮上的代码:
on (press) {//当按下的时候 totalplay = totalplay+1;//总数加1 if (totalplay == 30) {//当总数等于30的时候跳转到第五桢 gotoAndStop(5); } else if (totalplay<30) {//当小于30的时候 a = random(3)+2;//得到一个随机数 if (a == 4) { com = com+1;//当电脑获胜的时候,电脑获胜次数加1 } if (a == 3) { pla = pla+1;//当玩家获胜的时候,玩家获胜次数加1 //上面这些就是游戏规则,当剪刀遇到锤子的时候,锤子获胜,也就是电脑获胜 } _root.computer.gotoAndStop(a);//电脑那一边显示 _root.player.gotoAndStop(2);//玩家这一边显示你出的内容 } } } 其他两个按钮上的代码和上面的解释类似,大家看看就会明白 on (press) { totalplay = totalplay+1; if (totalplay == 30) { gotoAndStop(5); } else { a = random(3)+2; if (a == 2) { com = com+1; } if (a == 4) { pla = pla+1; } _root.computer.gotoAndStop(a); _root.player.gotoAndStop(3); } }
on (press) { totalplay = totalplay+1; if (totalplay == 30) { gotoAndStop(5); } else { a = random(3)+2; if (a == 3) { com = com+1; } if (a == 2) { pla = pla+1; } _root.computer.gotoAndStop(a); _root.player.gotoAndStop(4); } }
//其余的就是很简单的按钮控制,我就不必说了,只要懂一点AS就明白 ^_^
点击浏览该文件
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |