80行代码轻松搞定基本翻牌游戏

  • 内容
  • 评论
  • 相关

刚完成的,吸取上次的教训,这次应该没什么BUG了吧...思路:先从库中复制mc到舞台上,然后随机打乱数组,三角交换,并且标示也要跟着变化,主要是打乱数组问题和标记问题困惑了我半天,其他的都还很容易的。大家觉得有用的帮我顶啊,谢谢大家...

游戏效果:http://www.68design.net/download/200712/20071229/20071228121121681.swf

代码如下:

/*作者:梦自在*/
/*mc的宽和高*/
var width_num:Number = 50;
var height_num:Number = 40;
/*空隙*/
var jiange_num:Number = 5;
var x0:Number = Stage.width/2-150;
var y0:Number = Stage.height/2-100;
var num_num:Number = 0;
var save_array:Array = new Array("A", "B", "C", "D", "E", "F", "G", "H");
/*初始化并打乱顺序*/
function init() {
var num:Number;
for (var i:Number = 0; i<=15; i++) { attachMovie("pic", "pic"+i, i); attachMovie("block", "block"+i, i+20); _root["pic"+i]._x = x0+Math.floor(i/4)*(width_num+jiange_num); _root["pic"+i]._y = y0+i%4*(height_num+jiange_num); _root["pic"+i].txt.text = save_array[Math.floor(num_num/2)]; num_num += 1; _root["block"+i]._x = x0+Math.floor(i/4)*(width_num+jiange_num); _root["block"+i]._y = y0+i%4*(height_num+jiange_num); } random_array_func(); } /*随机函数*/function random_array_func() { var count:Number = 0; /*三角交换并打乱100次*/while (count<=100) { var value1_num:Number = Math.floor(Math.random()*15); var value2_num:Number = Math.floor(Math.random()*15); if (value1_num != value2_num) { var xcin:Number; var ycin:Number; var block_xcin:Number; var block_ycin:Number; xcin = _root["pic"+value1_num]._x; _root["pic"+value1_num]._x = _root["pic"+value2_num]._x; _root["pic"+value2_num]._x = xcin; ycin = _root["pic"+value1_num]._y; _root["pic"+value1_num]._y = _root["pic"+value2_num]._y; _root["pic"+value2_num]._y = ycin; block_xcin = _root["block"+value1_num]._x; _root["block"+value1_num]._x = _root["block"+value2_num]._x; _root["block"+value2_num]._x = block_xcin; block_ycin = _root["block"+value1_num]._y; _root["block"+value1_num]._y = _root["block"+value2_num]._y; _root["block"+value2_num]._y = block_ycin; } else { var value1_num:Number = Math.floor(Math.random()*15); var value2_num:Number = Math.floor(Math.random()*15); } count++; } } function start_func() { var id_num:Number = 0; var save_txt:Number = 0; for (var i:Number = 0; i<=15; i++) { _root["pic"+i].i = i; _root["pic"+i].onRelease = function() { /*第一次开始选择时*/ if (id_num == 0) { _root["pic"+this.i].swapDepths(_root["block"+this.i]); save_txt = _root["pic"+this.i].txt.text; id_num += 1; } /*第二次开始选择时*/ else if (id_num == 1) { if (save_txt == _root["pic"+this.i].txt.text) { /*如果text一样则交换深度*/ _root["pic"+this.i].swapDepths(_root["block"+this.i]); id_num = 0; save_txt = 0; } } }; } } init(); start_func(); 源文件下载:pic.rar

评论

0条评论

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注

    click to change 看不清?点击换一张!