labag 2.6.1 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/labag.d.ts CHANGED
@@ -19,10 +19,10 @@ export declare class LaBaG {
19
19
  /** 當前轉出的圖案組合 */
20
20
  patterns: [Pattern | null, Pattern | null, Pattern | null];
21
21
  /** 遊戲模式列表 */
22
- modes: Mode<Record<string, any>>[];
22
+ modes: Mode[];
23
23
  /** 事件監聽器列表 */
24
24
  eventListeners: Record<LaBaGEvent, ((game: LaBaG) => void)[]>;
25
- __defaultMode__: Mode<{}, "normal">;
25
+ __defaultMode__: Mode;
26
26
  constructor(times?: number);
27
27
  /**
28
28
  * 觸發指定事件。
@@ -94,6 +94,6 @@ export declare class LaBaG {
94
94
  roundEnd(): void;
95
95
  gameOver(): void;
96
96
  play(): void;
97
- getModes(name: ModeName): Mode<Record<string, any>, string>[];
97
+ getMode(name: ModeName): Mode<Record<string, any>, string> | undefined;
98
98
  get isRunning(): boolean;
99
99
  }
package/dist/labag.js CHANGED
@@ -86,7 +86,7 @@ class LaBaG {
86
86
  game.patterns[i] = matchedPattern;
87
87
  }
88
88
  },
89
- calculateScore: (game) => {
89
+ calculateScore: (game, mode) => {
90
90
  const [p1, p2, p3] = game.patterns;
91
91
  if (!p1 || !p2 || !p3) {
92
92
  game.marginScore = 0;
@@ -112,20 +112,24 @@ class LaBaG {
112
112
  this.marginScore += p1.scores[1];
113
113
  this.marginScore += p2.scores[2];
114
114
  }
115
- this.marginScore = Math.round(this.marginScore / 1.4);
115
+ this.marginScore = Math.round(this.marginScore / mode.variable.twoMatchDivisor);
116
116
  }
117
117
  else {
118
118
  // 三個圖案皆不同
119
119
  this.marginScore += p1.scores[2];
120
120
  this.marginScore += p2.scores[2];
121
121
  this.marginScore += p3.scores[2];
122
- this.marginScore = Math.round(this.marginScore / 3);
122
+ this.marginScore = Math.round(this.marginScore / mode.variable.allDifferentDivisor);
123
123
  }
124
124
  },
125
125
  roundEnd: (game) => {
126
126
  game.score += game.marginScore;
127
127
  },
128
128
  },
129
+ variable: {
130
+ twoMatchDivisor: 1.4,
131
+ allDifferentDivisor: 3,
132
+ },
129
133
  });
130
134
  this.addMode(this.__defaultMode__);
131
135
  }
@@ -269,8 +273,8 @@ class LaBaG {
269
273
  this.gameOver();
270
274
  }
271
275
  }
272
- getModes(name) {
273
- return this.modes.filter((m) => m.name === name);
276
+ getMode(name) {
277
+ return this.modes.find((m) => m.name === name);
274
278
  }
275
279
  get isRunning() {
276
280
  return this.played < this.times;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labag",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/labag.ts CHANGED
@@ -22,11 +22,11 @@ export class LaBaG {
22
22
  /** 當前轉出的圖案組合 */
23
23
  patterns: [Pattern | null, Pattern | null, Pattern | null];
24
24
  /** 遊戲模式列表 */
25
- modes: Mode<Record<string, any>>[];
25
+ modes: Mode[];
26
26
  /** 事件監聽器列表 */
27
27
  eventListeners: Record<LaBaGEvent, ((game: LaBaG) => void)[]>;
28
28
 
29
- __defaultMode__: Mode<{}, "normal">;
29
+ __defaultMode__: Mode;
30
30
 
31
31
  constructor(times: number = 30) {
32
32
  this.times = times;
@@ -92,7 +92,7 @@ export class LaBaG {
92
92
  game.patterns[i] = matchedPattern;
93
93
  }
94
94
  },
95
- calculateScore: (game) => {
95
+ calculateScore: (game, mode) => {
96
96
  const [p1, p2, p3] = game.patterns;
97
97
  if (!p1 || !p2 || !p3) {
98
98
  game.marginScore = 0;
@@ -117,19 +117,27 @@ export class LaBaG {
117
117
  this.marginScore += p1.scores[1];
118
118
  this.marginScore += p2.scores[2];
119
119
  }
120
- this.marginScore = Math.round(this.marginScore / 1.4);
120
+ this.marginScore = Math.round(
121
+ this.marginScore / mode.variable.twoMatchDivisor,
122
+ );
121
123
  } else {
122
124
  // 三個圖案皆不同
123
125
  this.marginScore += p1.scores[2];
124
126
  this.marginScore += p2.scores[2];
125
127
  this.marginScore += p3.scores[2];
126
- this.marginScore = Math.round(this.marginScore / 3);
128
+ this.marginScore = Math.round(
129
+ this.marginScore / mode.variable.allDifferentDivisor,
130
+ );
127
131
  }
128
132
  },
129
133
  roundEnd: (game) => {
130
134
  game.score += game.marginScore;
131
135
  },
132
136
  },
137
+ variable: {
138
+ twoMatchDivisor: 1.4,
139
+ allDifferentDivisor: 3,
140
+ },
133
141
  });
134
142
  this.addMode(this.__defaultMode__);
135
143
  }
@@ -290,8 +298,8 @@ export class LaBaG {
290
298
  }
291
299
  }
292
300
 
293
- getModes(name: ModeName) {
294
- return this.modes.filter((m) => m.name === name);
301
+ getMode(name: ModeName) {
302
+ return this.modes.find((m) => m.name === name);
295
303
  }
296
304
 
297
305
  get isRunning() {