Javacript双骰子游戏 [英] Javacript double dice game

查看:90
本文介绍了Javacript双骰子游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅使用两个骰子就用javascript和html为两个玩家制作骰子游戏?

1.每个玩家每回合投掷两个骰子一次.仅当您掷双打时才得分(也就是说,两个骰子顶面上的斑点数相同).

2.玩家为双打,双打,四打或五打得到5分.双六获得25分,但是如果投双三则您的得分会回到零.
3.在演奏时添加您的乐谱.第一位获得五十分的玩家将赢得比赛. (成人或大一点的孩子可能需要帮助得分,但您可以使用此游戏教小孩子数到五.)

How to make a dice game for two player in javascript and html using just two dice?

1. Each player throws both dice once per turn. You only score if you throw doubles (that is, both dice have the same number of spots on their top face).

2. Players score five points for double ones, twos, fours or fives. A double six scores twenty five points, but if you throw a double three your score goes back to zero.
3. Add your score as you play. The first player to get fifty points wins the game. (An adult or older child may need to help score, but you can use this game to teach younger children to count by fives.)

推荐答案

开发软件的顺序,而不是专家意见的问题.我们不这样做.请帮个忙:自己开发这个游戏,只有在这种情况下才有意义.

如果您遇到某些特殊问题并能够正确解决,我们将很乐意为您提供帮助.

—SA
This looks more like am order for development of the software, not a question for expert advice. We don''t do it. Please do yourself a favor: develop this game all by yourself, only in this case it would have some sense.

If you face some particular problem and able to formulate it correctly, we will gladly help you.

—SA


好,所以我只使用过javascript几次,但我决定尝试为您提供帮助.我根据您在解决方案2中发布的代码创建了此代码.也许这会让您对可以做的事情有所了解.

注意:我进入了网页.

Ok so I have only used javascript a couple of times but I have decided to try and help you. I created this code based on the code you posted in solution 2. Maybe this will give you an idea of something you can do.

Note: I made it into a webpage.

<html>
<body>

<input type="button" value="Roll The Dice" onClick="rollDice()" />
<br />

<script type="text/javascript">
var score = 0;
var maxScore = 50;
var rolls = 0;
var maxRolls = 20;


function rollDice()
{
    var x = Math.floor( Math.random() * 6 ) + 1;
    var y = Math.floor( Math.random() * 6 ) + 1;

    if( x == y )
    {
        score = getScore( x );
        alert("You threw a Double " + x + " Your Score is "+ score);
    }
    else
    {
        alert("You threw a " + x + " and a " + y + " Your Score is " + score);
    }

    rolls++;

    if (rolls == maxRolls && score < maxScore)

    {

        alert("Sorry You Lose!");

        score = 0;

        rolls = 0;

        return;

    }

    else if (score >= maxScore)
    {
        alert("Congratulations You Win!");
        score = 0;
        rolls = 0;
        return;
    }
}

function getScore(x)
{
    switch( x )
    {
        case 1:
            score += 5;
            break;
        case 2:
            score += 5;
            break;
        case 3:
            score = 0;
            break;
        case 4:
            score += 5;
            break;
        case 5:
            score += 5;
            break;
        case 6:
            score += 25;
            break;
    }

    return score;
}
</script>
</body>
</html>


有人可以在while循环中编写此代码,该循环将一直运行,直到确定获胜者的得分为50时,或经过多次掷球而获得得分为50时,它停止为止.

请??????????????? !!!!!!!!!
Can someone please write this code in while loop that will run until a winner is determined when he gets the score of 50 or after so many throws when he gets a score 50 it stops.

Please????????????!!!!!!!!!


这篇关于Javacript双骰子游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