我正在尝试创建简单的国际象棋代码,我会理解它是如何工作的。我确实找到了一两个样本,但我不明白那个代码。(链接1,链接2)你能帮帮我吗?
我尝试将倒数计时器与 checc 时钟结合起来,但没有成功。当我按下“开始”按钮时,时钟将开始为玩家 1(白色)倒计时。当该玩家按下按钮(“白色”)时,该玩家的时间将停止并开始为黑色玩家倒计时,因此当该玩家按下“黑色”按钮时,计时器开始为白色玩家倒计时。我需要 2 个单独的计时器还是足够一个可以“保存”计时器?如何设置“添加时间”?这是当玩家按下按钮时,计时器增加了几秒钟?
这是我到目前为止所尝试的:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Chess clock</title>
<style type="text/css">
#MoveWhite{
margin-left: 50px;
float:Left;
width:200px;
height: 100px;
background-color: silver;
text-align: center;
}
#MoveBlack{
float:left;
width:200px;
height: 100px;
background-color: blue;
text-align: center;
}
#Begin{
margin-left: 50px;
float:left;
width: 400px;
height: 100px;
background-color: green;
text-align: center;
}
#SetUp{
margin-left: 50px;
margin-right: 50px;
float: left;
width: 400px;
height: 100px;
background-color: green;
}
body{
width: 500px;
background-color: #06F;
}
</style>
<script type="text/javascript">
var minutesleft = 0;
var secondsleft = 60;
var finishedtext = "Lost"
ura = new Date();
ura.setMinutes(ura.getMinutes() + minutesleft);
ura.setSeconds(ura.getSeconds() + secondsleft);
function cdWhite(){
now = new Date();
diff = ura - now;
diff = new Date(diff);
var sec = diff.getSeconds();
var min = diff.getMinutes();
if (min < 10){
min = "0" + min;
}
if (sec < 10){
sec = "0" + sec;
}
if(now >= ura){
clearTimeout(timerID);
document.getElementById("cdtime").innerHTML = finishedtext;
}
else{
document.getElementById("cdtime").innerHTML = min + ":" + sec;
}
timerID = setTimeout("cdWhite()", 10);
}
</script>
</head>
<body>
<div id = "Begin">
<p>White player start game when press "Start game" button</p>
<button onClick="cdWhite()">Start game!</button>
</div>
<div id = "num1">
<div id = "MoveWhite">
<h1 id = "White"><span id="cdtime">TimerWhite??<!-- Lost (if white player loose) -->
</span></h1>
<button onClick="startBlack()">White</button>
</div>
<div id = "MoveBlack">
<h1 id = "Black">TimerBlack??</h1> <!-- Lost (if black player loose) -->
<button onClick="startWhite()">Black</button>
</div>
</div>
<div id = "SetUp">
<p>Set different starting time <br/>
Set starting time: ___min ___sec</p>
<p>Add time: ____ sec</p>
</div>
<ul id = "cas">
</ul>
</body>
</html>