为什么我不能从开关内的变量中减去?

布拉克斯顿·福克斯

在我开始之前,我想说对不起,我写得不太好,我对Java很陌生(这是我的第5天左右)。我试图从文本(将在控制台开发人员工具中使用)制作一个小的Web浏览器游戏,这是受到了传说的启发,而我的问题是,当我从交换机内部的敌人健康状况中减去时,它什么也没做。这是到目前为止的代码:

var health = (20)
var weapon = ('copper sword(5 DMG)')
var damage = (5)

//for npc's: name = [health, damage]
var playerstats = (name + ": health = " + health + ", weapon = " + weapon)
var skeleton1stats = [5, 5]

var name = prompt("Hi, what's your name?")
alert("Welcome " + name + " Are you ready to play Monster Fighter?")

alert("HINT: there will be messages in the log that you also should read. when a message like this appears click ok to continue")
alert("HINT: read log messages before dialog boxes, as the log messages are made before the dialog boxes are.")

console.log("Lets begin!")

console.log("You are walking through a forest when you trip and fall into a dark pit...")
console.log("As you are walking around a cave the pit lead you to, you are approached by a skeleton")
console.log("The skeleton tells you that he can lead you to safety")

alert("HINT: when you come across a character such as this one you will have multiple options, 3 of which are usually: fight, flee, and stats")
alert("HINT: I would recommend before fighting any character you view their stats.")

var skeleton1 = prompt("Do you choose to: TRUST, FIGHT, FLEE, STATS").toUpperCase()

switch (skeleton1) {

case 'TRUST':
console.log("The skeleton brings you to a dead end and stabs you doing 5 damage to you, and you hit him back doing 5 damage to him.");
skeleton1stats[0] - 5;
health - 5
break;

case 'FIGHT':
console.log("You thrust your sword through the skeleton doing 5 damage to the skeleton.");
skeleton1stats[0] - 5;
break;

case 'FLEE':
console.log("You make a run for it, but he catches up to you and stabs you dealing 5 damage to you. laying next to you is a iron sword(7 DMG), you picked it up and hit him with it doing 7 damage to him.");
health - 5;
skeleton1stats[0] - 7;
weapon = 'iron sword(7 DMG)'
damage = 7
break;

case 'STATS':
    console.log(playerstats + ", skeleton: health = " + skeleton1stats[0] + ", damage = " + skeleton1stats[1])
    var skeleton1 = prompt("Do you choose to: TRUST, FIGHT, FLEE").toUpperCase()
    switch (skeleton1) {
        case 'TRUST':
            console.log("The skeleton brings you to a dead end and stabs you doing 5 damage to you, and you hit him back doing 5 damage to him.");
            skeleton1stats[0] - 5;
            health - 5
        break;
        case 'FIGHT':
            console.log("You thrust your sword through the skeleton doing 5 damage to the skeleton.");
            skeleton1stats[0] - 5;
        break;
        case 'FLEE':
            console.log("You make a run for it, but he catches up to you and stabs you dealing 5 damage to you. laying next to you is a iron sword(7 DMG), you picked it up and hit him with it doing 7 damage to him.");
            health - 5;
            skeleton1stats[0] - 7;                
            weapon = 'iron sword(7 DMG)'
            damage = 7
        break;
        default:
            alert("ALERT: you must restart the game.")       
        break;
}
break;

default:
    alert("ALERT: if you do not enter one of the choices this time you will have to restart the game.")
    var skeleton1 = prompt("Do you choose to: TRUST, FIGHT, FLEE, STATS").toUpperCase()
    switch (skeleton1) {
        case 'TRUST':
            console.log("The skeleton brings you to a dead end and stabs you doing 5 damage to you, and you hit him back doing 5 damage to him.");
            skeleton1stats[0] - 5;
            health - 5
        break;
        case 'FIGHT':
            console.log("You thrust your sword through the skeleton doing 5 damage to the skeleton.");
            skeleton1stats[0] - 5;
        break;
        case 'FLEE':
            console.log("You make a run for it, but he catches up to you and stabs you dealing 5 damage to you. laying next to you is a iron sword(7 DMG), you picked it up and hit him with it doing 7 damage to him.");
            health - 5;
            skeleton1stats[0] - 7;              
            weapon = 'iron sword(7 DMG)'
            damage = 7
        break;
        case 'STATS':
            console.log(playerstats + ", skeleton: health = " + skeleton1stats[0] + ", damage = " + skeleton1stats[1])
        var skeleton1 = prompt("Do you choose to: TRUST, FIGHT, FLEE").toUpperCase()
        switch (skeleton1) {
            case 'TRUST':
                console.log("The skeleton brings you to a dead end and stabs you doing 5 damage to you, and you hit him back doing 5 damage to him.");
                skeleton1stats[0] - 5;
                health - 5
            break;
            case 'FIGHT':
                console.log("You thrust your sword through the skeleton doing 5 damage to the skeleton.");
                skeleton1stats[0] - 5;
            break;
            case 'FLEE':
                console.log("You make a run for it, but he catches up to you and stabs you dealing 5 damage to you. laying next to you is a iron sword(7 DMG), you picked it up and hit him with it doing 7 damage to him.");
                health - 5;
                skeleton1stats[0] - 7;
                weapon = 'iron sword(7 DMG)'
                damage = 7
            break;
            default:
                alert("ALERT: you must restart the game.")       
            break;
}
            break;
            default:
                alert("ALERT: you must restart the game.")       
            break;
}
            break;
}

