我正在制作一个简单的玩家对抗游戏,但由于某种原因,游戏无效。 ai没有运行,玩家可以继续将x放在游戏板上。当玩家“获胜”时,游戏不会结束或显示任何结束的迹象。
import flash.events.MouseEvent;
var BoardArray = new Array(TL, TC, TR, ML, MC, MR, BL, BC, BR)
var Humanturn:Boolean = true;
var Win:Boolean = false;
var Playerscore = 0;
var Computerscore = 0;
var Turns = 0;
for (var i = 0; i < BoardArray.length; i++)
{
BoardArray[i].stop();
BoardArray[i].buttonMode = true;
BoardArray[i].addEventListener(MouseEvent.CLICK, BoxClicked);
}
function BoxClicked(e:MouseEvent)
{
if (Win != true && Humanturn == true && e.target.currentFrame == 1)
{
e.target.gotoAndStop(2);
CheckWin();
Turns++;
if (Turns == 5)
{
Win = true;
gotoAndPlay(1, "Scene 4");
}
else
{
AIMove();
}
}
if (Win == true)
{
for (var j = 0; j < BoardArray.length; j++)
{
BoardArray[j].gotoAndStop(1);
}
Win = false;
Turns = 0;
}
}
function AIMove():void
{
var AIPosition = RndNum(8)
if (Win == false)
{
if (BoardArray[AIPosition].currentFrame == 1)
{
BoardArray[AIPosition].gotoAndStop(3);
CheckWin();
}
else
{
AIMove();
}
}
}
function CheckWin():void
{ // Check for Horizontal Win
if ( (TL.currentFrame == 2 && TC.currentFrame == 2 && TR.currentFrame == 2)
(ML.currentFrame == 2 && MC.currentFrame == 2 && MR.currentFrame == 2)
(BL.currentFrame == 2 && BC.currentFrame == 2 && BR.currentFrame == 2)
// Check for Vertical Win
(TL.currentFrame == 2 && ML.currentFrame == 2 && BL.currentFrame == 2)
(TC.currentFrame == 2 && MC.currentFrame == 2 && BC.currentFrame == 2)
(TR.currentFrame == 2 && MR.currentFrame == 2 && BR.currentFrame == 2)
// Check for Diagonal Win
(TL.currentFrame == 2 && MC.currentFrame == 2 && BR.currentFrame == 2)
(TR.currentFrame == 2 && MC.currentFrame == 2 && BL.currentFrame == 2) )
{
Playerscore++;
Player.text = "Player: " + Playerscore;
Win = true;
} // Check for AI Horizontal Win
else if ((TL.currentFrame == 3 && TC.currentFrame == 3 && TR.currentFrame == 3)
(ML.currentFrame == 3 && MC.currentFrame == 3 && MR.currentFrame == 3)
(BL.currentFrame == 3 && BC.currentFrame == 3 && BR.currentFrame == 3)
// Check for AI Vertical Win
(TL.currentFrame == 3 && ML.currentFrame == 3 && BL.currentFrame == 3)
(TC.currentFrame == 3 && MC.currentFrame == 3 && BC.currentFrame == 3)
(TR.currentFrame == 3 && MR.currentFrame == 3 && BR.currentFrame == 3)
// Check for AI Diagonal Win
(TL.currentFrame == 3 && MC.currentFrame == 3 && BR.currentFrame == 3)
(TR.currentFrame == 3 && MC.currentFrame == 3 && BL.currentFrame == 3) )
{
Computerscore++;
Computer.text = "Computer: " + Computerscore;
Win = true;
}
}
function RndNum(Numm):uint
{
return Math.round(Math.random() * Numm)
}
知道发生了什么事吗? 感谢
答案 0 :(得分:0)
您的获胜条件不佳,请尝试添加|| (或)条件之间。
例如:
if ( (TL.currentFrame == 2 && TC.currentFrame == 2 && TR.currentFrame == 2) ||
(ML.currentFrame == 2 && MC.currentFrame == 2 && MR.currentFrame == 2) ||
(BL.currentFrame == 2 && BC.currentFrame == 2 && BR.currentFrame == 2) ||
// Check for Vertical Win
(TL.currentFrame == 2 && ML.currentFrame == 2 && BL.currentFrame == 2) ||
(TC.currentFrame == 2 && MC.currentFrame == 2 && BC.currentFrame == 2) ||
(TR.currentFrame == 2 && MR.currentFrame == 2 && BR.currentFrame == 2) ||
// Check for Diagonal Win
(TL.currentFrame == 2 && MC.currentFrame == 2 && BR.currentFrame == 2) ||
(TR.currentFrame == 2 && MC.currentFrame == 2 && BL.currentFrame == 2) )
{
trace( 'playerwin' );
}
PS:尝试在单词的开头使用大写字母仅用于类名,并使用小写的开始字母表示变量。对每个人来说都更清楚;)(例如:MyClassName,myVarName)