在“垄断”中,当玩家登陆Chance或Community胸部时,会出现一张可能指示玩家前往不同位置的牌,在这种情况下,即使他掷出双倍牌,玩家轮到你了。我试图在我的代码中加入这个功能。 Here is a spreadsheet plan of my code.
问题在于我应该在什么级别checkDouble
。我想检查双打,如果玩家通过掷骰子落在那里,而不是当玩家被卡片移动时。
当玩家点击购买时,checkDouble
已经投放,changeTurn
已经投放,因此错误的玩家被分配到购买的房产。
我没有包含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();
};
答案 0 :(得分:0)
如果掷骰子时为rolledDoubles
设置了标记,则可以在pickcard
进入movement
后清除该标记。对于终端节点上的所有其他路径,检查标志rolledDoubles
,如果已设置,则调用一个新的'letPlayerKnowTheyCanRollAgain',调用rollDice
。
您的电子表格有助于可视化每个点的各种选择。我对大富翁的规则很生气。