我正在尝试制作一个小型的二十一点游戏。 我碰到了一个问题,蚂蚁我找不到我的错误。 如果您想在第一轮获得额外的卡,您将获得一张卡。 (您必须按一个按钮才能获得它),但在第二轮中,当您单击按钮时,该功能会触发两次,在第三轮中触发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();
}
有人知道解决方案吗?
谢谢!
答案 0 :(得分:1)
您没有包含必要的代码,但最有可能发生的是您每轮额外注册点击处理程序(最终调用extracard
函数)(这就是{{ 1}}'你得到n
额外卡片。
代码如下:
n
现在,如果您点击按钮3x,它将会调用button.addEventListener(MouseEvent.CLICK, extracard);
3x。
为确保不会发生这种情况,请尝试
之类的操作extracard