Skip to content

Commit ef02465

Browse files
committed
v0.8 : Add "Stage selector"
1 parent dec4f17 commit ef02465

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

Data/Stage/2.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export default {//ここにパズルの初期情報を入れてください。
2+
"size":{
3+
"Height" : 6,
4+
"Width" : 6
5+
},
6+
"target":{
7+
"hand":12,
8+
"score":0//将来的にスコアを目標にしたいので+処理の簡約化のため置いとく
9+
},
10+
"board":{
11+
"obj":[
12+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
13+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
14+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
15+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
16+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
17+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
18+
],
19+
"field":[
20+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
21+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
22+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
23+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
24+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],
25+
[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
26+
]
27+
}
28+
};

Script/puzzle.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ export default () => {
44
const [BASE_SCORE,SCORE_EXPONENT]=[100,1.5];
55
const ANIM_SPEED=100;
66
const SHORTEST_CHAIN=3;
7-
const MAIN_BOARD = document.querySelector("#puz_board");
8-
const DIV_PUZ_DISPLAY = document.querySelector("#puz_display");
9-
const DATALINK = "../Data/Stage/1.js";
7+
const MAIN_BOARD = document.getElementById('puz_board');
8+
const DIV_PUZ_DISPLAY = document.getElementById('puz_display');
109
const [ALT_ORB,ALT_OBJECT,ALT_FIELD] = ["□🔴🔵🟢🟡🟣","□🧱🌸","□🥬"];
1110
// SECTOR_2:変数群
1211
let [chain_now,chainable]=[false,false];
@@ -20,7 +19,7 @@ export default () => {
2019
// onmouce_cell(cell) : チェイン中の処理とかやってます
2120
const endscene = () => {
2221
DIV_PUZ_DISPLAY.style.display="none";
23-
document.querySelector("#move_START").onclick();
22+
document.getElementById('move_START').onclick();
2423
}
2524
const getType = obj => obj[0];
2625
const isnullobj = obj => getType(obj) === 0;
@@ -38,7 +37,7 @@ export default () => {
3837
const object_copy = x => JSON.parse(JSON.stringify(x));
3938
const update_display = () => {
4039
for(let i=0;i<DATA.size.Height;i++)for(let j=0;j<DATA.size.Width;j++)update_cell(i,j);
41-
document.querySelector("#puz_info").innerText = `Score : ${DATA.target.score} Hand : ${DATA.target.hand}`;
40+
document.getElementById('puz_info').innerText = `Score : ${DATA.target.score} Hand : ${DATA.target.hand}`;
4241
}
4342
const obj_erase = obj => [obj[0],obj[1]] = [0,0];
4443
const break_obj = (y,x,ischain,isobj=true) => {
@@ -75,7 +74,7 @@ export default () => {
7574
update_display();
7675
},ANIM_SPEED);
7776
}
78-
const onmouce_cell = cell => {
77+
const chain_connect = cell => {
7978
if(!chain_now) return;
8079
const [CELL_Y,CELL_X] = [cell.target.parentNode.rowIndex,cell.target.cellIndex];
8180
const CELL_COLOR = getType(DATA.board.obj[CELL_Y][CELL_X]);
@@ -125,15 +124,15 @@ export default () => {
125124
const [HEIGHT,WIDTH] = [DATA.size.Height,DATA.size.Width];
126125
PUZ_BOARD_BONE=new Array(HEIGHT).fill().map(_=>Array(WIDTH));
127126
MAIN_BOARD.innerHTML = null;
128-
if(HEIGHT <= 0){console.error(`GUARD! ${HEIGHT} is not positive`); return endscene();}
129-
if(WIDTH <= 0){console.error(`GUARD! ${WIDTH} is not positive`); return endscene();}
127+
if(HEIGHT <= 0){console.error(`GUARD! Height : ${HEIGHT} isn't positive`); return endscene();}
128+
if(WIDTH <= 0){console.error(`GUARD! Height : ${WIDTH} isn't positive`); return endscene();}
130129
for (let i = 0; i < HEIGHT; i++) {
131130
const TR = document.createElement("tr");
132131
TR.classList.add("puz_board_tr");
133132
for (let j = 0; j < WIDTH; j++) {
134133
const TD = document.createElement("td");
135134
TD.classList.add("inboard");
136-
TD.onmouseover = onmouce_cell;
135+
TD.onmouseover = chain_connect;
137136
TD.addEventListener('click',chain_toggler);
138137
TR.appendChild(TD);
139138
TD.innerHTML = `<img src="Pictures/Orbs/0.svg",width="40" height="40" class="notouch upper object" alt=" ">
@@ -149,10 +148,17 @@ export default () => {
149148
adj_list=chain_yx=[];
150149
update_display();
151150
}
151+
/**todo : DATALINK先が存在しないときの処理*/
152152
const startgame = () => {
153+
const StageID = document.getElementById('StageLink').value;
154+
if(isNaN(StageID)){
155+
console.error(`GUARD! StageID ${StageID} is NaN`)
156+
return endscene();
157+
}
158+
const DATALINK = "../Data/Stage/"+StageID+".js";
153159
DIV_PUZ_DISPLAY.style.display="block";
154160
import(DATALINK)
155161
.then(x => {DATA = object_copy(x.default) ; board_init()});
156162
};
157-
document.querySelector("#move_GAME").onclick=startgame;
163+
document.getElementById('move_GAME').onclick=startgame;
158164
}

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<button type="button" id="move_START" class="scene_mover">TP_START</button>
1212
<button type="button" id="move_GAME" class="scene_mover">TP_GAME</button>
1313
<div id="stage_select">
14+
<input type="text" value="1" id="StageLink">
1415
<button type="button" onclick="" id="startbutton">GAME START</button>
1516
</div>
1617
<div id="puz_display" style="display: none">

0 commit comments

Comments
 (0)