在我开始之前,我想说对不起,我写得不太好,我对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...") }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句