use javascript for game2 slaying dragon

use if while 判断语句,可以做到文字游戏的剧情。当涉及各种各样的游戏剧情会产生不一样的判定
从而使游戏的趣味ing大大增加。
<pre name="code" class="javascript">var slaying = true;
var youHit=Math.floor(Math.random()*2);
var damagethisround = Math.floor(Math.random()*5 + 1);
var totalDamage=0;
while(slaying)
{
    if(youHit=1)
    {
        console.log("you hit the dragon");
        totalDamage+=damagethisround;
        if(totalDamage >= 4)
        {
            console.log("you beat the dragon!");
            slaying=false}
            else
            {
                youHit=Math.floor(Math.random()*2);
                }
    }else
    {
        console.log("dragon defeat you");
        slaying=false;
    }

    
}



 

猜你喜欢

转载自blog.csdn.net/qq_26925867/article/details/52703803