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
window.addEventListener("load", function() { var divs = document.getElementsByClassName("tsume-shogi"); [].forEach.call(divs, function(div) { new _tsume_shogi(div); }); }); function _tsume_shogi(div) { div.classList.add("shogi-container"); var params = [ [_label.KYOUCHOU, 0, _str.SURU, true, _str.SHINAI, false], [_label.HANTEN, 1, _str.SURU, true, _str.SHINAI, false], ]; var setting = new _setting_panel(div, params, function(index, val) { switch (index) { case 0: view.set_kyouchou(val == "true"); break; case 1: view.set_hanten(val == "true"); break; } view.clean_and_draw(); }); var view = new _edit_view(div); var kifu_io = new _kifu_io(); view.set_kyokumen(_kyokumen.get_empty_kyokumen()); view.clean_and_draw(true); var panel = _util.add_panel(div); var result = _util.create_element("div", "", "result"); panel.appendChild(result); var result_timer = null; function show_result(index) { var s; if (index == -1) { s = "不正解"; result.classList.add("wrong"); } else { s = "正解"; result.classList.remove("wrong"); var count = ans_count(index); if (count != 0) { s += "<span>(別解あり 残り" + count + "つ)</span>"; } } result.innerHTML = s; result_timer = setInterval(blink_result, 1000); blink_result(); } function blink_result() { result.classList.toggle("show"); } function hide_result() { if (result_timer == null) return; clearInterval(result_timer); result_timer = null; result.classList.remove("show"); } _util.add_menu(panel, _label.MONDAI, function(index) { if (ans_flag == undefined) return; hide_result(); if (index == 0) { // 一手戻す controller.back(); view.kifu_edit_start(); } else if (index == 1) { // 解答 if (!confirm(_msg.KAITOU)) return; view.edit_end(); controller.move_to_start(); _util.change_panel(div, 1); } }); panel = _util.add_panel(div); var tesuu; var sasite_path; var controller = new _controller_panel(panel, view, function(count, kyokumen, sasite) { view.set_kyokumen(kyokumen); var s; if (sasite.is_empty_sasite()) { s = tesuu + "手詰め"; } else { s = count + "手目" if (count == tesuu && !view.on_kifu_edit()) s += " 詰上図(" + sasite.to_string() + "まで)"; else s += " " + sasite.to_string(); if (count == tesuu && view.on_kifu_edit()) { view.edit_end(); show_result(sasite_path.get_index( controller.get_sasite_path())); } } setting.set_sasite(s); view.clean_and_draw(true); }); _util.add_menu(panel, _label.KAITOU, function(index) { if (!confirm(_msg.MONDAI)) return; controller.move_to_start(); view.kifu_edit_start(); _util.change_panel(div, 0); }); var ans_flag; function ans_count(index) { ans_flag &= ~(1 << index); var n = 0; var flag = ans_flag; while (flag != 0) { n += flag & 0x1; flag >>>= 1; } return n; } view.set_sasite_callback(controller.next); _util.change_panel(div, 0); get_kifu(div, function(data) { view.set_mochigoma_mode(2); view.set_kyokumen(data[_key.KYOKUMEN]); var sasite_tree = data[_key.SASITE]; sasite_tree.set_tsume(true); sasite_path = new _sasite_path(sasite_tree.get_root()); tesuu = sasite_path.get_len(); controller.set_sasite_tree(sasite_tree); ans_flag = (1 << sasite_path.get_count()) - 1; view.draw(); view.kifu_edit_start(); }); }