gpt4 book ai didi

javascript - 慢点,控制台。 (javascript/jquery)

转载 作者:行者123 更新时间:2023-11-28 18:55:41 24 4
gpt4 key购买 nike

我正在开发一款主机游戏,但我不喜欢 console.logs 的速度以及提示之间的时间太短等。有没有 javascript/jquery 方法来减慢游戏速度?为此,我可以简单地delay()每一行(这听起来很乏味)吗?或者如果我要使用setTimeout(),理论上我是否必须拆分我的游戏分成很多不同的函数并设置超时或间隔?您有什么建议?

例如片段:

alert('~~ WELCOME TO [x] ~~');
console.log('Before we get started, let\'s find out a little about you.');
var usr = {
name : prompt('What\'s your name?'),
age : prompt('How old are you?'),
clr : prompt('What\'s your favorite color?'),
pref : prompt('Which [x] is your favorite?'),
}


console.log('The air smells pungent today, and the weather is perfect.');
console.log(''); console.log('');
console.log('Did you hear that? I think something may be following us down the path to the [x]...');
console.log('');


var alpha = prompt('');

会有if/elsesswitches,各种功能和选择。但我想要基于文本的控制台游戏的感觉。

我计划添加许多不同的路线、功能,并希望在某个时候添加移动。但这不是重点。如果有人知道一两种减慢游戏速度并遵循此准则的方法,请发布任何建议。

最佳答案

大多数用户认为提示既烦人又丑陋。在执行提示期间,用户将无法与其他任何内容(包括其他选项卡或控制台)进行交互。而且,作为开发人员使用它非常不方便,因为它们不可配置,并且开发、支持,尤其是调试都很困难。

实现与用户交互的 HTML 页面是一个更好的主意。因此,您将能够对其进行自定义并且看起来很漂亮。

例如,您可以创建一个看起来像聊天 - 文本窗口并在底部输入的页面。像这样:

function tell(text) 
{
$("<p/>").text(text).appendTo($('#chat'));
}

function ask(text, callback)
{
$("<p/>").text(text).addClass('question').appendTo($('#chat'));

$('#send')
.prop('disabled', false)
.one('click', function() {
var text = $("#message").val();
callback(text);
$("#message").val("");
$(this).prop('disabled', true);
});
}

tell("Hi");

ask("What is your name?", function(x) {
tell("So strange...my name is " + x + ", as well...");
});
#chat {
padding: 20px;
position: absolute;
top: 0px;
bottom: 20px;
left: 0px;
right: 0px;
background-color: #DDDDDD;
}

#message {
position: absolute;
bottom: 0px;
left: 0px;
height: 14px;
width: 80%;
}

#send {
position: absolute;
bottom: 0px;
left: 80%;
width: 20%;
height: 20px;
}

.question {
font-weight: bold;
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="chat"></div>
<input type="text" id="message"/>
<input type="submit" id="send" disabled/>

这只是一个例子。您可以添加任何内容,例如延迟或 CSS 样式。

关于javascript - 慢点,控制台。 (javascript/jquery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665148/

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