forked from xsir317/ku10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
625 lines (584 loc) · 24.4 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"><meta name="keywords" content="五子棋,连珠,五子棋必胜,Renjuclass,连珠教室,安度教室,五子棋先手必胜" />
<meta name="description" content="本站收集了RenjuClass的五子棋课程,详细讲解了五子棋先手必胜的走法,适合初学者,也适合有一定基础的五子棋爱好者自学。" />
<meta name="viewport" content="width=800, initial-scale=1">
<title>RenjuClass五子棋课程在线学习</title>
<link rel="stylesheet" href="/layui/css/layui.css" media="all">
<style>
body
{
font-family: "微软雅黑",Arial,Helvetica,sans-serif;
background-color: #EFEEF7;
}
img{border:none;}
h1,h2,h3{margin:0;}
p{font-size:14px;margin:0 0 5px 0;line-height:22px;}
ul,li,dt,dd,ol{list-style:none;padding:0;margin:0}
.footer {margin:10px 0;}
.footer p{text-align:center;}
.button{cursor:pointer;background:#59A8F3;border-color: #3990DB #3990DB #2F78B7;border-style: solid; border-width: 1px; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset; color: #FFFFFF; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);border-radius: 4px 4px 4px 4px; display: inline-block; font-size: 13px; padding: 3px 9px;}
.button:hover{background:#3F96E5;}
#board_main
{
background:url('/images/board-0.png') 0 -3px no-repeat;
height:583px;
width:590px;
padding-top:3px;
user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
}
.black
{
background:url('/images/b.png') center center no-repeat;
color:white;
}
.white
{
/*background:url('/images/w.png') center center no-repeat;*/
background:url('/images/w_combine.png') center center no-repeat;
}
.row
{
height:37px;
width:556px;
margin-left:5px;
overflow:hidden;
}
.row div
{
font-family:Arial;
height:37px;
width:37px;
float:left;
line-height:37px;
text-align:center;
font-weight:bold;
font-size:18px;
cursor:pointer;
overflow:hidden;
}
.controlbar{width: 550px;}
.controlbar button{margin-left:5px;}
#chat_content_list {height:600px;overflow-x: hidden;overflow-y:auto;padding: 12px 0px;background: #f2f2f2;margin-left:40px;}
#chat_content li{border-bottom: 1px solid #ddd;line-height: 25px;}
#chat_content .chat-name{font-weight: bold;color:#59A8F3;}
#chat_content .teacher{color:#e24329;}
#chat_content .chat-move{color:#3f9343;}
#chat_content .chat-sys{color:#9e5724;}
#lesson_list{height:560px;overflow-x:hidden;overflow-y:scroll;}
#lesson_list ul li{line-height:26px;height:26px;overflow:hidden;white-space:nowrap;}
#lesson_list ul li a{color:#5b76a0}
#lesson_list ul li a:hover{color:#ffaa56}
#lesson_list ul li a:visited{color:#894e14}
#play_control{padding: 0 5px 0 5px;height:60px;overflow:hidden;}
#progress{width:100%;height:20px;overflow:hidden;border:1px solid #ddd}
#progress>div{width:0%;height:20px;background-color:#779e23;}
#lesson_list a{text-decoration: none; margin-bottom: 5px; display: block; }
</style>
</head>
<body>
<div class="layui-container" style="margin-top: 20px;">
<div class="layui-col-space5 layui-row">
<div class="layui-col-md6 layui-col-xs9"><div id="board_main"></div></div>
<div class="chat_area layui-col-md3 layui-col-xs3">
<div id="chat_content_list">
<ul id="chat_content"></ul>
</div>
</div>
<div id="lesson_list" class="layui-col-md3 layui-col-xs12">
<ul></ul>
</div>
<div id="play_control" class="layui-col-md3 layui-col-xs12">
<div id="progress">
<div></div>
</div>
<div class="buttons">
<button class="button btn_play"> > </button>
<button class="button btn_pause"> ||</button>
<select name="speed">
<option value="1000">播放速度</option>
<option value="1333">0.75倍速</option>
<option value="999">正常</option>
<option value="667">1.5倍速</option>
<option value="1333">0.75倍速</option>
<option value="500">2倍速</option>
<option value="333" selected="selected">3倍速</option>
<option value="100">10倍速</option>
<option value="10">100倍速</option>
</select>
</div>
</div>
</div>
</div>
<div class="layui-footer footer footer-doc">
<p>
本项目在<a href="https://github.com/xsir317/ku10" target="_blank">Github</a>维护。主页展示的是所有ORC课程记录,另有<a href="/resources/index.html" target="_blank">文本资料</a>。 </p>
<p>
请使用Chrome或Firefox访问。本站内容来自网络,感谢Ando老师、Luwenzhe老师和课程讲师的贡献。内容版权归原作者所有。<br />如有疑问欢迎联系我 [email protected] </p>
</div>
<script src="https://image.kk1.cn/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
/**
* @author [email protected]
* @license http://creativecommons.org/licenses/by-sa/3.0/deed.zh
*/
let board = null;
let record_player = null;
let boardObj = function()
{
//棋盘的DOM对象,基本上棋子、棋盘逻辑都在这里面。
let board = $("#board_main");
let _obj = this;
//整个游戏的数据结构,包括对局进程、状态、双方等等。会通过页面变量或者Websocket推过来。
//_obj.game_record = '';
//字符串,当前局面记录。
_obj.currgame = '';
//字符串,记录终局状态。
_obj.endgame = '';
// 当前颜色,在初始化时会初始化为黑色
_obj.curr_color = 'black';
//当前手数,会被初始化为1
_obj.curr_step = 1;
//load 一个游戏数据。
_obj.load = function( game_record ){
//为了播放声音,这里对比一下旧盘面和新load的盘面,决定是否播放一次声音
//let play_sound = (_obj.currgame != game_data.game_record);
//_obj.game_record = game_record;
_obj.endgame = game_record;
_obj.show_origin();
/*if(play_sound)
{
pager.play_sound('Move');
}*/
};
//自动切换模式。
_obj.switch_mode = (function(){
let _mode = 'game';// game or analyze
return function(mode){
if(mode == _mode)
{
return true;
}
_mode = mode;
switch(mode)
{
case 'game':
//board.removeClass("mode_analyze").addClass("mode_game");
board.css("background-image","url(/images/board.png)");
break;
case 'analyze':
board.css("background-image","url(/images/board-grey.png)");
break;
default:
break;
}
};
})();
/**
* @description 在指定位置放置一枚棋子。
* @param {string} coordinate 传入坐标。
* @param {boolean} play_sound 是否播放声音
* @returns {boolean}
*/
_obj.place_stone = function(coordinate,play_sound){
let target_cell = board.find('.'+coordinate);
if(!target_cell.hasClass('blank'))
{
return false;
}
target_cell.removeClass('blank').addClass(_obj.curr_color).html(_obj.curr_step ++);
/*try rand stone*/
if(_obj.curr_color == 'white')
{
target_cell.css({
"background-position" : "0px " + (-37 * Math.floor(Math.random() * 9 )).toString() + "px"
});
}
_obj.curr_color = (_obj.curr_color == 'black' ? 'white':'black');
_obj.currgame += coordinate;
if(_obj.currgame != _obj.endgame.substr(0,_obj.currgame.length))
{
_obj.endgame = _obj.currgame;
//在改变了endgame时,如果不是playing ,则都进入研究模式。
//record_player.pause();
//_obj.switch_mode('analyze');
}
if(play_sound)
{
//pager.play_sound('Move');
}
return true;
};
_obj.get_current_board = function () {
return _obj.currgame;
};
/**
* 右键和回退按钮的事件,往回退一个棋子。并不产生任何Ajax,这不是悔棋操作。
* @returns {boolean}
*/
_obj.move_pre = function(){
if(_obj.currgame)
{
let last_move = _obj.currgame.substr(_obj.currgame.length-2,2);
//这个棋子拿起来。。。
let target_cell = board.find('.'+last_move);
target_cell.removeClass('black white').addClass('blank').removeAttr('style').html('');
_obj.curr_step --;
_obj.curr_color = (_obj.curr_color == 'black' ? 'white':'black');
_obj.currgame = _obj.currgame.substr(0,_obj.currgame.length-2);
return true;
}
return false;
};
/**
* 根据endgame,一步一步走下去,把整个棋局展示出来。
* @returns {boolean}
*/
_obj.move_next = function(){
if(_obj.currgame != _obj.endgame)
{
let nextstep = _obj.endgame.substr(_obj.currgame.length,2);
_obj.place_stone(nextstep);
return true;
}
return false;
};
/**
* 回退到空棋盘状态。
*/
_obj.board_clean = function(){
while (_obj.move_pre()) {}
};
/**
* 根据目前的棋局记录一路Next到局面结束的状态。
*/
_obj.board_end = function(){
while(_obj.move_next()) {}
};
/**
* 根据game_record 初始化棋盘的文字信息和棋盘Game信息
*/
_obj.show_origin = function(){
//_obj.switch_mode('game');
_obj.board_clean();
//_obj.endgame = _obj.game_record;
_obj.board_end();
};
/**
* 画棋盘和按钮。绑定右键事件。
* 整个页面载入的时候会执行一次。仅此一次。
*/
_obj.init_board = function(){
_obj.currgame = '';
_obj.curr_color = 'black';
_obj.curr_step = 1;
board.html('');
board.bind("contextmenu", function() { return false; });
for(let i=15;i>=1;i--)
{
//insert a row
let newrow = $(document.createElement("div"));
newrow.addClass('row');
for(let j=1;j<=15;j++)
{
//insert a cross point
let newcell = $(document.createElement("div"));
newcell.addClass(j.toString(16) + i.toString(16));
newcell.attr('alt',j.toString(16) + i.toString(16));
newcell.addClass('blank');
newrow.append(newcell);
}
board.append(newrow);
}
board.find('.row div').click(function(){
//_obj.place_stone($(this).attr('alt'),true);
let coordinate = $(this).attr('alt');
let c_x = parseInt(coordinate.charAt(0),16) + 96;
let c_y = parseInt(coordinate.charAt(1),16);
let show_x = String.fromCharCode(c_x);
if(show_x == 'l') show_x = 'L';
let show_content = show_x + c_y.toString();
record_player.sysMsg("点击: " + show_content);
return true;
});
//生成控制按钮
let controlbar = $(document.createElement("div"));
controlbar.addClass('controlbar');
board.after(controlbar);
//按钮
$(document.createElement("button")).addClass('button').text("分析") .click(function(){
record_player.pause();
window.open('/board.html#' + _obj.currgame , 'analyze', 'height=660,width=660,fullscreen=0,location=0,menubar=0,resize=0',true);
}).appendTo(controlbar);
$(document.createElement("button")).addClass('button show').text("隐藏数字").click(function(){
let _btn = $(this);
if(_btn.hasClass("show"))
{
_btn.text("显示数字").removeClass('show');
$("<style>").attr("id",'hide_number').html('.row div{text-indent:-999px;overflow:hidden;}').appendTo("head");
}
else
{
_btn.text("隐藏数字").addClass('show');
$("#hide_number").remove();
}
}).appendTo(controlbar);
};
};
let recordPlayer = function(){
let obj = this;
this.pointer = 0;//当前播放到第几个action
this.timer = 0;//计时器
this.record = [];
this.status = 0;
obj.load = function(record){
obj.pause();
obj.record = record;
obj.pointer = 0;
obj.timer = 0;
obj.status = 0;
board.load('');
$("#chat_content").empty();
$("#progress>div").css("width", '0%');
obj.play();
};
obj.play = function(){
if(typeof(obj.record[obj.pointer]) == 'undefined')
{
return false;
}
if(!obj.renderRow(obj.record[obj.pointer]))
{
obj.sysMsg("播放失败");
return false;
}
let now = obj.record[obj.pointer]['time_int'];
obj.pointer ++;
//计算progress
let progress_percent = 0;
if(obj.pointer % 5 == 0 && obj.record.length > 0)
{
progress_percent = parseInt(obj.pointer * 100 / obj.record.length );
$("#progress>div").css("width", progress_percent + '%');
}
//progress 结束
if(typeof(obj.record[obj.pointer]) == 'object')
{
obj.status = 1;
let delta_time = obj.record[obj.pointer]['time_int'] - now;
if(obj.record[obj.pointer] == 'RESET')
{
delta_time = 1;
}
delta_time = delta_time <= 5 ? delta_time : 5;
let speed = parseInt($("select[name=speed]").val());
obj.timer = setTimeout(function(){obj.play();},10 + speed * delta_time);
}
else
{
obj.sysMsg("播放完毕");
}
};
obj.pause = function(){
if(obj.timer)
{
obj.status = 0;
clearTimeout(obj.timer);
obj.timer = 0;
obj.sysMsg("播放暂停");
}
};
obj.renderRow = function(row){
//console.log(row);
let function_name = 'action'+row['action'];
let $return = false;
if(typeof obj[function_name] == 'function')
{
$return = obj[function_name](row);
}
else
{
//console.log(row);
}
if($("#chat_content").find("li").length > 150)
{
for(let i = 1; i <= 100; i ++)
{
$("#chat_content").find("li:first").remove();
}
}
$("#chat_content_list").scrollTop($("#chat_content_list")[0].scrollHeight - $("#chat_content_list").height());
return $return;
};
/**
* 以下是各种事件的处理方法。
*/
obj.actionRESET = function(){
board.load('');
return true;
};
obj.actionTALK = function(row){
let _name = $("<span>").html(row.user).addClass("chat-name");
let _content = $("<span>").html(row.content).addClass("chat-content");
if(row.user == 'RenjuTeacher' || row.user == 'GrandMaster')
{
_content.addClass("teacher");
}
let li = $("<li>");
li.append(_name).append(": ").append(_content);
li.appendTo($("#chat_content"));
return true;
};
obj.actionMOVE = function(row){
//coordinate
let c_x = parseInt(row.content.charAt(0),16) + 96;
let c_y = parseInt(row.content.charAt(1),16);
let show_x = String.fromCharCode(c_x);
if(show_x == 'l') show_x = 'L';
let show_content = board.curr_step.toString() + ' - ' + show_x + c_y.toString();
let _content = $("<span>").html(row.user + ': ' + show_content).addClass("chat-move");
let li = $("<li>");
li.append(_content);
li.appendTo($("#chat_content"));
return board.place_stone(row.content);
};
obj.actionCHECKRESULT = function(row){
obj.sysMsg("点名:" + row.content);
return true;
};
obj.actionEMOTE = function(row){
return obj.actionTALK(row);
};
obj.actionGOTO = function(row){
while(board.get_current_board().length > row.content * 2)
{
if(!board.move_pre()) break;
}
while(board.get_current_board().length < row.content * 2)
{
if(!board.move_next()) break;
}
return true;
};
obj.actionBACK = function(row){
board.move_pre();
return true;
};
obj.actionFIRST = function(row){
board.board_clean();
board.move_next();
return true;
};
obj.actionCREDIT = function(row){
obj.sysMsg("本次课程拿到学分的同学:" + row.content);
return true;
};
obj.actionNEXT = function(row){
board.move_next();
return true;
};
obj.actionCLEAR = function(row){
board.load('');
return true;
};
obj.actionLOAD = function(row){
board.load(row.content);
return true;
};
obj.actionLAST = function(row){
board.board_end();
return true;
};
//事件处理结束
obj.sysMsg = function(msg){
let li = $("<li>");
$("<span>").addClass("chat-sys").html(msg).appendTo(li);
li.appendTo($("#chat_content"));
$("#chat_content_list").scrollTop($("#chat_content_list")[0].scrollHeight - $("#chat_content_list").height());
}
};
//1.new出对象
board = new boardObj();
record_player = new recordPlayer();
$(document).ready(function(){
board.init_board();
let load_game = function(source,callback){
$.getJSON("/json/" + source,{},function(_data){
//play data
//console.log(source);
record_player.load(_data);
if(typeof callback == 'function')
{
callback();
}
});
};
let auto_play = function(){
console.log(window.location.hash);
if(window.location.hash.charAt(0) == '#')
{
console.log(window.location.hash.charAt(0));
let autoplay_num = parseInt(window.location.hash.substring(1));
console.log(autoplay_num);
console.log($("#lesson_list>ul li").length);
if(autoplay_num >= 0 && autoplay_num < $("#lesson_list>ul li").length)
{
$("#lesson_list>ul").find('#play_link_' + autoplay_num).click();
}
}
else
{
load_game("20181229.json",function(){
//record_player.sysMsg("欢迎!");
});
}
};
$.getJSON('/trans.json?d=20190314',{},function(_data){
for (let i in _data)
{
let _tmp = _data[i];
let _link = $(document.createElement('a'));
_link.attr("title",_tmp['show_name'])
.attr("data-source",_tmp["data"])
.attr("href","#" + i)
.attr("id",'play_link_' + i)
.html(_tmp['show_name']);
_link.click(function(){
$("title").text($(this).text() + " @ RenjuClass课程在线学习");
record_player.sysMsg("Loading......");
load_game($(this).attr('data-source'),function(){
record_player.sysMsg("开始播放" + $("title").text());
});
});
if (typeof _tmp['origin'] == 'boolean' && _tmp['origin'])
{
$("<li></li>").append(_link).prependTo($("#lesson_list>ul"));
}
else
{
$("<li></li>").append(_link).appendTo($("#lesson_list>ul"));
}
}
auto_play();
});
$(".btn_play").click(function(){
if(record_player.status == 0)
{
record_player.sysMsg("继续播放");
record_player.play();
}
});
$(".btn_pause").click(function(){
if(record_player.status == 1)
{
record_player.pause();
}
});
});
</script>
<span style="display:none;"><script src="https://s5.cnzz.com/z_stat.php?id=1275630823&web_id=1275630823" language="JavaScript"></script></span>
</body>
</html>