1
在玩家着陸在機會或社區胸部的專賣中,可以指示玩家前往不同位置的牌,在這種情況下,玩家的回合結束即使他翻了兩倍。正是我試圖在我的代碼中加入這個特性。 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();
};
我的'rollDice'函數中已經有一個變量'isDouble',它會生成2個隨機骰子卷。 'checkDouble'稍後使用該變量來確定是否需要'changeTurn'。當玩家被卡移動時,我將該變量設置爲false。所以它將是checkPurchasable - > pickCard - >移動 - > checkPurchasble(但現在isDouble設置爲false。) - > checkDouble(因爲isDouble爲false,changeTurn運行)。 – Elton
'changeturn'是否有檢查確保所有用戶輸入已完成,或者您是否使用回調來防止在用戶用盡選項之前調用changeTurn?例如'showPurchaseCard'使用回調函數? –
不,它不。 'changeTurn'只需在1和0之間切換。我不知道回調是什麼,我必須閱讀。 'ShowPurchaseCard'也不使用回調函數。 – Elton