游戏界面: 游戏规则: 1、玩家通过掷筛子掷出的点数大小来控制主角在地图中前进的步数,当玩家到达终点则游戏结束。
2、你将与两家聪明的电脑玩家同场竞技。(ai设定)
3、玩家点击右下角两个筛子掷筛,停止后可选择任意一个筛子的大小值作为角色前进的步数。
4、电脑和玩家轮流掷筛,轮到任意一方时将会有闪烁提示。并能够体现电脑的操作过程。
5、地图内设各种事件格,如:前进,后退,暂停等,将对棋子前进造成2次变化。(不会存在2次以上的变化)
6、如果两个棋子走到同1格停止,则后来的将会把原来的弹回出发点。
7、地图中设定练习格,当玩家的棋子走到该格子时将要完成练习题方能继续,该格的练习同时也消失,做对给10分,错误扣10分。(玩家的基础分为100分,同一次格内的练习只能做1次)
游戏分数: 玩家试题得分=(100+正确试题个数*10-错误试题个数*10)
玩家时间得分=int(100/到达终点分钟数)
最终分数=(玩家试题得分+玩家时间得分)*名次系数
第1名名次系数:1.5
第2名名次系数:1.2
第3名名次系数:1.0
游戏开发模块: 1、角色与筛子控制模块程序
2、电脑AI模块
3、地图生成模块
4、试题练习模块
5、评价模块
游戏主要代码: 这里我固定了c1表示玩家,c2,c3表示电脑
1.建立地图格子,为避免出现死循环,按照一定的顺序和规则进行.
function createmap() { //初始化格子信息 for (var i = 1; i<=titleMaxnum; i++) { eval("t"+i).types = 1; } //生成前进和后退格,从第4格开始,每隔4格随机产生一个 for (var i = 4; i<=titleMaxnum; i += 4) { var trnd = int(Math.random()*5)+1; eval("t"+i).gotoAndStop(trnd); eval("t"+i).types = trnd; } //生成暂停格 trace(getEmptyTitle().length); var pausenum = 8; var t_array = getEmptyTitle(); var pause_d = int(t_array.length/pausenum); for (var i = pause_d-1; i<=t_array.length-1; i += pause_d) { t_array[i].gotoAndStop(6); t_array[i].types = 6; } //生成返回起点格 trace(getEmptyTitle().length); var backnum = 3; var t_array = getEmptyTitle(); var pause_d = int(t_array.length/backnum); for (var i = pause_d-1; i<=t_array.length-1; i += pause_d) { t_array[i].gotoAndStop(8); t_array[i].types = 8; } //生成时空隧道格 trace(getEmptyTitle().length); var spacenum = 6; var t_array = getEmptyTitle(); var pause_d = int(t_array.length/spacenum); for (var i = pause_d-1; i<=t_array.length-1; i += pause_d) { t_array[i].gotoAndStop(7); t_array[i].types = 7; } //生成练习格 var testnum = 10; var t_array = getEmptyTitle(); var pause_d = int(t_array.length/testnum); for (var i = pause_d-1; i<=t_array.length-1; i += pause_d) { t_array[i].gotoAndStop(9); t_array[i].types = 9; } } 2.获取空格信息,并返回数组 function getEmptyTitle() { var t_array = []; for (var i = 1; i<=titleMaxnum; i++) { if (eval("t"+i).types == 1) { t_array.push(eval("t"+i)); } } return t_array; }
3.控制筛子,随机扔,b1和b2为两个mc,里面共6帧
function throwPoint() { trace("事件:玩家"+curplayer+"出筛子"); curflag = false; b1.play(); b2.play(); throwid = setInterval(function () { var b1_num = int(Math.random()*6)+1; var b2_num = int(Math.random()*6)+1; b1.gotoAndStop(b1_num); b2.gotoAndStop(b2_num); b1.values = b1_num; b2.values = b2_num; trace("第1个筛子的大小为:"+b1.values); trace("第2个筛子的大小为:"+b2.values); //throw_btn._visible = 1; curflag = true; //电脑执行移动 if (curplayer<>1) { comai(); } clearInterval(throwid); }, 2000); }
4.玩家轮流制控制
function nextplayer() { if (c1.overflag) { trace("游戏结束"); return; } //下一个玩家执行 if (curplayer == 3) { curplayer = 1; if (!this["c"+curplayer].overflag) { if (!this["c"+curplayer].stopflag) { flashcast(this["c"+curplayer], true); throw_btn._visible = 1; } else { this["c"+curplayer].stopflag = false; nextplayer(); } } else { nextplayer(); } } else { curplayer++; if (!this["c"+curplayer].overflag) { if (!this["c"+curplayer].stopflag) { flashcast(this["c"+curplayer], true); throwPoint(); } else { this["c"+curplayer].stopflag = false; nextplayer(); } } else { nextplayer(); } } }
Flash动画:
pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'
type='application/x-shockwave-flash' width=550 height=400>
《历史飞行棋》移动控制上采用了纯AS运算移动,另外本游戏采用了双筛子和随机地图,所以需要进行电脑选择筛子的判断,这里选择最优化的筛子进行移动就是电脑AI的所在. 5.控制棋子移动 使用了setInterval来控制时间,这里将每个title按顺序命名:t1,t2...... 参数_who表示要移动的mc,如:c1,c2,c3,_step表示要移动的步数,该函数支持步数为负,即退.
function movecast(_who, _step) { trace("事件:移动"+_step); flashcast(_who, false); var dpos = _who.pos+_step; var dr = true; if (_step<0) { dr = false; } clearInterval(moveid); moveid = setInterval(function () { if (dr) { if (_who.pos<dpos) { if (_who.pos<=titleMaxnum) { _who.pos += 1; if (_who.pos == titleMaxnum+1) { _who._x = _who.x00; _who._y = _who.y00; //执行后退 if (_who.pos-dpos<>0) { movecast(_who, _who.pos-dpos); } else { _who.overflag = true; trace("事件:"+_who+"胜利!"); } } else { _who._x = eval("t"+_who.pos)._x+18; _who._y = eval("t"+_who.pos)._y+11; } } } else { exeevent(_who); clearInterval(moveid); } } else { if (_who.pos>dpos) { _who.pos -= 1; _who._x = eval("t"+_who.pos)._x+18; _who._y = eval("t"+_who.pos)._y+11; } else { exeevent(_who); clearInterval(moveid); } } }, 500); }
6、AI设定,电脑的AI是人思维的体现,一个完善的AI应该是一个系统,应该是很多人智慧的结晶! 这不仅仅需要良好的程序结构,更需要总结人的操作过程。这里仅总结一下个人对AI的理解。 我常把电脑的智能操作分成几个等级,这样才能提高游戏的娱乐性,电脑什么都想到了游戏的价值就没有了, 何况人也有操作和分析失误的时候。 本游戏我将AI分为三个等级: AI-1:这是一种随机的操作,从两个数中任意选择一个数。
//简单随机 var rnd = int(Math.random()*2)+1; curstep = this["b"+rnd].values; movecast(this["c"+curplayer], curstep);
AI-2:只简单的做一次判断,是否目的地是友好的。
if (b1.values<>b2.values) { var maxnum; var minnum; if (b1.values>b2.values) { maxnum = b1; minnum = b2; } else { maxnum = b2; minnum = b1; } trace("tt"+maxnum.values); var good_array = [1, 4, 5, 7, 9]; for (var i = 0; i<good_array.length; i++) { if (this["t"+this["c"+curplayer].pos+maxnum.values].types == good_array[i]) { curstep = maxnum.values; movecast(this["c"+curplayer], curstep); return; } } for (var i = 0; i<good_array.length; i++) { if (this["t"+this["c"+curplayer].pos+minnum.values].types == good_array[i]) { curstep = minnum.values; movecast(this["c"+curplayer], curstep); return; } } curstep = maxnum.values; movecast(this["c"+curplayer], curstep); } else { curstep = b1.values; movecast(this["c"+curplayer], curstep); }
AI-3:比较完善的分析,分别计算出选择每一个筛子后走出的最终效果得分,最后选择效果分高执行。
//ai2 对两个筛子的最后结果大小进行比较 /*2:-1 ,3:-3,4:+1,5:+3,6:-5,7:+n,8:-n,碰撞其他人得分*/ //基础分等于2个筛子的大小 可以提炼成为一个函数,根据who,_step就可以得出最终效果分数 var score1 = b1.values; var score2 = b2.values; //对b1进行判断最终得分 var pos0 = this["c"+curplayer].pos+b1.values; if (pos0<>titleMaxnum+1) { if (pos0>titleMaxnum+1) { var p0 = (titleMaxnum+1)-this["c"+curplayer].pos; pos0 = (titleMaxnum+1)-(b1.values-p0); delete p0; } //是否存在对手 score1 += checkhit_pos(pos0); //退1 if (this["t"+pos0].types == 2) { score1 -= 1; score1 += checkhit_pos(pos0-1); if (this["t"+(pos0-1)].types == 6) { score1 -= 5; } else if (this["t"+(pos0-1)].types == 7) { score1 += checksd_pos(pos0-1); } else if (this["t"+(pos0-1)].types == 8) { score1 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 3) { score1 -= 3; score1 += checkhit_pos(pos0-3); if (this["t"+(pos0-3)].types == 6) { score1 -= 5; } else if (this["t"+(pos0-3)].types == 7) { score1 += checksd_pos(pos0-3); } else if (this["t"+(pos0-3)].types == 8) { score1 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 4) { score1 += 1; score1 += checkhit_pos(pos0+1); if (this["t"+(pos0+1)].types == 6) { score1 -= 5; } else if (this["t"+(pos0+1)].types == 7) { score1 += checksd_pos(pos0+1); } else if (this["t"+(pos0+1)].types == 8) { score1 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 5) { score1 += 3; score1 += checkhit_pos(pos0+3); if (this["t"+(pos0+3)].types == 6) { score1 -= 5; } else if (this["t"+(pos0+3)].types == 7) { score1 += checksd_pos(pos0+3); } else if (this["t"+(pos0+3)].types == 8) { score1 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 6) { score1 -= 5; } else if (this["t"+pos0].types == 7) { score1 += checksd_pos(pos0); } else if (this["t"+pos0].types == 8) { score1 -= this["c"+curplayer].pos; } } else { //表示达到终点 score1 += 10000; } //对b2进行判断最终得分 var pos0 = this["c"+curplayer].pos+b2.values; if (pos0<>titleMaxnum+1) { if (pos0>titleMaxnum+1) { var p0 = (titleMaxnum+1)-this["c"+curplayer].pos; pos0 = (titleMaxnum+1)-(b2.values-p0); delete p0; } //是否存在对手 score2 += checkhit_pos(pos0); //退1 if (this["t"+pos0].types == 2) { score2 -= 1; score2 += checkhit_pos(pos0-1); if (this["t"+(pos0-1)].types == 6) { score2 -= 5; } else if (this["t"+(pos0-1)].types == 7) { score2 += checksd_pos(pos0-1); } else if (this["t"+(pos0-1)].types == 8) { score2 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 3) { score2 -= 3; score2 += checkhit_pos(pos0-3); if (this["t"+(pos0-3)].types == 6) { score2 -= 5; } else if (this["t"+(pos0-3)].types == 7) { score2 += checksd_pos(pos0-3); } else if (this["t"+(pos0-3)].types == 8) { score2 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 4) { score2 += 1; score2 += checkhit_pos(pos0+1); if (this["t"+(pos0+1)].types == 6) { score2 -= 5; } else if (this["t"+(pos0+1)].types == 7) { score2 += checksd_pos(pos0+1); } else if (this["t"+(pos0+1)].types == 8) { score2 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 5) { score2 += 3; score2 += checkhit_pos(pos0+3); if (this["t"+(pos0+3)].types == 6) { score2 -= 5; } else if (this["t"+(pos0+3)].types == 7) { score2 += checksd_pos(pos0+3); } else if (this["t"+(pos0+3)].types == 8) { score2 -= this["c"+curplayer].pos; } } else if (this["t"+pos0].types == 6) { score2 -= 5; } else if (this["t"+pos0].types == 7) { score2 += checksd_pos(pos0); } else if (this["t"+pos0].types == 8) { score2 -= this["c"+curplayer].pos; } } else { //表示达到终点 score2 += 10000; } //判断分数大小,并决定采用那个筛子 trace("______________利用ai-2结果如下_______________"); trace("第1个筛子的效果分:"+score1); trace("第2个筛子的效果分:"+score2); if (score1>=score2) { trace("采用第1个筛子进行命令"); trace("______________利用ai-2结果如上_______________"); curstep = b1.values; movecast(this["c"+curplayer], curstep); } else { trace("采用第2个筛子进行命令"); trace("______________利用ai-2结果如上_______________"); curstep = b2.values; movecast(this["c"+curplayer], curstep); }