if(skeleton1stats[0] < 1) {
console.log("You defeated the skeleton!") }

console.log("You continue down the cave further...")
console.log("far into the cave you see light, but coming from it are 3 zombies!")
console.log("Fairies then appear and kill the zombies and tell you to follow them to the 'hallow'")
console.log("in the hallow there are many fairies and the biggest one of them, the queen says she needs your help slaying these monsters that have begun appearing near the hallow")

var helpsfairies = confirm("will you help the fairies?")

if(helpsfairies) {
console.log("The fairies thank you and show you the way to a cave that they have seen many zombies in lately")
} else {
    console.log("The queen puts you under a spell and you help them anyway...") }
查迪

您需要将值分配回变量:

IE

health = health - 5;

更多信息:http : //www.w3schools.com/js/js_variables.asp

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么不能在Java中的开关内初始化变量?

来自分类Dev

在for循环中绘图:为什么我不能从计数器中减去?

来自分类Dev

为什么不能从最大double中减去1

来自分类Dev

为什么不能从浮点最大值中减去?

来自分类Dev

为什么我不能从我的 scss 文件中调用我的 id 变量?

来自分类Dev

为什么我不能从python中的异常返回我的局部变量?

来自分类Dev

为什么我不能从集合中获取项目并将其存储在变量中?

来自分类Dev

为什么我不能从AsyncTask访问全局变量?

来自分类Dev

为什么我不能从类访问脚本变量?

来自分类Dev

为什么我不能从 class() 获取变量

来自分类Dev

为什么我不能从闭包中返回对外部变量的可变引用?

来自分类Dev

为什么我不能从这个 C 代码访问在汇编中声明的 Tss 变量?

来自分类Dev

为什么我不能从类外部访问 __init__ 中定义的类变量?

来自分类Dev

为什么我不能从该表中删除记录?

来自分类Dev

为什么我不能从远程分支中拉出?

来自分类Dev

为什么我不能从闭包中返回引用?

来自分类Dev

为什么我不能从Python类中调用方法?

来自分类Dev

为什么我不能从提取中存储数据

来自分类Dev

为什么我不能从列表中删除所需的元素

来自分类Dev

为什么我不能从XPath查询中检索URL?

来自分类Dev

为什么我不能从C中的函数传回链表?

来自分类Dev

为什么我不能从Perl的同一包中声明的sub访问包中声明的变量?

来自分类Dev

为什么我的 for 循环不会从变量中减去?

来自分类Dev

为什么我不能从其他类访问公共变量?

来自分类Dev

为什么我不能从终端启动Eclipse?更改 $PATH 环境变量

来自分类Dev

为什么我不能从我的活动中调用此服务?

来自分类Dev

为什么我的 Raycast2Ds 不能从我的 tilemap 中检测到墙壁

来自分类Dev

为什么我不能从我的Json文件中检索数据?

来自分类Dev

我不知道为什么我不能从Pandas df中删除重复项

Related 相关文章

  1. 1

    为什么不能在Java中的开关内初始化变量?

  2. 2

    在for循环中绘图:为什么我不能从计数器中减去?

  3. 3

    为什么不能从最大double中减去1

  4. 4

    为什么不能从浮点最大值中减去?

  5. 5

    为什么我不能从我的 scss 文件中调用我的 id 变量?

  6. 6

    为什么我不能从python中的异常返回我的局部变量?

  7. 7

    为什么我不能从集合中获取项目并将其存储在变量中?

  8. 8

    为什么我不能从AsyncTask访问全局变量?

  9. 9

    为什么我不能从类访问脚本变量?

  10. 10

    为什么我不能从 class() 获取变量

  11. 11

    为什么我不能从闭包中返回对外部变量的可变引用?

  12. 12

    为什么我不能从这个 C 代码访问在汇编中声明的 Tss 变量?

  13. 13

    为什么我不能从类外部访问 __init__ 中定义的类变量?

  14. 14

    为什么我不能从该表中删除记录?

  15. 15

    为什么我不能从远程分支中拉出?

  16. 16

    为什么我不能从闭包中返回引用?

  17. 17

    为什么我不能从Python类中调用方法?

  18. 18

    为什么我不能从提取中存储数据

  19. 19

    为什么我不能从列表中删除所需的元素

  20. 20

    为什么我不能从XPath查询中检索URL?

  21. 21

    为什么我不能从C中的函数传回链表?

  22. 22

    为什么我不能从Perl的同一包中声明的sub访问包中声明的变量?

  23. 23

    为什么我的 for 循环不会从变量中减去?

  24. 24

    为什么我不能从其他类访问公共变量?

  25. 25

    为什么我不能从终端启动Eclipse?更改 $PATH 环境变量

  26. 26

    为什么我不能从我的活动中调用此服务?

  27. 27

    为什么我的 Raycast2Ds 不能从我的 tilemap 中检测到墙壁

  28. 28

    为什么我不能从我的Json文件中检索数据?

  29. 29

    我不知道为什么我不能从Pandas df中删除重复项

热门标签

归档