我正在开发一款主机游戏,我不喜欢console.log的速度,也不喜欢提示之间的时间太少。有没有一种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/elses
,switches
,各种各样的功能和选择。但我想要一个基于文本的主机游戏的感觉。
我计划添加许多不同的路线、功能,并希望在某个时候增加动作。但这一切都无关紧要。如果有人知道减缓比赛节奏的方法,可以遵循这一指导原则,发表任何建议。
大多数用户认为提示既烦人又丑陋。在执行提示期间,用户将无法与任何其他内容交互,包括其他选项卡或控制台。此外,作为开发人员使用它非常不方便,因为它们是不可配置的,而且在开发、支持,尤其是调试方面很困难。
实现一个与用户交互的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样式。
创建自己的console
、alert
和prompt
方法来包装本机。
例如:
function logConsole(text, delay) {
window.setTimeout(function() {
console.log(text);
}, delay || 0);
};
如果没有传入延迟参数,您可以将上面的0
值更改为默认延迟。
logConsole('The air smells pungent today, and the weather is perfect.', 1000);
只是一个想法