【发布时间】:2016-04-04 21:19:36
【问题描述】:
我正在尝试制作一个小二十一点游戏。 我遇到了一个问题,我找不到我的错误。 当你在第一轮想要一张额外的牌时,你会得到一张牌。 (您必须按一个按钮才能获得它),但是在第二轮中,当您单击按钮时,该功能会触发两次,在第三轮中会触发3次,依此类推。 在两轮之间,我从屏幕上删除了所有内容。
这里是经常触发的函数:
function extracard() {
var cextra: int = drawcard(cardpos, 400, true);
trace("drew extra card");
if (cextra == 1) {
var valchooser3: _1or11 = new _1or11();
addChild(valchooser3);
valchooser3.one.addEventListener(MouseEvent.CLICK, choose3_1);
valchooser3.eleven.addEventListener(MouseEvent.CLICK, choose3_11);
valchooser3.x = 280;
valchooser3.y = 380;
//chipsandcardonscreen.push(valchooser3);
function choose3_1() {
valchooser3.one.removeEventListener(MouseEvent.CLICK, choose3_1);
removeChild(valchooser3);
}
function choose3_11() {
valchooser3.eleven.removeEventListener(MouseEvent.CLICK, choose3_11);
playerpoints += 10;
trace(playerpoints);
removeChild(valchooser3);
}
}
cardpos += 150;
playerpoints += cextra;
}
抽卡功能:
function drawcard(xpos: int, ypos: int, faceup: Boolean): int {
var rand: int = Math.floor(Math.random() * shoe.length);
var newcard: Karte = shoe[rand];
addChild(newcard);
trace("aktuelle Karte:" + getChildAt(numChildren - 1).name);
trace("draw:" + numChildren);
newcard.x = xpos;
newcard.y = ypos;
if (!faceup) {
toturn.push(newcard);
newcard.turncard();
}
shoe.splice(rand, 1);
return newcard.getcardval();
if (shoe.length <= 0) {
trace("shoe empty");
realshoe.gotoAndStop(2);
}
还有删除所有功能
function realreset() {
canBet = true;
while (numChildren != 0) {
removeChild(getChildAt(0));
}
startsinglegame();
}
有人知道解决办法吗?
谢谢!
【问题讨论】:
-
您没有显示相关代码。在您的代码中某处调用“extracard”。因未努力显示相关代码而被否决。
-
出于同样的原因,我投了反对票。
标签: actionscript-3 flash cc