Skip to content

Commit e2d2942

Browse files
committed
Refactor isExCellCount to base classes
1 parent e42543d commit e2d2942

File tree

6 files changed

+37
-164
lines changed

6 files changed

+37
-164
lines changed

src/variety-common/Answer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,41 @@ pzpr.classmgr.makeCommon({
973973
code
974974
);
975975
},
976+
checkShadeCount: function() {
977+
this.checkRowsCols(this.isExCellCount, "exShadeNe");
978+
},
979+
getRowsColsValue: function(clist) {
980+
return clist.filter(function(c) {
981+
return c.isShade();
982+
}).length;
983+
},
984+
isExCellCount: function(clist) {
985+
var d = clist.getRectSize(),
986+
bd = this.board;
987+
var count = this.getRowsColsValue(clist);
988+
989+
var result = true;
990+
991+
if (d.x1 === d.x2) {
992+
var exc = bd.getex(d.x1, -1);
993+
if (exc.qnum !== -1 && exc.qnum !== count) {
994+
exc.seterr(1);
995+
result = false;
996+
}
997+
}
998+
if (d.y1 === d.y2) {
999+
var exc = bd.getex(-1, d.y1);
1000+
if (exc.qnum !== -1 && exc.qnum !== count) {
1001+
exc.seterr(1);
1002+
result = false;
1003+
}
1004+
}
1005+
1006+
if (!result) {
1007+
clist.seterr(1);
1008+
}
1009+
return result;
1010+
},
9761011

9771012
//---------------------------------------------------------------------------
9781013
// ans.checkBorderCount() ある交点との周り四方向の境界線の数を判定する(bp==1:黒点が打たれている場合)

src/variety/aquarium.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -377,40 +377,6 @@
377377
clist.seterr(1);
378378
}
379379
}
380-
},
381-
382-
checkShadeCount: function() {
383-
this.checkRowsCols(this.isExCellCount, "exShadeNe");
384-
},
385-
386-
isExCellCount: function(clist) {
387-
var d = clist.getRectSize(),
388-
bd = this.board;
389-
var count = clist.filter(function(c) {
390-
return c.isShade();
391-
}).length;
392-
393-
var result = true;
394-
395-
if (d.x1 === d.x2) {
396-
var exc = bd.getex(d.x1, -1);
397-
if (exc.qnum !== -1 && exc.qnum !== count) {
398-
exc.seterr(1);
399-
result = false;
400-
}
401-
}
402-
if (d.y1 === d.y2) {
403-
var exc = bd.getex(-1, d.y1);
404-
if (exc.qnum !== -1 && exc.qnum !== count) {
405-
exc.seterr(1);
406-
result = false;
407-
}
408-
}
409-
410-
if (!result) {
411-
clist.seterr(1);
412-
}
413-
return result;
414380
}
415381
}
416382
});

src/variety/batten.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -413,40 +413,6 @@
413413
var ca = shaded[0];
414414
var cb = shaded[1];
415415
return ca.bx !== cb.bx && ca.by !== cb.by;
416-
},
417-
418-
checkShadeCount: function() {
419-
this.checkRowsCols(this.isExCellCount, "exShadeNe");
420-
},
421-
422-
isExCellCount: function(clist) {
423-
var d = clist.getRectSize(),
424-
bd = this.board;
425-
var count = clist.filter(function(c) {
426-
return c.isShade();
427-
}).length;
428-
429-
var result = true;
430-
431-
if (d.x1 === d.x2) {
432-
var exc = bd.getex(d.x1, -1);
433-
if (exc.qnum !== -1 && exc.qnum !== count) {
434-
exc.seterr(1);
435-
result = false;
436-
}
437-
}
438-
if (d.y1 === d.y2) {
439-
var exc = bd.getex(-1, d.y1);
440-
if (exc.qnum !== -1 && exc.qnum !== count) {
441-
exc.seterr(1);
442-
result = false;
443-
}
444-
}
445-
446-
if (!result) {
447-
clist.seterr(1);
448-
}
449-
return result;
450416
}
451417
}
452418
});

