use javascript for game2 slaying dragon

来源:互联网 发布:数据库系统的应用 编辑:程序博客网 时间:2024/06/06 01:54
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;    }    }


                                             
0 0
原创粉丝点击