gpt4 book ai didi

javascript - 垄断 : check for double only if player lands naturally

转载 作者:行者123 更新时间:2023-11-28 08:30:49 27 4
gpt4 key购买 nike

在《大富翁》中,当玩家落在机会或社区宝箱上时,会抽出一张牌,可能会指示玩家前进到不同的位置,在这种情况下,即使玩家掷出双倍,该玩家的回合也结束了。我正在尝试将这个功能合并到我的代码中。 Here is a spreadsheet plan of my code.

问题是我应该将checkDouble放在什么级别。我想检查玩家是否通过掷骰子到达那里,而不是当玩家被纸牌移动时是否出现 double 。

当玩家点击购买时,checkDouble 已经运行,changeTurn 也已运行,因此错误的玩家被分配到购买的属性(property)。

我没有包含我的所有代码,即 455 行代码。我希望我提供了足够的代码。

function gameEngine(){
clearContent();
rollDice();
drawDice(dice1, dice2);
processDice();
updatePos();
movePiece();
checkPurchasable();
checkDouble();// this is a problem, because by the time the player clicks the buy button, checkDouble has run and hence changeTurn.
}

function checkPurchasable(){
if (getPurchasable()) {
checkForsale();
} else {
nonPurchasable();
}
}

function checkForsale() {
if (getOwner() == "unowned") {
toggleButtons();
if ($(".action-card").is(":visible")) {
$(".action-card").delay(1000).fadeOut('slow', function() {
$(".deed-card").toggle();
});
} else {
$(".deed-card").toggle();
}

switch (true) {
case (getType() == "city"):
showDeedCard();
break;
case (getType() == "airport"):
showAirportCard();
break;
case (getType() == "utility"):
showUtilityCard();
break;
}
} else {
payRent();
}
}

function nonPurchasable() {
switch(true) {
case (getType() == "chest"):
drawCard(player, chest, "Community Chest");
break;
case (getType() == "tax"):
updateBalance(getTax()*-1,player);
break;
case (getType() == "chance"):
drawCard(player, chance, "Chance");
break;
case (getType() == "corner"):
break;
}
}

function Buy() {
$(".deed-card").slideToggle();
toggleButtons();
assignOwner();
updateBalance(getPrice()*-1,player);
var x = getTitle();
var xx = x.substring(0,3);
var res = xx.toUpperCase();
if (getType() != "city") {
$("#assets"+player).append('<span class="black">' + res + '</span>');
} else {
showPrice();
var set = positions[pos].set;
$("#assets"+player).append('<span class="' + set + '">' + res + '</span>');
}
}

function drawCard(player, deck, title) {
var card = deck.shift();
flipCard(card.instruction, title);
card.act(player);
deck.push(card);
}

function assignOwner() {
positions[pos].owner = player;
}

function changeTurn() {
player = 1 - player;
}

function checkDouble() {
if (isDouble) {
dblRolls++;
} else {
dblRolls = 0;
changeTurn();
}
}

function AbsMoveCard(instruction, destination) {
this.instruction = instruction;
this.destination = destination;
}

AbsMoveCard.prototype.act = function(player) {
pos = this.destination;
if (pos == 0 || pos<players[player].pos) {
updateBalance(200, player);
}
isDouble = false;
updatePos();
movePiece();
checkPurchasable();
};

function RelMoveCard(instruction, distance) {
this.instruction = instruction;
this.distance = distance;
}

RelMoveCard.prototype.act = function(player) {
alert("Moving relative.");
pos -= this.distance;
isDouble = false;
updatePos();
movePiece();
checkPurchasable();
};

最佳答案

如果掷骰子时您为 rolledDoubles 设置了一个标志,那么当您跟随 pickcard 进入移动时,您可以清除该标志。对于终端节点处的所有其他路径,请检查标志 rolledDoubles,如果设置了该标志,则调用新的“letPlayerKnow TheyCanRollAgain”,该标志将调用 rollDice

您的电子表格有助于可视化每个点的各种选择。我对《大富翁》的规则感到生疏。

关于javascript - 垄断 : check for double only if player lands naturally,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21886446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com