gpt4 book ai didi

javascript - 如何使程序在不重新输入的情况下恢复为原始文本

转载 作者:行者123 更新时间:2023-11-30 00:28:45 25 4
gpt4 key购买 nike

if (playerChoseWeapon === true) {

var roomGenerator = Math.Random();

if (roomGenerator > 0.75) {

var roomGeneratorRoomOne = Math.Random();

if (roomGeneratorRoomOne > 0.75) {

var rGenR1One = prompt("You see a dusty room with a door on the other side, what do you want to do? REST, DOOR, or STOP");

if (rGenR1One === REST && playerHealthPoints < 5) {

playerHealthPoints++;

//Make so it goes back to original thing!

} else if (rGenR1One === STOP) {

alert("Script stopped, you can restart now.");

//Maybe add some way to ask if they want to restart and it will let them?!

} else if (rGenR1One === DOOR) {


}

上面的代码看起来真的很难看,但在我的编辑器中看起来好多了。

基本上,当您执行 REST 时,“您看到一个满是灰尘的房间……”中的代码,并且它执行了,它将恢复到相同的“您看到一个满是灰尘的房间……”。

所以我不必重新输入数千次。

最佳答案

您可以使用 do while 循环:

if (playerChoseWeapon === true) {
var roomGenerator = Math.Random();
if (roomGenerator > 0.75) {
var roomGeneratorRoomOne = Math.Random();
if (roomGeneratorRoomOne > 0.75) {
do{
var rGenR1One = prompt("You see a dusty room with a door on the other side, what do you want to do? REST, DOOR, or STOP");
if (rGenR1One === REST && playerHealthPoints < 5) {
playerHealthPoints++;
//Make so it goes back to original thing!
} else if (rGenR1One === STOP) {
alert("Script stopped, you can restart now.");
//Maybe add some way to ask if they want to restart and it will let them?!
} else if (rGenR1One === DOOR) {
}
}while(rGenR1One === REST)

或者像这样:

if (roomGeneratorRoomOne > 0.75) {
var rGenR1One = prompt("You see a dusty room with a door on the other side, what do you want to do? REST, DOOR, or STOP");
if (rGenR1One === REST && playerHealthPoints < 5) {
playerHealthPoints++;
do{
var rGenR1One = prompt("You see a dusty room with a door on the other side, what do you want to do? REST, DOOR, or STOP");
if (rGenR1One === REST && playerHealthPoints < 5) {
playerHealthPoints++;
}
}while(rGenR1One === REST)
} else if (rGenR1One === STOP) {
alert("Script stopped, you can restart now.");
//Maybe add some way to ask if they want to restart and it will let them?!
} else if (rGenR1One === DOOR) {
}
}

关于javascript - 如何使程序在不重新输入的情况下恢复为原始文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30418350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com