src/variety/snake.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,6 @@
311311
return !cell.isShade() && cell.qnum > 0;
312312
}, "circleUnshade");
313313
},
314-
315-
checkShadeCount: function() {
316-
this.checkRowsCols(this.isExCellCount, "exShadeNe");
317-
},
318-
319314
checkShadeLoop: function() {
320315
var snakes = this.board.sblkmgr.components;
321316
for (var r = 0; r < snakes.length; r++) {
@@ -338,36 +333,6 @@
338333
}
339334
}
340335
}
341-
},
342-
343-
isExCellCount: function(clist) {
344-
var d = clist.getRectSize(),
345-
bd = this.board;
346-
var count = clist.filter(function(c) {
347-
return c.isShade();
348-
}).length;
349-
350-
var result = true;
351-
352-
if (d.x1 === d.x2) {
353-
var exc = bd.getex(d.x1, -1);
354-
if (exc.qnum !== -1 && exc.qnum !== count) {
355-
exc.seterr(1);
356-
result = false;
357-
}
358-
}
359-
if (d.y1 === d.y2) {
360-
var exc = bd.getex(-1, d.y1);
361-
if (exc.qnum !== -1 && exc.qnum !== count) {
362-
exc.seterr(1);
363-
result = false;
364-
}
365-
}
366-
367-
if (!result) {
368-
clist.seterr(1);
369-
}
370-
return result;
371336
}
372337
}
373338
});

src/variety/statuepark.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,40 +2225,6 @@
22252225
}
22262226
return cell.isShade() && cell.qnum !== cell.getShape();
22272227
}, "csMismatch");
2228-
},
2229-
2230-
checkShadeCount: function() {
2231-
this.checkRowsCols(this.isExCellCount, "exShadeNe");
2232-
},
2233-
2234-
isExCellCount: function(clist) {
2235-
var d = clist.getRectSize(),
2236-
bd = this.board;
2237-
var count = clist.filter(function(c) {
2238-
return c.isShade();
2239-
}).length;
2240-
2241-
var result = true;
2242-
2243-
if (d.x1 === d.x2) {
2244-
var exc = bd.getex(d.x1, -1);
2245-
if (exc.qnum !== -1 && exc.qnum !== count) {
2246-
exc.seterr(1);
2247-
result = false;
2248-
}
2249-
}
2250-
if (d.y1 === d.y2) {
2251-
var exc = bd.getex(-1, d.y1);
2252-
if (exc.qnum !== -1 && exc.qnum !== count) {
2253-
exc.seterr(1);
2254-
result = false;
2255-
}
2256-
}
2257-
2258-
if (!result) {
2259-
clist.seterr(1);
2260-
}
2261-
return result;
22622228
}
22632229
},
22642230
"AnsCheck@pentatouch": {

src/variety/tents.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -651,35 +651,10 @@
651651
checkTentCount: function() {
652652
this.checkRowsCols(this.isExCellCount, "exTentNe");
653653
},
654-
655-
isExCellCount: function(clist) {
656-
var d = clist.getRectSize(),
657-
bd = this.board;
658-
var count = clist.filter(function(c) {
654+
getRowsColsValue: function(clist) {
655+
return clist.filter(function(c) {
659656
return c.getNum() === 2;
660657
}).length;
661-
662-
var result = true;
663-
664-
if (d.x1 === d.x2) {
665-
var exc = bd.getex(d.x1, -1);
666-
if (exc.qnum !== -1 && exc.qnum !== count) {
667-
exc.seterr(1);
668-
result = false;
669-
}
670-
}
671-
if (d.y1 === d.y2) {
672-
var exc = bd.getex(-1, d.y1);
673-
if (exc.qnum !== -1 && exc.qnum !== count) {
674-
exc.seterr(1);
675-
result = false;
676-
}
677-
}
678-
679-
if (!result) {
680-
clist.seterr(1);
681-
}
682-
return result;
683658
}
684659
}
685660
});

0 commit comments

Comments
 (0)