Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doppelblock: Add support for qnum in Cell #512

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions src/variety/doppelblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
},
mouseinput_number: function() {
if (this.mousestart) {
if (this.puzzle.editmode) {
this.inputqnum_excell();
} else {
if (!this.puzzle.editmode || !this.inputqnum_excell()) {
this.inputqnum();
}
}
Expand All @@ -33,9 +31,7 @@
}
}
} else if (this.puzzle.editmode) {
if (this.mousestart) {
this.inputqnum_excell();
}
this.mouseinput_number();
}
},

Expand All @@ -53,10 +49,11 @@
},

getNewNumber: function(cell, val) {
var bound = this.puzzle.editmode ? -1 : -3;
if (this.btn === "left") {
val = val + 1;
if (val > cell.getmaxnum()) {
return -3;
return bound;
} else {
var minnum = cell.getminnum();
if (val >= 0 && val < minnum) {
Expand All @@ -66,7 +63,7 @@
}
} else if (this.btn === "right") {
val = val - 1;
if (val < -3) {
if (val < bound) {
return cell.getmaxnum();
} else {
if (val >= 0 && val < cell.getminnum()) {
Expand All @@ -80,12 +77,18 @@
},

inputDot: function() {
this.inputFixedNumber(-2);
},
inputShade: function() {
this.inputFixedNumber(-3);
},
inputFixedNumber: function(num) {
var cell = this.getcell();
if (cell.isnull) {
return;
}
if (this.inputData === null) {
this.inputData = cell.getNum() === -2 ? -1 : -2;
this.inputData = cell.getNum() === num ? -1 : num;
}

cell.setNum(this.inputData);
Expand All @@ -99,12 +102,6 @@
KeyEvent: {
enablemake: true,
enableplay: true,
moveTarget: function(ca) {
if (this.puzzle.playmode) {
return this.moveTCell(ca);
}
return this.moveExCell(ca);
},
keyinput: function(ca) {
if (this.puzzle.playmode) {
var isSnum = this.cursor.targetdir !== 0;
Expand All @@ -124,6 +121,8 @@
var excell = this.cursor.getex();
if (!excell.isnull) {
this.key_inputqnum_main(excell, ca);
} else {
this.key_inputqnum(ca);
}
}
}
Expand All @@ -132,6 +131,7 @@
//---------------------------------------------------------
// 盤面管理系
Cell: {
disInputHatena: true,
enableSubNumberArray: true,
numberWithMB: true,

Expand All @@ -140,10 +140,13 @@
},

noNum: function() {
return this.anum < 0 && this.qans !== 1;
return this.qnum < 0 && this.anum < 0 && this.qans !== 1;
},

getNum: function() {
if (this.qnum !== -1) {
return this.qnum;
}
if (this.anum > 0) {
return this.anum;
}
Expand All @@ -157,6 +160,18 @@
},

setNum: function(val) {
if (this.puzzle.editmode) {
this.setQnum(val);
this.setAnum(-1);
this.setQsub(0);
this.setQans(0);
this.clrSnum();
return;
}
if (this.qnum !== -1) {
return;
}

if (val > 0) {
this.setAnum(val);
this.setQsub(0);
Expand Down Expand Up @@ -225,6 +240,7 @@

this.drawSubNumbers();
this.drawAnsNumbers();
this.drawQuesNumbers();
this.drawNumbersExCell();

this.drawChassis();
Expand All @@ -237,9 +253,17 @@
Encode: {
decodePzpr: function(type) {
this.decodeNumber16ExCell();
this.decodeNumber16();
},
encodePzpr: function(type) {
this.encodeNumber16ExCell();
if (
this.board.cell.some(function(b) {
return b.qnum !== -1;
})
) {
this.encodeNumber16();
}
}
},
//---------------------------------------------------------
Expand All @@ -258,6 +282,10 @@
} else if (obj.group === "excell") {
obj.qnum = +ca;
} else if (obj.group === "cell") {
if (ca[0] === "q") {
obj.qnum = +ca.substr(1);
return;
}
if (ca.indexOf("[") >= 0) {
ca = this.setCellSnum(obj, ca);
}
Expand All @@ -278,6 +306,9 @@
return "" + obj.qnum + " ";
}
} else if (obj.group === "cell") {
if (obj.qnum !== -1) {
return "q" + obj.qnum + " ";
}
var ca = ".";
if (obj.anum !== -1) {
ca = "" + obj.anum;
Expand Down Expand Up @@ -353,8 +384,9 @@
}
} else if (shaded === 1) {
sumlist.add(cell);
if (cell.anum > 0) {
sum += cell.anum;
var n = cell.getNum();
if (n > 0) {
sum += n;
}
}
}
Expand Down
50 changes: 49 additions & 1 deletion test/script/doppelblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,58 @@ ui.debug.addDebugData("doppelblock", {
"nmSum",
"pzprv3/doppelblock/5/5/. . 6 . 3 4 /. . . . . . /1 - 1 - 2 3 /0 1 - 3 - 2 /. . . . . . /. . . . . . /"
],
[
null,
"pzprv3/doppelblock/5/5/. . 6 . 3 4 /. 3 - 2 1 - /1 - 1 - 2 3 /0 2 q3 - - 1 /. - 2 1 3 - /. 1 - 3 - 2 /",
{ skiprules: true }
],
[
null,
"pzprv3/doppelblock/5/5/. . 6 . 3 4 /. 3 - 2 1 - /1 - 1 - 2 3 /0 2 3 - - 1 /. - 2 1 3 - /. 1 - 3 - 2 /"
]
],
inputs: []
inputs: [
{
input: [
"newboard,4,4",
"editmode",
"cursor,3,-1",
"key,2",
"cursor,3,3",
"mouse,left,3,3"
],
result:
"pzprv3/doppelblock/4/4/. . 2 . . /. . . . . /. . q1 . . /. . . . . /. . . . . /"
},
{
input: ["playmode", "cursor,1,3", "key,1,right,2,right,2"],
result:
"pzprv3/doppelblock/4/4/. . 2 . . /. . . . . /. 1 q1 2 . /. . . . . /. . . . . /"
},
{
input: [
"playmode,shade",
"mouse,left,1,3,7,3",
"playmode,objblank",
"mouse,left,7,7"
],
result:
"pzprv3/doppelblock/4/4/. . 2 . . /. . . . . /. - q1 - - /. . . . . /. . . . + /"
},
{
input: [
"playmode,auto",
"cursor,1,3",
"mouse,left,1,3",
"cursor,5,3",
"mouse,leftx2,5,3",
"cursor,3,1",
"mouse,right,3,1",
"cursor,3,5",
"mouse,rightx3,3,5"
],
result:
"pzprv3/doppelblock/4/4/. . 2 . . /. . + . . /. + q1 . - /. . 2 . . /. . . . + /"
}
]
});