所以我正在制作这个文本冒险游戏,基本上你可以在这张想象的地图中输入一组你想去的动作。例如,在输入框中输入“north”,那么结果将是“你决定向北走,并遇到了一家超市”。我想知道的是,是否可以根据我选择的目的地添加图像?就像上面的例子一样,我选择了向北并最终到达了一家超市,因此结果将是一家超市的图像。我已经弄清楚了显示文本的 if 语句的工作原理,让玩家知道他去了哪里,但我还想知道如何添加图像?
...
<p> Pick a direction to go </p>
<input id = "input" type = "text" placeholder = "Type Help for actions"/><button onClick = "button()">Confirm</button>
<p id = "message"></p>
<script>
function button() {
var textInput;
var newInput = input.value;
if (newInput == "North") {
textInput = "you went to the Abandoned Church";
document.getElementById("message").innerHTML = textInput;
}
if (newInput == "North Again") {
textInput = "you went to the Abandoned Someplace";
document.getElementById("message").innerHTML = textInput;
}
if (newInput == "Help") {
textInput = "Commands you can use: <ul><li>South</li><li>North</li><li>East</li><li>West</li><li>North Again</li><li>South again</li><li>West Again</li><li>East Again</li><li>North One More</li><li>East Once More</li><li>West Once More</li><li>South Once More</li>";
document.getElementById("message").innerHTML = textInput;
}
}
</script>
哆啦的时光机
蝴蝶不菲
相关分类