-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·254 lines (246 loc) · 7.84 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>读心天平</title>
<style type="text/css">
<!--
.style1 {color: #006699}
.style2 {color: #FFFFFF}
-->
</style>
</head>
<script type="text/javascript" language="javascript" src="ajax.js"></script>
<script type="text/javascript" language="javascript" src="balance.js"></script>
<script type="text/javascript" language="javascript">
function createElement(tag,type,name,value){
var e=document.createElement(tag);
e.setAttribute("type",type);
e.setAttribute("name",name);
e.setAttribute("value",value);
return e;
}
function createEle(tag){
var e=document.createElement(tag);
return e;
}
function show(id){
var e=document.getElementById(id);
e.style.display="block";
}
function hide(id){
var e=document.getElementById(id);
e.style.display="none";
}
function clear(id){
var e=document.getElementById(id);
while(e.hasChildNodes())
e.removeChild(e.childNodes[0]);
}
function createLog(left,right,stat,r){
var e=createEle("td");
e.appendChild(document.createTextNode("第"+r+"次:"+stat));
var t=createEle("p");
t.style.color="#006699";
t.appendChild(document.createTextNode("天平左侧:"));
e.appendChild(t);
t=createEle("small");
t.appendChild(document.createTextNode(left));
e.appendChild(t);
// e.appendChild(createEle("br"));
t=createEle("p");
t.style.color="#006699";
t.appendChild(document.createTextNode("天平右侧:"));
e.appendChild(t);
t=createEle("small");
t.appendChild(document.createTextNode(right));
e.appendChild(t);
t=createEle("tr");
t.appendChild(e);
e=createEle("tbody");
e.appendChild(t);
t=createEle("table");
t.setAttribute("border","0");
t.setAttribute("bgcolor","#C3D9FF");
t.setAttribute("width","800");
t.appendChild(e);
e=document.getElementById("tianpinlog");
if(e.hasChildNodes()){
e.insertBefore(t,e.childNodes[0]);
e.insertBefore(createEle("br"),e.childNodes[0]);
}else {
e.appendChild(createEle("br"));
e.appendChild(t);
}
}
function toggleStep(evt) {
evt = (evt) ? evt : event;
var target = (evt.target) ? evt.target : evt.srcElement;
var block;
if (target.name == "button1"){
hide("step1");
show("step2");
}
else if (target.name == "button2"){
hide("step2");
show("step3");
}
else if (target.name == "button3"){
hide("step3");
show("tianpin");
}else if(target.name=="playagain"){
hide("showanswer");
clear("tianpinlog");
show("step2");
}
}
function setCount(){
var e=document.getElementById("txtCount").value;
var reg = /^[-]?\d*\.?\d*$/;
e = e.toString( );
if(!e.match(reg)){
alert("你所输入的内容不是一个整数");
return;
}
var f=new Number(e);
if(f<3 || f> Number.MAX_VALUE ){
alert("你所输入的应该是一个大于3的数字");
return;
}
setBallsCount(f);
var txt="现在将球编号为:1,2,.."+f+"。请在心中选择其中一个球作为那颗质量不一样的球,并记住它的编号,以及他比其他的球重还是轻。"
replaceInnerHTML("step3_count",txt);
hide("step2");
show("step3");
}
var round=0;
function onDecide(evt){
evt = (evt) ? evt : event;
var target = (evt.target) ? evt.target : evt.srcElement;
if(target.id=="tianpinleft"){
round++;
createLog(getBallsAt(1),getBallsAt(2),"左重右轻",round);
tianpinStatus=1;
judge();
}else if(target.id=="tianpinright"){
round++;
createLog(getBallsAt(1),getBallsAt(2),"右重左轻",round);
tianpinStatus=2;
judge();
}else if(target.id=="tianpinpinhen"){
round++;
createLog(getBallsAt(1),getBallsAt(2),"平衡",round);
tianpinStatus=0;
judge();
}
else
round=0;
var r=decide();
var e;
if(-1==r){
replaceInnerHTML("theanswer","无解");
hide("tianpin");
hide("message");
show("showanswer");
}else if(1==r){
replaceInnerHTML("theanswer",getAnswer());
hide("tianpin");
hide("message");
show("showanswer");
}else{
replaceInnerHTML("onleft",getBallsAt(1))
replaceInnerHTML("onright",getBallsAt(2));
hide("step3");
show("tianpin");
}
}
function replaceInner(node,text){
if(node.hasChildNodes()){
node.removeChild(node.childNodes[0]);
}
var textnode = document.createTextNode(text);
node.appendChild(textnode);
}
function replaceInnerHTML(id,text){
var node = document.getElementById(id);
replaceInner(node,text);
}
function tellFrieds(){
var e=document.getElementById("message");
if (e.style.display=="none"){
var s="读心天平。\n"+document.location.toString();
e.style.display="block";
e.value=s;
e.focus();
e.select();
}
hide("copied");
if(window.clipboardData.setData("Text",e.value)){
show("copied");
}
}
</script>
<body>
<noscript>
<p>
<div align="center" style="color:red">本页面必须使用javascript才可以正确显示,但你目前的浏览器设置禁用或阻止了使用javascript</div>
</p>
</noscript>
<div align="center" style="width:800px;margin:0 auto;">
<h1>读心天平</h1>
<div align="left">
<div id="step1" style="display:block ">
<p>在一堆大小相同的球之中,有一只球与其他的球重量不同,现有一只没有砝码的天平,现在由玩家来设定这些球,机器人将用天平判断出哪一只球是那只不一样的球。</p>
<div align="right">
<input type="button" name="button1" value="我明白了,开始玩吧" onClick="toggleStep(event)">
</div>
</div>
<div id="step2" style="display:none"><p align="left">请玩家来设定总球数(建议不要超过1500个球):
<input id="txtCount" name="textfield" type="text" size="5">
<input type="button" name="button2" value="OK" style="width:80" onClick="setCount()"></p></div>
<div id="step3" style="display:none">
<div id="step3_count"></div>
<input type="button" name="button3" value="I am ready" onClick="onDecide(event)">
</div>
<div id="tianpin" style="display:none">
<p class="style1">天平左侧:
</p>
<small><div id="onleft">a</div></small>
<br>
<span class="style1">天平右侧:</span>
<small><div id="onright">a</div></small>
<br> <div align="center">
<input id="tianpinleft" type="button" name="Submit5" value="左重右轻" onClick="onDecide(event)">
<input id="tianpinpinhen" type="button" name="Submit6" value="平衡" style="width:80" onClick="onDecide(event)">
<input id="tianpinright" type="button" name="Submit7" value="右重左轻" onClick="onDecide(event)">
</div>
</div>
<div id="showanswer" style="display:none "><div id="theanswer" style="color:#006699 ">a</div><br>
<p align="center">
<input name="playagain" type="button" value="再整一局玩玩" onClick="toggleStep(event)"/>
<input type="button" value="告诉朋友" onClick="tellFrieds()"></input>
<br>
</p>
<div align="center">
<table id="copied" style="display:none " border="0">
<td bgcolor="#3399FF"><span class="style2">下面的文字已复制到剪切板</span></td>
</table>
<br>
<textarea cols="50" rows="6" id="message" style="display:none"></textarea>
</div>
</div>
<div id="tianpinlog" align="center">
</div>
</div>
<br><br><br>
<div align="center">
<p><a href="http://github.com/guileen">桂林@github</a></p>
<p><a href="mailto:guileen@gmail.com">guileen@gmail.com</a></p>
<p>© 2007 All rights reserved.</p>
</div>
</div>
</body>
</html>