亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Resetting the visibility of "startButtonGame" is the only problem; everything else works fine
P粉614840363
P粉614840363 2023-09-19 22:02:31
0
1
862

I am developing a blackjack game. So far, everything is working fine except this small detail. Basically, the start game button should only be visible before the game and after the game. I have no problem setting it to hidden, but when I finish a game it doesn't work.

function startGame() {
    startGameButton.style.visibility = "hidden";
    if (!player.playerName) {
        player.playerName = prompt("你叫什么名字?")
        player.chips = 100

        playerEl.textContent = "玩家:" + player.playerName;
    }

    if (cards.length < 2) {
        let bet = prompt('你想下注多少(籌碼:' + player.chips + ')')
        player.chips = player.chips - bet;
        chipsEl.textContent = "籌碼:" + player.chips;
    }

    let firstCard = randomCard();
    let secondCard = randomCard();
    cards = [firstCard, secondCard];
    let tableFirstCard = randomCard();
    let tableSecondCard = randomCard();
    tableCards = [tableFirstCard, tableSecondCard];
    let message = "";
    let hasBlackJack = false;
    let isAlive = true;

    sum = firstCard + secondCard;
    newCardButton.style.visibility = "visible";
    startGameButton.textContent = "新游戲";

    if (sum < 21) {
        message = "你想要抽一張新牌嗎?";
    } else if (sum === 21) {
        message = "你得到了21點(diǎn)!";
        newCardButton.style.visibility = "hidden";
        startGameButton.style.visibility = "visible";
        player.chips = player.chips + bet * 2
        hasBlackJack = true;
    } else {
        startGameButton.style.visibility = "visible";
        isAlive = false;
        message = "運(yùn)氣不好!你已經(jīng)離開(kāi)游戲了!";
    }

    messageEl.textContent = message;
    cardsEl.textContent = "牌:" + firstCard + " " + secondCard;
    tableCardsEl.textContent = "桌面牌:" + tableSecondCard + " " + tableSecondCard;
    sumEl.textContent = "總和:" + sum;
    console.log("21點(diǎn):" + hasBlackJack);
    console.log("存活:" + isAlive);
}

I even tried swapping the order to see if it made any difference, but all that happens is:

if (sum < 21) {
        message = "你想要抽一張新牌嗎?";
    } else if (sum === 21) {
        message = "你得到了21點(diǎn)!";
        newCardButton.style.visibility = "hidden";
        startGameButton.style.visibility = "visible";
        player.chips = player.chips + bet * 2
        hasBlackJack = true;
    } else {
        startGameButton.style.visibility = "visible";
        isAlive = false;
        message = "運(yùn)氣不好!你已經(jīng)離開(kāi)游戲了!";
    }

Everything in the if statement is happening except the visibility part.

If you need more context, please refer to the code link: https://github.com/pedrosilva410/blackjack-game

P粉614840363
P粉614840363

reply all(1)
P粉463840170

I've looked at the entire code on your Github, and the problem is that your startGame function is only called when the game first starts (which makes sense, obviously). It does nothing while the game is in progress.

Your instructions about making the "Start Game" button visible are correct, you just have them in the wrong place. Add them to your drawCard function as well.

function drawCard() {

    if (hasBlackJack == false || isAlive == true) {
        let newCard = randomCard();
        let newTableCard = randomCard();
        sum = sum + newCard

        if (sum < 21) {
            message = "你想要抽一張新牌嗎?";
        } else if (sum === 21) {
            message = "你得到了21點(diǎn)!";
            newCardButton.style.visibility = "hidden";
            startGameButton.style.visibility = "visible";
            hasBlackJack = true;
        } else {
            isAlive = false;
            message = "運(yùn)氣不好!你已經(jīng)出局了!";
            startGameButton.style.visibility = "visible";
            newCardButton.style.visibility = "hidden"
        }

        messageEl.textContent = message;
        cardsEl.textContent = cardsEl.textContent + " " + newCard;
        tableCardsEl.textContent = tableCardsEl.textContent + " " + newTableCard;
        sumEl.textContent = "總和: " + sum;
        console.log("黑杰克: " + hasBlackJack);
        console.log("還活著: " + isAlive);
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template