Skip to content

Commit cbdecfb

Browse files
committed
Start Button
1 parent 4e602ef commit cbdecfb

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

Script/script.js renamed to Script/puzzle.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const [BASE_SCORE,SCORE_EXPONENT]=[100,1.5];
55
const ANIM_SPEED=100;
66
const SHORTEST_CHAIN=3;
77
const MAIN_BOARD = document.querySelector("#puz_board");
8+
const DIV_PUZ_DISPLAY = document.querySelector("#puz_display");
9+
const DIV_STAGE_SELECT = document.querySelector("#stage_select");
810
const DATALINK = "../Data/Stage/1.js";
11+
const [ALT_ORB,ALT_OBJECT,ALT_FIELD] = ["□🔴🔵🟢🟡🟣","□🧱🌸","□🥬"];
912
// SECTOR_2:変数群
1013
let [chain_now,chainable]=[false,false];
1114
let chain_info={color : null,count : 0};
@@ -25,12 +28,18 @@ let DATA={};
2528
// onmouce_cell(cell) : チェイン中の処理とかやってます
2629
// chain_toggler(cell) : 関数名通り
2730
// board_init() : 関数名通り
31+
// startgame() : 関数名通り
2832
const fallable = obj_type => (obj_type>0)||[-2].includes(obj_type);
2933
const is_adj_break = obj_type => [-2].includes(obj_type);
3034
const dest_sync = field_type => [1].includes(field_type);
31-
const update_cell = (y,x) =>
32-
[PUZ_BOARD_BONE[y][x].querySelector("img.object").src,PUZ_BOARD_BONE[y][x].querySelector("img.field").src] =
33-
[`Pictures/Orbs/${DATA.board.obj[y][x][0]}.svg`,`Pictures/Fields/${DATA.board.field[y][x][1]}.svg`];
35+
const alt_text = (type,isobj) => isobj?(type<0?ALT_OBJECT[-type]:ALT_ORB[type]):ALT_FIELD[type];
36+
const update_cell = (y,x) =>{
37+
const CELL=PUZ_BOARD_BONE[y][x];
38+
[CELL.querySelector("img.object").src,CELL.querySelector("img.field").src,
39+
CELL.querySelector("img.object").alt,CELL.querySelector("img.field").alt] =
40+
[`Pictures/Orbs/${DATA.board.obj[y][x][0]}.svg`,`Pictures/Fields/${DATA.board.field[y][x][0]}.svg`,
41+
alt_text(DATA.board.obj[y][x][0],true),alt_text(DATA.board.field[y][x][0],false)];
42+
}
3443
const object_copy = x => JSON.parse(JSON.stringify(x));
3544

3645
const update_display = () => {
@@ -122,7 +131,8 @@ const chain_toggler = cell => {
122131
adj_list=chain_yx=[];
123132
if(DATA.target.hand<=0){
124133
alert(`ゲームオーバー! スコアは${DATA.target.score}でした!`);
125-
import(DATALINK).then(x => {DATA = object_copy(x.default) ; board_init()});
134+
DIV_STAGE_SELECT.style.display="block";
135+
DIV_PUZ_DISPLAY.style.display="none";
126136
}
127137
}else if(CELL_COLOR>0){//チェイン開始の処理
128138
chain_now=true;
@@ -143,21 +153,27 @@ const load_board = () => {
143153
TD.onmouseover = onmouce_cell;
144154
TD.addEventListener('click',chain_toggler);
145155
TR.appendChild(TD);
146-
TD.innerHTML = `<img src="Pictures/Orbs/0.svg",width="40" height="40" class="notouch upper object">
147-
<img src="Pictures/Fields/0.svg",width="40" height="40" class="notouch field">`;
156+
TD.innerHTML = `<img src="Pictures/Orbs/0.svg",width="40" height="40" class="notouch upper object" alt=" ">
157+
<img src="Pictures/Fields/0.svg",width="40" height="40" class="notouch field" alt=" ">`;
148158
PUZ_BOARD_BONE[i][j] = TD;
149159
}
150160
MAIN_BOARD.appendChild(TR);
151161
}
152162
}
153163
const board_init = () => {
164+
console.log(document.querySelector("#startbutton"));
154165
load_board();
155166
falling_orb();
156-
DATA.target.score=0;
157167
adj_list=chain_yx=[];
158168
update_display();
159169
}
160-
import(DATALINK).then(x => {DATA = object_copy(x.default) ; board_init()});
170+
const startgame = () => {
171+
DIV_STAGE_SELECT.style.display="none";
172+
DIV_PUZ_DISPLAY.style.display="block";
173+
import(DATALINK)
174+
.then(x => {DATA = object_copy(x.default) ; board_init()});
175+
};
176+
document.querySelector("#startbutton").onclick=startgame;
161177
//1~:オーブ
162178
//0:無空間
163179
//~-1:妨害ブロック

index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
<link rel="stylesheet" type="text/css" href="css.css">
88
</head>
99
<body>
10-
<div id="puz_disp">
10+
<div id="stage_select">
11+
<button type="button" onclick="" id="startbutton">GAME START</button>
12+
</div>
13+
<div id="puz_display" style="display: none">
1114
<p id="puz_info">LOADING...</p>
1215
<table class="board" id="puz_board"></table>
1316
</div>
14-
<script src="Script/script.js" type="module" charset="UTF-8"></script>
17+
<script src="Script/puzzle.js" type="module" charset="UTF-8"></script>
1518
</body>
1619
</html>

0 commit comments

Comments
 (0)