@@ -4,23 +4,29 @@ interface point {
44 y : number ;
55}
66/**@todo Dateオブジェクトなど、一部のオブジェクトがコピーできないのでその対策。 */
7- const object_copy = ( obj : any ) => JSON . parse ( JSON . stringify ( obj ) ) ;
7+ const object_copy = ( obj : unknown ) => JSON . parse ( JSON . stringify ( obj ) ) ;
88
99/**
1010 * Array.someのobject版です。
1111 */
12- const objectSome = ( obj : any , func : any ) => Object . keys ( obj ) . some ( x => func ( obj [ x ] ) ) ;
12+ const objectSome = < T > ( obj : Record < string , T > , func : ( x :T ) => boolean ) => Object . keys ( obj ) . some ( x => func ( obj [ x ] ) ) ;
13+ const enum ENUM_STATUS {
14+ "CHAINING" ,
15+ "IDLE" ,
16+ "ANIMATION"
17+ } ;
18+ import type { Board } from "../Data/Stage/format.ts" ;
1319export default class scenePuzzle {
1420 // SECTOR_1:定数群
15- scenes : any = { } ;
16- constructor ( scenes : any ) {
21+ scenes : { start ?: any } = { start : undefined } ;
22+ constructor ( scenes : { start ?: any } ) {
1723 this . scenes = scenes ;
1824 }
1925 SAVER = new dataSaver ( "savedata" ) ;
2026 ORB_COLORS = 5 as const ;
2127 BASE_SCORE = 100 as const ;
2228 SCORE_EXPONENT = 1.5 as const ;
23- ANIM_SPEED = 100 as const ;
29+ ANIM_SPEED = 200 as const ;
2430 SHORTEST_CHAIN = 3 as const ;
2531 CONTINUE_BONUS = 5 as const ;
2632 CONTINUE_COST = 100 as const ;
@@ -31,14 +37,13 @@ export default class scenePuzzle{
3137 ALT_ORB = "□🔴🔵🟢🟡🟣" as const ;
3238 ALT_OBJECT = "□🧱🌸" as const ;
3339 ALT_FIELD = "□🥬" as const ;
34- ENUM_STATUS = Object . freeze ( { CHAINING : 0 , IDLE : 1 , ANIMATION : 2 } ) ;
3540 // SECTOR_2:変数群
36- game_state : number = this . ENUM_STATUS . CHAINING ;
41+ game_state : number = ENUM_STATUS . CHAINING ;
3742 chain_color : number = - 1 ;
3843 chain_yx : point [ ] = [ ] ; //[i].(x | y)
3944 //SECTOR_2.5:準const変数群
4045 PUZ_BOARD_BONE : HTMLElement [ ] [ ] = [ ] ;
41- DATA : { [ x : string ] : any } = { } ;
46+ DATA : Board = { } as Board ;
4247 STAGE_ID : number = - 1 ;
4348 // SECTOR 3 : 関数群
4449 endscene ( err : Error | null = null , wasSuccess = false ) {
@@ -58,12 +63,12 @@ export default class scenePuzzle{
5863 return true ;
5964 } ;
6065 addScore ( score_mult : number , base = this . BASE_SCORE ) { this . DATA . target . score += Math . floor ( base * score_mult ) } ;
61- getType ( obj : any [ ] ) { return obj [ 0 ] } ;
62- getCellPos ( cell : { target : any } ) { return [ cell . target . parentNode . rowIndex , cell . target . cellIndex ] } ;
63- isnullobj ( obj : any [ ] ) { return this . getType ( obj ) === 0 ; }
64- fallable ( obj : any [ ] ) { return this . getType ( obj ) > 0 || [ - 2 ] . includes ( this . getType ( obj ) ) ; }
65- is_adj_break ( obj : any [ ] ) { return [ - 2 ] . includes ( this . getType ( obj ) ) ; }
66- dest_sync ( field : any [ ] ) { return [ 1 ] . includes ( this . getType ( field ) ) } ;
66+ getType ( obj : number [ ] ) { return obj [ 0 ] } ;
67+ getCellPos ( cell : { target : any } ) : [ number , number ] { return [ cell . target . parentNode . rowIndex , cell . target . cellIndex ] } ;
68+ isnullobj ( obj : number [ ] ) { return this . getType ( obj ) === 0 ; }
69+ fallable ( obj : number [ ] ) { return this . getType ( obj ) > 0 || [ - 2 ] . includes ( this . getType ( obj ) ) ; }
70+ is_adj_break ( obj : number [ ] ) { return [ - 2 ] . includes ( this . getType ( obj ) ) ; }
71+ dest_sync ( field : number [ ] ) { return [ 1 ] . includes ( this . getType ( field ) ) } ;
6772 alt_text ( type : number , isobj : boolean ) { return isobj ? ( type < 0 ? this . ALT_OBJECT [ - type ] : this . ALT_ORB [ type ] ) : this . ALT_FIELD [ type ] ; }
6873 get_img ( type : number , isobj : boolean ) { return `<img src="Pictures/${
6974 isobj ? "Orbs" : "Fields"
@@ -97,7 +102,7 @@ export default class scenePuzzle{
97102 . map ( type => this . get_img ( type , false ) + "x" + String ( this . DATA . target . field [ type ] ) )
98103 . toString ( ) ) ;
99104
100- obj_erase ( obj : any [ ] ) { [ obj [ 0 ] , obj [ 1 ] ] = [ 0 , 0 ] } ;
105+ obj_erase ( obj : unknown [ ] ) { [ obj [ 0 ] , obj [ 1 ] ] = [ 0 , 0 ] } ;
101106 break_obj ( y : number , x : number , ischain : boolean , isobj = true ) {
102107 const TARGET = isobj ? this . DATA . board . obj [ y ] [ x ] : this . DATA . board . field [ y ] [ x ] ;
103108 const OBJTYPE = this . getType ( TARGET ) ;
@@ -113,14 +118,14 @@ export default class scenePuzzle{
113118 isobj && this . dest_sync ( this . DATA . board . field [ y ] [ x ] ) && this . break_obj ( y , x , false , false ) ;
114119 }
115120 } ;
116- fall_obj < T > ( obj_from : T [ ] , obj_to : T [ ] ) {
121+ fall_obj ( obj_from : number [ ] , obj_to : number [ ] ) {
117122 if ( ! this . isnullobj ( obj_to ) || ! this . fallable ( obj_from ) ) return false ;
118123 [ obj_to [ 0 ] , obj_to [ 1 ] ] = obj_from ;
119124 this . obj_erase ( obj_from ) ;
120125 return true ;
121126 } ;
122127 falling_orb ( ) {
123- this . game_state = this . ENUM_STATUS . ANIMATION ;
128+ this . game_state = ENUM_STATUS . ANIMATION ;
124129 const FALL_TIMER = setInterval ( ( ) => {
125130 let refall = false ;
126131 for ( let i = this . DATA . size . Height - 1 ; i > 0 ; i -- ) /*性質上、下から探索したほうがいい*/ {
@@ -131,18 +136,18 @@ export default class scenePuzzle{
131136 for ( let j = 0 ; j < this . DATA . size . Width - 1 ; j ++ )
132137 refall = this . fall_obj ( this . DATA . board . obj [ i - 1 ] [ j ] , this . DATA . board . obj [ i ] [ j + 1 ] ) || refall ; //R-shift
133138 }
134- this . DATA . board . obj [ 0 ] = this . DATA . board . obj [ 0 ] . map ( ( x : any [ ] ) =>
139+ this . DATA . board . obj [ 0 ] = this . DATA . board . obj [ 0 ] . map ( ( x : [ number , number ] ) =>
135140 this . isnullobj ( x ) ? ( ( refall = true ) , [ ~ ~ ( Math . random ( ) * this . ORB_COLORS ) + 1 , 1 ] ) : x
136141 ) ;
137142 if ( ! refall ) {
138143 clearInterval ( FALL_TIMER ) ;
139- this . game_state = this . ENUM_STATUS . IDLE ;
144+ this . game_state = ENUM_STATUS . IDLE ;
140145 }
141146 this . update_display ( ) ;
142147 } , this . ANIM_SPEED ) ;
143148 } ;
144149 chain_connect ( cell : { target : any } ) {
145- if ( this . game_state !== this . ENUM_STATUS . CHAINING ) return ;
150+ if ( this . game_state !== ENUM_STATUS . CHAINING ) return ;
146151 const [ CELL_Y , CELL_X ] = this . getCellPos ( cell ) ;
147152 const CELL_COLOR = this . getType ( this . DATA . board . obj [ CELL_Y ] [ CELL_X ] ) ;
148153 const CHAIN_LAST = this . chain_yx . at ( - 1 ) as point ;
@@ -175,9 +180,10 @@ export default class scenePuzzle{
175180 ) ;
176181 this . update_display ( ) ;
177182 this . falling_orb ( ) ;
183+ } else {
184+ this . game_state = ENUM_STATUS . IDLE ;
178185 }
179186 if ( this . gameClear ( ) ) return ;
180- this . game_state = this . ENUM_STATUS . IDLE ;
181187 this . chain_yx . forEach ( pos => {
182188 const target = this . PUZ_BOARD_BONE [ pos . y ] [ pos . x ] . querySelector ( "img" ) ! ;
183189 target . classList . remove ( "chaining" ) ;
@@ -186,34 +192,36 @@ export default class scenePuzzle{
186192 this . chain_yx = [ ] ;
187193 if ( this . DATA . target . hand <= 0 ) {
188194 if (
189- this . SAVER . getData ( [ " haveCoin" ] ) >= this . CONTINUE_COST &&
195+ this . SAVER . data . haveCoin >= this . CONTINUE_COST &&
190196 confirm ( `コンテニューしますか?(手数+${ this . CONTINUE_BONUS } )` )
191197 ) {
192198 this . DATA . target . hand += this . CONTINUE_BONUS ;
193- this . SAVER . setData ( [ "haveCoin" ] , this . SAVER . getData ( [ "haveCoin" ] ) - this . CONTINUE_COST ) ;
199+ this . SAVER . data . haveCoin -= this . CONTINUE_COST ;
200+ this . SAVER . save ( ) ;
194201 return ;
195202 }
196203 alert ( `ゲームオーバー! スコアは${ this . DATA . target . score } でした!` ) ;
197204 this . endscene ( null , false ) ;
198205 }
199206 } ;
200207 chain_start ( cell : { target : any } ) {
208+ if ( this . game_state !== ENUM_STATUS . IDLE ) return ;
201209 const [ CELL_Y , CELL_X ] = this . getCellPos ( cell ) ;
202210 const CELL_COLOR = this . getType ( this . DATA . board . obj [ CELL_Y ] [ CELL_X ] ) ;
203211 if ( CELL_COLOR <= 0 ) return ;
204- this . game_state = this . ENUM_STATUS . CHAINING ;
212+ this . game_state = ENUM_STATUS . CHAINING ;
205213 this . chain_color = CELL_COLOR ;
206214 this . chain_yx . push ( { x : CELL_X , y : CELL_Y } ) ;
207215 cell . target . querySelector ( "img" ) . classList . add ( "chaining" ) ;
208216 } ;
209217 chain_toggler ( cell : any ) {
210218 switch ( this . game_state ) {
211- case this . ENUM_STATUS . ANIMATION :
219+ case ENUM_STATUS . ANIMATION :
212220 return ;
213- case this . ENUM_STATUS . CHAINING :
221+ case ENUM_STATUS . CHAINING :
214222 this . chain_over ( ) ;
215223 break ;
216- case this . ENUM_STATUS . IDLE :
224+ case ENUM_STATUS . IDLE :
217225 this . chain_start ( cell ) ;
218226 break ;
219227 default :
0 commit comments