如何使程序恢复到原始文本,而无需重新键入它

How to make the program revert back to original text without retyping it

本文关键字:新键入 文本 程序 何使 恢复 原始      更新时间:2023-09-26
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) {
        }
}