Skip to content

Commit 4e602ef

Browse files
committed
バグ対策でいろいろ変更
1 parent 412f119 commit 4e602ef

File tree

2 files changed

+43
-53
lines changed

2 files changed

+43
-53
lines changed

Script/script.js

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
// SECTOR_1:定数群
23
const ORB_COLORS=5;
34
const [BASE_SCORE,SCORE_EXPONENT]=[100,1.5];
@@ -21,7 +22,6 @@ let DATA={};
2122
// obj_erase(y,x,draw=false) : 指定したマスを消す。drawなら描画する。
2223
// load_board() : [TODO] ファイルからパズルの読み込みをする
2324
// falling_orb() : 関数名通り
24-
// fall_orb_seed() : オーブを落下(1マス分)
2525
// onmouce_cell(cell) : チェイン中の処理とかやってます
2626
// chain_toggler(cell) : 関数名通り
2727
// board_init() : 関数名通り
@@ -33,91 +33,68 @@ const update_cell = (y,x) =>
3333
[`Pictures/Orbs/${DATA.board.obj[y][x][0]}.svg`,`Pictures/Fields/${DATA.board.field[y][x][1]}.svg`];
3434
const object_copy = x => JSON.parse(JSON.stringify(x));
3535

36-
function update_display(){
36+
const update_display = () => {
3737
for(let i=0;i<DATA.size.Height;i++)for(let j=0;j<DATA.size.Width;j++)update_cell(i,j);
3838
document.querySelector("#puz_info").innerText = `Score : ${DATA.target.score} Hand : ${DATA.target.hand}`;
3939
}
40-
function obj_erase(y,x,isobj=true){
41-
const TARGET = isobj?DATA.board.obj[y][x]:DATA.board.field[y][x];
42-
[TARGET[0],TARGET[1]] = [0,0];
40+
const obj_erase = (y,x,isobj=true) => {
41+
(isobj?DATA.board.obj:DATA.board.field)[y][x] = [0,0];
4342
update_cell(y,x);
4443
}
45-
function load_board(){
46-
PUZ_BOARD_BONE=new Array(DATA.size.Height).fill().map(_=>Array(DATA.size.Width));
47-
MAIN_BOARD.innerHTML = null;
48-
for (let i = 0; i < DATA.size.Height; i++) {
49-
const TR = document.createElement("tr");
50-
TR.classList.add("puz_board_tr");
51-
for (let j = 0; j < DATA.size.Width; j++) {
52-
const TD = document.createElement("td");
53-
TD.classList.add("inboard");
54-
TD.onmouseover = onmouce_cell;
55-
TD.addEventListener('click',chain_toggler);
56-
TR.appendChild(TD);
57-
TD.innerHTML = `<img src="Pictures/Orbs/0.svg",width="40" height="40" class="notouch upper object">
58-
<img src="Pictures/Fields/0.svg",width="40" height="40" class="notouch field">`;
59-
PUZ_BOARD_BONE[i][j] = TD;
60-
}
61-
MAIN_BOARD.appendChild(TR);
62-
}
63-
}
64-
function break_obj(y,x,ischain,isobj=true){
44+
const break_obj = (y,x,ischain,isobj=true) => {
6545
const TARGET = isobj?DATA.board.obj[y][x]:DATA.board.field[y][x];
66-
TARGET[1]--;
67-
if(TARGET[1]<=0||ischain){
68-
if(!isobj&&TARGET[0]==1)DATA.target.score+=BASE_SCORE;
46+
if(--TARGET[1]<=0||ischain){
47+
if(!isobj&&TARGET[0] === 1)DATA.target.score+=BASE_SCORE;
6948
obj_erase(y,x,isobj);
7049
isobj && dest_sync(DATA.board.field[y][x][0]) && break_obj(y,x,false,false);
7150
}
7251
}
73-
function fall_obj(yfrom,xfrom,yto,xto){
52+
const fall_obj = (yfrom,xfrom,yto,xto) => {
7453
const [OBJ_TO,OBJ_FROM] = [DATA.board.obj[yto][xto],DATA.board.obj[yfrom][xfrom]];
75-
if(OBJ_TO[0] == 0 && fallable(OBJ_FROM[0]) ){
76-
[OBJ_TO[0],OBJ_TO[1]]=[OBJ_FROM[0],OBJ_FROM[1]];
54+
if(OBJ_TO[0] === 0 && fallable(OBJ_FROM[0]) ){
55+
[OBJ_TO[0],OBJ_TO[1]]=OBJ_FROM;
7756
update_cell(yto,xto);
7857
obj_erase(yfrom,xfrom);
7958
return true;
8059
}
8160
else return false;
8261
}
83-
function falling_orb(){
62+
const falling_orb = () => {
8463
chainable=false;
85-
let fallseedtimer = null;
86-
function fall_orb_seed(){
64+
const FALL_TIMER = setInterval(() => {
8765
let refall=false;
8866
for(let i=DATA.size.Height-1;i>0;i--)/*性質上、下から探索したほうがいい*/{
8967
for(let j=0;j<DATA.size.Width;j++)refall=fall_obj(i-1,j,i,j)||refall;//C-shift
9068
for(let j=1;j<DATA.size.Width;j++)refall=fall_obj(i-1,j,i,j-1)||refall;//L-shift
9169
for(let j=0;j<DATA.size.Width-1;j++)refall=fall_obj(i-1,j,i,j+1)||refall;//R-shift
9270
}
9371
for(let i=0;i<DATA.size.Width;i++){
94-
if(DATA.board.obj[0][i][0]==0){
72+
if(DATA.board.obj[0][i][0] === 0){
9573
DATA.board.obj[0][i]=[~~(Math.random()*ORB_COLORS)+1,1];
9674
refall=true;
9775
}
9876
}
9977
if(!refall){
100-
clearInterval(fallseedtimer);
78+
clearInterval(FALL_TIMER);
10179
chainable=true;
10280
}
10381
update_display();
104-
}
105-
fallseedtimer = setInterval(fall_orb_seed,ANIM_SPEED);
82+
},ANIM_SPEED);
10683
}
107-
function onmouce_cell(cell){
84+
const onmouce_cell = cell => {
10885
const [CELL_Y,CELL_X] = [cell.target.parentNode.rowIndex,cell.target.cellIndex];
10986
const CELL_COLOR = DATA.board.obj[CELL_Y][CELL_X][0];
11087
if(chain_now){
11188
if(Math.abs(chain_yx.at(-1).y-CELL_Y)<=1&&Math.abs(chain_yx.at(-1).x-CELL_X)<=1)/*位置チェック*/{
112-
if(chain_info.color==CELL_COLOR&&!chain_yx.some(e => e.x == CELL_X && e.y == CELL_Y))/*条件チェック*/{
89+
if(chain_info.color === CELL_COLOR&&!chain_yx.some(e => e.x === CELL_X && e.y === CELL_Y))/*条件チェック*/{
11390
cell.target.querySelector("img").classList.add("chaining");
11491
chain_yx.push({x : CELL_X,y : CELL_Y});
11592
chain_info.count++;
11693
}
11794
}
11895
}
11996
}
120-
function chain_toggler(cell){
97+
const chain_toggler = cell => {
12198
if(!chainable)return;
12299
const [CELL_Y,CELL_X] = [cell.target.parentNode.rowIndex,cell.target.cellIndex];
123100
const CELL_COLOR = DATA.board.obj[CELL_Y][CELL_X][0];
@@ -126,26 +103,21 @@ function chain_toggler(cell){
126103
if(!(chain_info.count<SHORTEST_CHAIN)){
127104
DATA.target.score+=~~(chain_info.count**SCORE_EXPONENT*BASE_SCORE);
128105
DATA.target.hand--;
129-
chain_yx.forEach(function(pos){
106+
chain_yx.forEach(pos => {
130107
break_obj(pos.y,pos.x,true);
131108
for(let dy=-1;dy<=1;dy++){
132109
const NEWY=pos.y+dy;
133110
for(let dx=-1;dx<=1;dx++){
134111
const NEWX=pos.x+dx;
135-
if(!DATA.board.obj[NEWY]?.[NEWX])continue;//範囲内か?
136-
if(!adj_list.some(e => e.x == NEWX && e.y == NEWY))adj_list.push({y : NEWY,x : NEWX});
112+
DATA.board.obj[NEWY]?.[NEWX] && (adj_list.some(e => e.x === NEWX && e.y === NEWY) || adj_list.push({y : NEWY,x : NEWX}));
137113
}
138114
}
139115
});
140-
adj_list.forEach(function(pos){
141-
is_adj_break(DATA.board.obj[pos.y][pos.x][0]) && break_obj(pos.y,pos.x,false);
142-
});
116+
adj_list.forEach(pos => is_adj_break(DATA.board.obj[pos.y][pos.x][0]) && break_obj(pos.y,pos.x,false));
143117
update_display();
144118
falling_orb();
145119
}
146-
chain_yx.forEach(function(pos){
147-
PUZ_BOARD_BONE[pos.y][pos.x].querySelector("img").classList.remove("chaining");
148-
});
120+
chain_yx.forEach(pos => PUZ_BOARD_BONE[pos.y][pos.x].querySelector("img").classList.remove("chaining"));
149121
chain_info={count : 0,color : null};
150122
adj_list=chain_yx=[];
151123
if(DATA.target.hand<=0){
@@ -159,7 +131,26 @@ function chain_toggler(cell){
159131
cell.target.querySelector("img").classList.add("chaining");
160132
}
161133
}
162-
function board_init(){
134+
const load_board = () => {
135+
PUZ_BOARD_BONE=new Array(DATA.size.Height).fill().map(_=>Array(DATA.size.Width));
136+
MAIN_BOARD.innerHTML = null;
137+
for (let i = 0; i < DATA.size.Height; i++) {
138+
const TR = document.createElement("tr");
139+
TR.classList.add("puz_board_tr");
140+
for (let j = 0; j < DATA.size.Width; j++) {
141+
const TD = document.createElement("td");
142+
TD.classList.add("inboard");
143+
TD.onmouseover = onmouce_cell;
144+
TD.addEventListener('click',chain_toggler);
145+
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">`;
148+
PUZ_BOARD_BONE[i][j] = TD;
149+
}
150+
MAIN_BOARD.appendChild(TR);
151+
}
152+
}
153+
const board_init = () => {
163154
load_board();
164155
falling_orb();
165156
DATA.target.score=0;

index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html lang="ja">
33
<head>
44
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
65
<meta name="viewport" content="width=device-width, initial-scale=1.0">
76
<title>chain_puzzle</title>
87
<link rel="stylesheet" type="text/css" href="css.css">
@@ -12,6 +11,6 @@
1211
<p id="puz_info">LOADING...</p>
1312
<table class="board" id="puz_board"></table>
1413
</div>
15-
<script src="Script/script.js" type="module"></script>
14+
<script src="Script/script.js" type="module" charset="UTF-8"></script>
1615
</body>
1716
</html>

0 commit comments

Comments
 (0)