你好。flash as3.0小游戏,要源代码,类似于连连看,打砖块之类的。能发我吗? 5
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
1个回答
展开全部
2048的源码!!
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.text.*;
import flash.geom.Point;
public class GameMain extends Sprite
{
private var i:int = 0;
private var j:int = 0;
private var k:int = 0;
private var tf:TextFormat = new TextFormat();
private var ContainTxt:Sprite = new Sprite();
private var arrTxt:Array = new Array();
private var arrTxtColor:Array = new Array();
private var arrTxtValue:Array = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
private var arrTemp:Array = new Array(5);
private var arrValue:Array = [0, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, GameMain, 4096];
private var arrColor:Array = [0xffffff, 0x999999, 0xff6666, 0xffcc66, 0xff9900, 0xff6600, 0xff3300, 0xff0000, 0xffff66, 0x99ff33, 0x66ff00, 0xff00ff];
private var B_change:Boolean = false;
private var dotest:int = 0;
private var score:int = 0;
public function GameMain():void
{
Depth(); //深度管理
new_Game(); //初始化
TF1();
}
private function new_Game():void
{
stage.addEventListener(Event.ENTER_FRAME, ValueToTxt);
Create_one();
Create_one();
stage.addEventListener(KeyboardEvent.KEY_DOWN, KEYDOWN);
}
private function KEYDOWN(ekey:KeyboardEvent):void
{
switch (ekey.keyCode)
{
case 37:
for (j = 0; j <= 3; j++)
{
for (i = 0; i <= 3; i++)
{
arrTemp[i] = arrTxtValue[i][j];
}
arrTemp[4] = 0;
doMove();
for (i = 0; i <= 3; i++)
{
arrTxtValue[i][j] = arrTemp[i];
}
}
break;
case 38:
for (k = 0; k <= 3; k++)
{
for (j = 0; j <= 3; j++)
{
arrTemp[j] = arrTxtValue[k][j];
}
arrTemp[4] = 0;
doMove();
for (j = 0; j <= 3; j++)
{
arrTxtValue[k][j] = arrTemp[j];
}
}
break;
case 39:
for (j = 0; j <= 3; j++)
{
for (i = 0; i <= 3; i++)
{
arrTemp[i] = arrTxtValue[3 - i][j];
}
arrTemp[4] = 0;
doMove();
for (i = 0; i <= 3; i++)
{
arrTxtValue[3 - i][j] = arrTemp[i];
}
}
break;
case 40:
for (k = 0; k <= 3; k++)
{
for (j = 0; j <= 3; j++)
{
arrTemp[j] = arrTxtValue[k][3 - j];
}
arrTemp[4] = 0;
doMove();
for (j = 0; j <= 3; j++)
{
arrTxtValue[k][3 - j] = arrTemp[j];
}
}
break;
default:
break;
}
}
private function doMove():void
{
var temp:int = 0;
score++;
//02
do
{
for (i = 0; i <= 3; i++)
{
if (arrTemp[i] == 0)
{
if (arrTemp[i] != arrTemp[i + 1])
{
arrTemp[i] = arrTemp[i + 1];
arrTemp[i + 1] = 0;
B_change = true;
}
}
}
temp++;
} while (temp <= 3);
//22
do
{
for (i = 1; i < 4; i++)
{
if (arrTemp[i] == arrTemp[i - 1])
{
if (arrTemp[i] != 0)
{
arrTemp[i - 1] = arrTemp[i] * 2;
arrTemp[i] = 0;
B_change = true;
}
}
}
temp++;
} while (temp <= 3);
//00
do
{
for (i = 0; i < 4; i++)
{
if (arrTemp[i] == 0)
{
arrTemp[i] = arrTemp[i + 1];
arrTemp[i + 1] = 0;
}
}
temp++;
} while (temp <= 3);
//20 donothing
}
private function Create_one():void
{
do
{
i = Math.floor(Math.random() * 4);
j = Math.floor(Math.random() * 4);
} while (arrTxtValue[i][j] != 0);
if (Math.random() < 0.777)
{
arrTxtValue[i][j] = arrValue[1];
}
else
{
arrTxtValue[i][j] = arrValue[2];
}
}
private function ValueToTxt(e:Event):void
{
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
var n:int = arrValue.indexOf(arrTxtValue[i][j]);
arrTxtColor[i][j].backgroundColor = arrColor[n];
arrTxt[i][j].text = arrTxtValue[i][j];
arrTxt[i][j].setTextFormat(tf);
}
}
//
if (B_change)
{
Create_one();
B_change = false;
}
}
private function GameOver():void
{
stage.removeEventListener(Event.ENTER_FRAME, ValueToTxt);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, KEYDOWN);
}
private function TF1():void
{
tf.align = "center";
tf.bold = true;
tf.size = 35;
tf.font = "Arial";
tf.color = 0xFFFFFF;
}
private function Depth():void
{
addChild(ContainTxt); //文本框容器
var Frame:Sprite = FRAME();
addChild(Frame); //结构
FrameTxt(); //文本框
}
private function FrameTxt():void
{
for (i = 0; i < 4; i++)
{
arrTxt[i] = new Array();
arrTxtColor[i] = new Array();
for (j = 0; j < 4; j++)
{
var temptxt:TextField = new TextField();
var temptxtColor:TextField = new TextField();
temptxt.selectable = temptxtColor.selectable = false;
temptxt.x = i * 100;
temptxtColor.x = i * 100;
temptxt.y = j * 100 + 30;
temptxtColor.y = j * 100;
temptxtColor.width = temptxtColor.height = 100;
temptxtColor.background = true;
ContainTxt.addChild(temptxtColor);
ContainTxt.addChild(temptxt);
arrTxt[i][j] = temptxt;
arrTxtColor[i][j] = temptxtColor;
}
}
}
private function FRAME():Sprite
{
var tempframe:Sprite = new Sprite();
for (i = 0; i <= 4; i++)
{
tempframe.graphics.moveTo(i * 100, 0);
tempframe.graphics.lineStyle(8, 0xCCCCCC);
tempframe.graphics.lineTo(i * 100, 400);
}
for (j = 0; j <= 4; j++)
{
tempframe.graphics.moveTo(0, j * 100);
tempframe.graphics.lineStyle(8, 0xCCCCCC);
tempframe.graphics.lineTo(400, j * 100);
}
return tempframe;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询