labag 2.2.6 → 2.2.8

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/README.md CHANGED
@@ -1,14 +1,123 @@
1
+
1
2
  # LaBaG
2
3
 
3
- LaBaG 是一款使用 TypeScript 撰寫的拉霸機。
4
- 多模式、多種組合得分,適合用於遊戲開發與教育用途。
4
+ LaBaG 是一款用 TypeScript 撰寫的高彈性拉霸機遊戲引擎,支援多種模式、事件監聽、組合得分,適合用於遊戲開發、教學或自訂玩法。
5
+
6
+ [![npm version](https://img.shields.io/npm/v/labag.svg)](https://www.npmjs.com/package/labag)
7
+
8
+ ---
9
+
10
+ ## 特色
5
11
 
6
- [![npm version](https://img.shields.io/npm/v/labag.svg)](https://www.npmjs.com/package/labag)
12
+ - 支援多種拉霸模式(可自訂/擴充)
13
+ - 圖案與分數組合彈性設定
14
+ - 事件監聽機制,方便擴充互動
15
+ - TypeScript 強型別,易於二次開發
7
16
 
8
17
  ---
9
18
 
10
- ## 安裝方式
19
+ ## 安裝
11
20
 
12
21
  ```bash
13
22
  npm install labag
14
23
  ```
24
+
25
+ ---
26
+
27
+ ## 基本用法
28
+
29
+ ```typescript
30
+ import { labag, modeList, LaBaG } from "labag";
31
+
32
+ labag.init();
33
+ while (labag.isRunning()) {
34
+ labag.play();
35
+ // 可在此取得 labag.patterns, labag.score 等資訊
36
+ }
37
+ console.log(labag.score);
38
+ ```
39
+
40
+ ### 事件監聽
41
+
42
+ ```typescript
43
+ labag.addEventListener("roundEnd", (game) => {
44
+ console.log(game.patterns, game.marginScore, game.score);
45
+ });
46
+ ```
47
+
48
+ ---
49
+
50
+ ## API 介紹
51
+
52
+ ### 主要類別
53
+
54
+ - `LaBaG`:拉霸機主體,管理分數、模式、事件等
55
+ - `Mode`:遊戲模式,決定圖案機率與特殊行為
56
+ - `Pattern`:圖案及分數設定
57
+
58
+ ### 主要方法
59
+
60
+ - `labag.init()`:初始化遊戲
61
+ - `labag.play()`:執行一次拉霸
62
+ - `labag.isRunning()`:判斷是否還可繼續遊玩
63
+ - `labag.addMode(mode)`:新增模式
64
+ - `labag.addEventListener(event, fn)`:註冊事件
65
+
66
+ ### 主要屬性
67
+
68
+ - `labag.score`:目前總分
69
+ - `labag.patterns`:本輪轉出的圖案陣列
70
+ - `labag.modes`:目前所有模式
71
+
72
+ ---
73
+
74
+ ## 內建模式
75
+
76
+ | 模式名稱 | 說明 |
77
+ |------------|--------------------------|
78
+ | normal | 標準機率分布 |
79
+ | greenwei | 特殊加倍與觸發條件 |
80
+ | pikachu | 特殊復活與替換 |
81
+ | superhhh | 高風險高報酬 |
82
+
83
+ 可自訂/擴充模式,詳見 `src/modes/` 範例。
84
+
85
+ ---
86
+
87
+ ## 圖案與分數
88
+
89
+ | 圖案名稱 | 三連分數 | 雙連分數 | 單出分數 |
90
+ |------------|----------|----------|----------|
91
+ | gss | 800 | 400 | 180 |
92
+ | hhh | 1500 | 800 | 300 |
93
+ | hentai | 2500 | 1200 | 500 |
94
+ | handson | 2900 | 1450 | 690 |
95
+ | kachu | 12000 | 8000 | 1250 |
96
+ | rrr | 20000 | 12000 | 2500 |
97
+
98
+ ---
99
+
100
+ ## 事件列表
101
+
102
+ | 事件名稱 | 說明 |
103
+ |----------------|------------------|
104
+ | gameStart | 遊戲開始 |
105
+ | roundStart | 每輪開始 |
106
+ | rollSlots | 轉動產生圖案 |
107
+ | calculateScore | 計算分數 |
108
+ | roundEnd | 每輪結束 |
109
+ | gameOver | 遊戲結束 |
110
+
111
+ ---
112
+
113
+ ## 進階用法
114
+
115
+ - 可自訂模式(繼承 `Mode` 並設定 eventListener)
116
+ - 可自訂圖案與分數
117
+ - 可串接前端 UI 或 CLI
118
+
119
+ ---
120
+
121
+ ## 授權
122
+
123
+ MIT License
package/dist/labag.d.ts CHANGED
@@ -14,6 +14,8 @@ export declare class LaBaG {
14
14
  score: number;
15
15
  /** 邊際分數 */
16
16
  marginScore: number;
17
+ /** 產生的隨機數字 */
18
+ randNums: number[];
17
19
  /** 當前轉出的圖案組合 */
18
20
  patterns: [Pattern | null, Pattern | null, Pattern | null];
19
21
  /** 遊戲模式列表 */
package/dist/labag.js CHANGED
@@ -17,6 +17,8 @@ class LaBaG {
17
17
  score;
18
18
  /** 邊際分數 */
19
19
  marginScore;
20
+ /** 產生的隨機數字 */
21
+ randNums;
20
22
  /** 當前轉出的圖案組合 */
21
23
  patterns;
22
24
  /** 遊戲模式列表 */
@@ -33,6 +35,7 @@ class LaBaG {
33
35
  this.rounds = 0;
34
36
  this.score = 0;
35
37
  this.marginScore = 0;
38
+ this.randNums = [];
36
39
  this.patterns = [null, null, null];
37
40
  this.modes = [];
38
41
  this.eventListeners = {
@@ -131,6 +134,7 @@ class LaBaG {
131
134
  this.played = 0;
132
135
  this.score = 0;
133
136
  this.marginScore = 0;
137
+ this.randNums = [];
134
138
  this.patterns = [null, null, null];
135
139
  this.rounds = 0;
136
140
  this.emit("gameStart");
@@ -151,12 +155,12 @@ class LaBaG {
151
155
  const { ranges } = this.getCurrentConfig();
152
156
  const rangesAcc = ranges.length > 0 ? ranges[ranges.length - 1].threshold : 0;
153
157
  // 產生 3 個隨機數字
154
- const randomNums = [
158
+ this.randNums = [
155
159
  (0, randInt_1.randInt)(1, rangesAcc),
156
160
  (0, randInt_1.randInt)(1, rangesAcc),
157
161
  (0, randInt_1.randInt)(1, rangesAcc),
158
162
  ];
159
- randomNums.forEach((num, index) => {
163
+ this.randNums.forEach((num, index) => {
160
164
  // 根據預先計算的區間找到對應的圖案
161
165
  const match = ranges.find((r) => num <= r.threshold);
162
166
  if (match) {
@@ -43,8 +43,8 @@ exports.default = new mode_1.Mode(false, "greenwei", {
43
43
  }
44
44
  variable.count += gssCount;
45
45
  if (mode.active) {
46
- if (patterns.some((p) => p?.name === "gss")) {
47
- variable.times += 1;
46
+ if (allGSS) {
47
+ variable.times += 2;
48
48
  }
49
49
  if (variable.times <= 0) {
50
50
  mode.active = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labag",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/labag.ts CHANGED
@@ -17,6 +17,8 @@ export class LaBaG {
17
17
  score: number;
18
18
  /** 邊際分數 */
19
19
  marginScore: number;
20
+ /** 產生的隨機數字 */
21
+ randNums: number[];
20
22
  /** 當前轉出的圖案組合 */
21
23
  patterns: [Pattern | null, Pattern | null, Pattern | null];
22
24
  /** 遊戲模式列表 */
@@ -34,6 +36,7 @@ export class LaBaG {
34
36
  this.rounds = 0;
35
37
  this.score = 0;
36
38
  this.marginScore = 0;
39
+ this.randNums = [];
37
40
  this.patterns = [null, null, null];
38
41
  this.modes = [];
39
42
  this.eventListeners = {
@@ -143,6 +146,7 @@ export class LaBaG {
143
146
  this.played = 0;
144
147
  this.score = 0;
145
148
  this.marginScore = 0;
149
+ this.randNums = [];
146
150
  this.patterns = [null, null, null];
147
151
  this.rounds = 0;
148
152
  this.emit("gameStart");
@@ -166,13 +170,13 @@ export class LaBaG {
166
170
  const rangesAcc =
167
171
  ranges.length > 0 ? ranges[ranges.length - 1].threshold : 0;
168
172
  // 產生 3 個隨機數字
169
- const randomNums = [
173
+ this.randNums = [
170
174
  randInt(1, rangesAcc),
171
175
  randInt(1, rangesAcc),
172
176
  randInt(1, rangesAcc),
173
177
  ];
174
178
 
175
- randomNums.forEach((num, index) => {
179
+ this.randNums.forEach((num, index) => {
176
180
  // 根據預先計算的區間找到對應的圖案
177
181
  const match = ranges.find((r) => num <= r.threshold);
178
182
  if (match) {
@@ -44,11 +44,11 @@ export default new Mode(
44
44
  }
45
45
  }
46
46
 
47
- variable.count += gssCount;
47
+ variable.count += gssCount;
48
48
 
49
49
  if (mode.active) {
50
- if (patterns.some((p) => p?.name === "gss")) {
51
- variable.times += 1;
50
+ if (allGSS) {
51
+ variable.times += 2;
52
52
  }
53
53
  if (variable.times <= 0) {
54
54
  mode.active = false;
@@ -85,4 +85,4 @@ export default new Mode(
85
85
  scores: [800, 400, 180],
86
86
  },
87
87
  }
88
- );
88
+ );