|
| 1 | +/* global Set:false */ |
| 2 | +(function(pidlist, classbase) { |
| 3 | + if (typeof module === "object" && module.exports) { |
| 4 | + module.exports = [pidlist, classbase]; |
| 5 | + } else { |
| 6 | + pzpr.classmgr.makeCustom(pidlist, classbase); |
| 7 | + } |
| 8 | +})(["oasis"], { |
| 9 | + //--------------------------------------------------------- |
| 10 | + // マウス入力系 |
| 11 | + MouseEvent: { |
| 12 | + RBShadeCell: true, |
| 13 | + use: true, |
| 14 | + inputModes: { |
| 15 | + edit: ["number", "clear"], |
| 16 | + play: ["shade", "unshade", "peke", "completion"] |
| 17 | + }, |
| 18 | + mouseinput_auto: function() { |
| 19 | + if (this.puzzle.playmode) { |
| 20 | + if (this.mousestart) { |
| 21 | + this.isDraggingPeke = this.puzzle.key.isALT; |
| 22 | + } |
| 23 | + if (this.isDraggingPeke) { |
| 24 | + this.inputpeke(); |
| 25 | + } else if (this.btn === "left" && this.mousestart) { |
| 26 | + if (!this.inputqcmp()) { |
| 27 | + this.inputcell(); |
| 28 | + } |
| 29 | + } else if (this.inputData === null || this.inputData < 20) { |
| 30 | + this.inputcell(); |
| 31 | + } |
| 32 | + } else if (this.puzzle.editmode) { |
| 33 | + if (this.mousestart) { |
| 34 | + this.inputqnum(); |
| 35 | + } |
| 36 | + } |
| 37 | + }, |
| 38 | + inputqcmp: function() { |
| 39 | + var cell = this.getcell(); |
| 40 | + if (cell.isnull || !cell.isNum()) { |
| 41 | + return false; |
| 42 | + } |
| 43 | + |
| 44 | + this.inputData = 20; |
| 45 | + cell.setQcmp(+!cell.qcmp); |
| 46 | + cell.draw(); |
| 47 | + |
| 48 | + this.mousereset(); |
| 49 | + return true; |
| 50 | + } |
| 51 | + }, |
| 52 | + |
| 53 | + //--------------------------------------------------------- |
| 54 | + // キーボード入力系 |
| 55 | + KeyEvent: { |
| 56 | + enablemake: true |
| 57 | + }, |
| 58 | + |
| 59 | + //--------------------------------------------------------- |
| 60 | + // 盤面管理系 |
| 61 | + Cell: { |
| 62 | + numberRemainsUnshaded: true, |
| 63 | + |
| 64 | + maxnum: function() { |
| 65 | + return this.board.cols * this.board.rows - 1; |
| 66 | + }, |
| 67 | + |
| 68 | + isCmp: function() { |
| 69 | + if (!this.isNum()) { |
| 70 | + return false; |
| 71 | + } |
| 72 | + if (this.qcmp === 1) { |
| 73 | + return true; |
| 74 | + } |
| 75 | + if (!this.isValidNum() || !this.puzzle.execConfig("autocmp")) { |
| 76 | + return false; |
| 77 | + } |
| 78 | + return this.countResult(true) === 0; |
| 79 | + }, |
| 80 | + |
| 81 | + countResult: function(explicit) { |
| 82 | + if (!this.isValidNum()) { |
| 83 | + return 0; |
| 84 | + } |
| 85 | + var targets = new Set(); |
| 86 | + for (var dir in this.adjacent) { |
| 87 | + var c = this.adjacent[dir]; |
| 88 | + if (c.isNum()) { |
| 89 | + targets.add(c); |
| 90 | + } |
| 91 | + var group = explicit ? c.autooasis : c.oasis; |
| 92 | + if (group) { |
| 93 | + group.adjclist.each(function(obj) { |
| 94 | + targets.add(obj); |
| 95 | + }); |
| 96 | + } |
| 97 | + } |
| 98 | + targets.delete(this); |
| 99 | + return targets.size - this.qnum; |
| 100 | + }, |
| 101 | + redrawConnected: function() { |
| 102 | + if (this.autooasis) { |
| 103 | + this.autooasis.adjclist.each(function(c) { |
| 104 | + c.draw(); |
| 105 | + }); |
| 106 | + } else { |
| 107 | + for (var dir in this.adjacent) { |
| 108 | + var c = this.adjacent[dir]; |
| 109 | + if (c && c.autooasis) { |
| 110 | + c.redrawConnected(); |
| 111 | + } else if (c && c.isNum()) { |
| 112 | + c.draw(); |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + }, |
| 117 | + |
| 118 | + posthook: { |
| 119 | + qnum: function() { |
| 120 | + var bd = this.board; |
| 121 | + var oasis = new Set(); |
| 122 | + var autooasis = new Set(); |
| 123 | + |
| 124 | + for (var dir in this.adjacent) { |
| 125 | + var c = this.adjacent[dir]; |
| 126 | + if (c && c.oasis) { |
| 127 | + oasis.add(c.oasis); |
| 128 | + } |
| 129 | + if (c && c.autooasis) { |
| 130 | + autooasis.add(c.autooasis); |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + oasis.forEach(function(cmp) { |
| 135 | + bd.oasisgraph.setExtraData(cmp); |
| 136 | + }); |
| 137 | + autooasis.forEach(function(cmp) { |
| 138 | + bd.autooasisgraph.setExtraData(cmp); |
| 139 | + }); |
| 140 | + this.redrawConnected(); |
| 141 | + }, |
| 142 | + qsub: function() { |
| 143 | + this.redrawConnected(); |
| 144 | + } |
| 145 | + } |
| 146 | + }, |
| 147 | + Board: { |
| 148 | + hasborder: 1, |
| 149 | + cols: 8, |
| 150 | + rows: 8, |
| 151 | + |
| 152 | + addExtraInfo: function() { |
| 153 | + this.oasisgraph = this.addInfoList(this.klass.ImplicitOasisGraph); |
| 154 | + this.autooasisgraph = this.addInfoList(this.klass.ExplicitOasisGraph); |
| 155 | + } |
| 156 | + }, |
| 157 | + |
| 158 | + AreaUnshadeGraph: { |
| 159 | + enabled: true |
| 160 | + }, |
| 161 | + "ImplicitOasisGraph:AreaGraphBase": { |
| 162 | + enabled: true, |
| 163 | + relation: { "cell.qans": "node", "cell.qnum": "node", "cell.qsub": "node" }, |
| 164 | + setExtraData: function(component) { |
| 165 | + this.common.setExtraData.call(this, component); |
| 166 | + |
| 167 | + var set = new Set(); |
| 168 | + |
| 169 | + component.clist.each(function(cell) { |
| 170 | + for (var dir in cell.adjacent) { |
| 171 | + var adj = cell.adjacent[dir]; |
| 172 | + if (adj.isNum()) { |
| 173 | + set.add(adj); |
| 174 | + } |
| 175 | + } |
| 176 | + }); |
| 177 | + component.adjclist = new this.klass.CellList(Array.from(set)); |
| 178 | + }, |
| 179 | + |
| 180 | + isnodevalid: function(cell) { |
| 181 | + return cell.isUnshade() && !cell.isNum(); |
| 182 | + }, |
| 183 | + |
| 184 | + getComponentRefs: function(obj) { |
| 185 | + return obj.oasis; |
| 186 | + }, |
| 187 | + setComponentRefs: function(obj, component) { |
| 188 | + obj.oasis = component; |
| 189 | + }, |
| 190 | + getObjNodeList: function(nodeobj) { |
| 191 | + return nodeobj.oasisnodes; |
| 192 | + }, |
| 193 | + resetObjNodeList: function(nodeobj) { |
| 194 | + nodeobj.oasisnodes = []; |
| 195 | + } |
| 196 | + }, |
| 197 | + "ExplicitOasisGraph:ImplicitOasisGraph": { |
| 198 | + isnodevalid: function(cell) { |
| 199 | + return cell.isUnshade() && !cell.isNum() && cell.qsub; |
| 200 | + }, |
| 201 | + getComponentRefs: function(obj) { |
| 202 | + return obj.autooasis; |
| 203 | + }, |
| 204 | + setComponentRefs: function(obj, component) { |
| 205 | + obj.autooasis = component; |
| 206 | + }, |
| 207 | + getObjNodeList: function(nodeobj) { |
| 208 | + return nodeobj.autooasisnodes; |
| 209 | + }, |
| 210 | + resetObjNodeList: function(nodeobj) { |
| 211 | + nodeobj.autooasisnodes = []; |
| 212 | + } |
| 213 | + }, |
| 214 | + |
| 215 | + //--------------------------------------------------------- |
| 216 | + // 画像表示系 |
| 217 | + Graphic: { |
| 218 | + qanscolor: "black", |
| 219 | + gridcolor_type: "LIGHT", |
| 220 | + |
| 221 | + autocmp: "number", |
| 222 | + hideHatena: true, |
| 223 | + |
| 224 | + paint: function() { |
| 225 | + this.drawBGCells(); |
| 226 | + this.drawDotCells(); |
| 227 | + this.drawGrid(); |
| 228 | + this.drawShadedCells(); |
| 229 | + |
| 230 | + this.drawCircledNumbers(); |
| 231 | + |
| 232 | + this.drawChassis(); |
| 233 | + |
| 234 | + this.drawPekes(); |
| 235 | + |
| 236 | + this.drawTarget(); |
| 237 | + }, |
| 238 | + |
| 239 | + getCircleFillColor: function(cell) { |
| 240 | + if (!cell.isNum()) { |
| 241 | + return null; |
| 242 | + } |
| 243 | + return cell.isCmp() ? this.qcmpcolor : this.bgcolor; |
| 244 | + } |
| 245 | + }, |
| 246 | + |
| 247 | + //--------------------------------------------------------- |
| 248 | + // URLエンコード/デコード処理 |
| 249 | + Encode: { |
| 250 | + decodePzpr: function(type) { |
| 251 | + this.decodeNumber16(); |
| 252 | + }, |
| 253 | + encodePzpr: function(type) { |
| 254 | + this.encodeNumber16(); |
| 255 | + } |
| 256 | + }, |
| 257 | + //--------------------------------------------------------- |
| 258 | + FileIO: { |
| 259 | + decodeData: function() { |
| 260 | + this.decodeCellQnum(); |
| 261 | + this.decodeCellQanssubcmp(); |
| 262 | + this.decodeBorderLine(); |
| 263 | + }, |
| 264 | + encodeData: function() { |
| 265 | + this.encodeCellQnum(); |
| 266 | + this.encodeCellQanssubcmp(); |
| 267 | + this.encodeBorderLineIfPresent(); |
| 268 | + }, |
| 269 | + |
| 270 | + decodeCellQanssubcmp: function() { |
| 271 | + this.decodeCell(function(cell, ca) { |
| 272 | + if (ca === "+") { |
| 273 | + cell.qsub = 1; |
| 274 | + } else if (ca === "-") { |
| 275 | + cell.qcmp = 1; |
| 276 | + } else if (ca === "1") { |
| 277 | + cell.qans = 1; |
| 278 | + } |
| 279 | + }); |
| 280 | + }, |
| 281 | + encodeCellQanssubcmp: function() { |
| 282 | + this.encodeCell(function(cell) { |
| 283 | + if (cell.qans === 1) { |
| 284 | + return "1 "; |
| 285 | + } else if (cell.qsub === 1) { |
| 286 | + return "+ "; |
| 287 | + } else if (cell.qcmp === 1) { |
| 288 | + return "- "; |
| 289 | + } else { |
| 290 | + return ". "; |
| 291 | + } |
| 292 | + }); |
| 293 | + } |
| 294 | + }, |
| 295 | + |
| 296 | + //--------------------------------------------------------- |
| 297 | + // 正解判定処理実行部 |
| 298 | + AnsCheck: { |
| 299 | + checklist: [ |
| 300 | + "checkShadeCellExist", |
| 301 | + "checkAdjacentShadeCell", |
| 302 | + "checkConnectUnshadeRB", |
| 303 | + "checkCellNumberLarge", |
| 304 | + "check2x2UnshadeCell++", |
| 305 | + "checkCellNumberSmall", |
| 306 | + "doneShadingDecided" |
| 307 | + ], |
| 308 | + |
| 309 | + checkCellNumberLarge: function() { |
| 310 | + this.checkAllCell(function(cell) { |
| 311 | + return cell.countResult(false) < 0; |
| 312 | + }, "nmOasisGt"); |
| 313 | + }, |
| 314 | + checkCellNumberSmall: function() { |
| 315 | + this.checkAllCell(function(cell) { |
| 316 | + return cell.countResult(false) > 0; |
| 317 | + }, "nmOasisLt"); |
| 318 | + } |
| 319 | + } |
| 320 | +}); |
0 commit comments