在使用javascript的游戏中,Play和Pause按钮是如何工作的?

在使用javascript的游戏中,Play和Pause按钮是如何工作的?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在创建一个游戏,其中我使用javascript构建了几乎所有的函数。 但我无法创建播放和暂停按钮。 实际上,我想在那个按钮上做一个按钮,当你们点击PLAY按钮,游戏开始,当我点击Pause按钮,游戏暂停,所以。 谁能告诉我该怎么办。使播放和暂停按钮在一个按钮上工作。 这里我展示我的代码 看看吧,给我提个建议 var BrainShift=BrainShift | |{}; document.addEventListener(“DOMContentLoaded”,function()){ B

我正在创建一个游戏,其中我使用javascript构建了几乎所有的函数。 但我无法创建播放和暂停按钮。 实际上,我想在那个按钮上做一个按钮,当你们点击PLAY按钮,游戏开始,当我点击Pause按钮,游戏暂停,所以。 谁能告诉我该怎么办。使播放和暂停按钮在一个按钮上工作。 这里我展示我的代码

看看吧,给我提个建议

var BrainShift=BrainShift | |{};
document.addEventListener(“DOMContentLoaded”,function()){
BrainShift.init();
});
BrainShift.game_数据={
幻灯片:2,
时间间隔:60,
播放文字:“播放”,
welocme_text1:“大脑转移”,
欢迎你的潜台词:“描述选项”,
宽度:200,
身高:200,
哑巴:是的,
正文:“,
可能:“0123456789”,
可能1:“abcdefghijklmnopqrstuvxyz”,
声音图像:“”,
音频:'',
timerStart:'
};
BrainShift.util={
随机数:函数(){
BrainShift.game_data.text=“”;
对于(变量i=0;i<1;i++)
BrainShift.game_data.text+=BrainShift.game_data.mable.charAt(Math.floor(Math.random()*BrainShift.game_data.mable.length))+BrainShift.game_data.possible1.charAt(Math.floor(Math.random()*BrainShift.game_data.mable.length));
返回BrainShift.game_data.text;
},
onLoad:函数doOnLoad(num)
{
如果(num==0){
document.getElementById(“second_div”).innerHTML=“”;
document.getElementById(“first_div”).innerHTML=BrainShift.util.randomNumber();
document.getElementById(“first”).play();
}
如果(num==1){
document.getElementById(“first_div”).innerHTML=“”;
document.getElementById(“second_div”).innerHTML=BrainShift.util.randomNumber();
document.getElementById(“第二个”).play();
}
},
};
BrainShift.init=函数(){
document.getElementById(“first_div”).innerHTML=BrainShift.util.randomNumber();
BrainShift.game_data.soundImage=document.getElementById(“静音”);
BrainShift.game_data.audios=document.queryselectoral(“音频”);
BrainShift.game_data.timerStart=setInterval(BrainShift.operation.timer,1000);
}
BrainShift.recordAnswer=函数(){
//创建json并存储在用户_数据中
//正确的
//滑梯
//不正确
//花费的时间
//准确度
//百分比
}
脑力转换操作={
静音:函数(){
if(BrainShift.game_data.mute==真)
{
BrainShift.game_data.soundImage.style.backgroundImage=“url('muteNew.png')”;
BrainShift.game_data.audios.forEach.call(BrainShift.game_data.audios,function(audios){audios.muted=true});
BrainShift.game_data.mute=false;
}
否则{
BrainShift.game_data.soundImage.style.backgroundImage=“url('unmuteNew.png')”;
BrainShift.game_data.audios.forEach.call(BrainShift.game_data.audios,function(audios){audios.muted=false});
BrainShift.game_data.mute=true;
}
},
计时器:函数(){
var分钟=数学轮((BrainShift.game\u data.time\u interval-30)/60);
remainingSeconds=BrainShift.game\u data.time\u间隔%60;
如果(剩余秒span,#暂停>span{
字号:900;
最高:0%;
左:30%;
位置:相对位置;
字体大小:xx大号;
}
#停顿{
左边缘:49%;
宽度:35px;
高度:35px;
边界半径:50%;
边框:1px纯白;
显示:内联块;
背景色:白色;
}
#哑巴{
左缘:5%;
宽度:35px;
高度:35px;
边界半径:50%;
边框:1px纯白;
显示:内联块;
背景图片:url('images/unmuteNew.png');
光标:指针;
}

脑力转换游戏
家
您的浏览器不支持
音频
元素。 您的浏览器不支持
音频
元素。 您的浏览器不支持
音频
元素。 您的浏览器不支持
音频
元素。 不 对 ?
当您编写代码时,游戏将在加载
DOMContentLoaded
时启动。不要在加载文档后立即启动游戏,而是将
BrainShift.init();
放入函数中,并使用按钮调用该函数

使用两个函数更改以下行,这两个函数处理播放和暂停,如代码段所示

document.addEventListener("DOMContentLoaded", function(){
    BrainShift.init();
});
注意:使用您的代码在
pause()
函数中暂停游戏

var BrainShift=BrainShift | |{};
函数播放(){
BrainShift.init();
document.getElementById(“playbtn”).style.display=“无”;
document.getElementById(“pausebtn”).style.display=“block”;
}
函数暂停(){
//使用您的代码在此处暂停游戏
document.getElementById(“playbtn”).style.display=“block”;
document.getElementById(“pausebtn”).style.display=“无”;
}
BrainShift.game_数据={
幻灯片:2,
时间间隔:60,
播放文字:“播放”,
welocme_text1:“大脑转移”,
欢迎你的潜台词:“描述选项”,
宽度:200,
身高:200,
哑巴:是的,
正文:“,
可能:“0123456789”,
可能1:“abcdefghijklmnopqrstuvxyz”,
声音图像:“”,
音频:'',
timerStart:'
};
BrainShift.util={
随机数:函数(){
BrainShift.game_data.text=“”;
对于(变量i=0;i<1;i++)
BrainShift.game_data.text+=BrainShift.game_data.mable.charAt(Math.floor(Math.random()*BrainShift.game_data.mable.length))+BrainShift.game_data.possible1.charAt(Math.floor(Math.random()*BrainShift.game_data.mable.length));
返回B