NON-PRODUCTION
Mines — tài liệu ghép client
Chọn ô trên lưới, tránh mìn. Cashout hoặc clear board để nhận thưởng. Client nói HTTP JSON với server game. Trang này chỉ được serve khi ENVIRONMENT != production.
1. Tổng quan
| Mục | Giá trị |
|---|---|
| Board | levels[].row_size × col_size. Size lấy từ /gameplay, đừng hardcode. |
| Index | position tuyến tính row-major: index = row * col_size + col. Ô (0,0) = 0. |
| Tiền | Trừ bet lúc /start (reason BET). WIN lúc /stop hoặc clear board. Nổ mìn = 0, không hoàn bet. |
| Multiplier | Mảng theo số ô an toàn đã mở. current_multiplier sau gem; next_multiplier nếu mở tiếp. |
| Base path | /api/v1 |
Session in-memory. Vào game bắt buộc
GET /api/v1/gameplay. Nếu is_playing thì restore ô đã mở, không gọi /start lại.2. Demo bàn 5×5
Số trên ô = position. Xanh = gem đã mở, đỏ = mìn lộ, xám = chưa mở.
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Ví dụ: ô hàng 3 cột 3 → 3 * 5 + 3 = 18 (mìn). Client highlight theo opened_positions / mine_positions, không tự random mìn.
3. Auth & envelope
Authorization: Bearer <access_token> Content-Type: application/json
Mọi API dưới /api/v1 cần JWT. Trang docs không cần token. HTTP 200 + code = 0 là thành công; payload nằm trong msg.
{
"code": 0,
"msg": { ... }
}
| code | Ý nghĩa |
|---|---|
0 | OK |
-1 | Unknown / thiếu JWT / token invalid (HTTP 401) |
-2 | Invalid input (body JSON sai) |
69 | Wrong game state — chưa /gameplay, đang chơi mà /start, bet/size không hợp lệ, mở ô đã mở |
1000 | Popup error (i18n) |
POST /start bị middleware.Block: user đang room PvP khác → HTTP 400 body "blocked".4. GET /api/v1/gameplay
Gọi 1 lần khi vào. Set session. Thiếu bước này thì action sau trả code 69.
| Field | Type | Client dùng để |
|---|---|---|
user_money | int64 | Chip hiện tại |
bet | int64 | Bet đang chọn trên server |
bets | int64[] | Mức bet hợp lệ — chỉ gửi đúng 1 giá trị này |
show_bets | int64[] | Giá trị hiển thị UI (cùng index với bets) |
levels | Level[] | Size bàn + cấu hình mìn |
is_playing | bool | Đang giữa ván → restore grid |
opened_positions | int[] | Ô gem đã mở (khi playing) |
number_of_mines | int | Số mìn ván hiện tại / mặc định level 0 |
current_multiplier | float | Hệ số cashout hiện tại |
next_multiplier | float | Hệ số nếu mở thêm 1 gem |
current_row_size / current_col_size | int | Kích thước bàn đang chơi |
multipliers | float[] | Toàn bộ nấc hệ số theo số gem đã mở |
Level
| Field | Ý nghĩa |
|---|---|
row_size, col_size | Gửi đúng cặp này khi /start |
mines[] | {number_of_mines, init_multiplier} — số mìn hợp lệ + hệ số lúc 0 gem |
quick_mines | Shortcut UI (vd 1 / 5 / 10) |
{
"code": 0,
"msg": {
"user_money": 500000,
"bet": 1000,
"bets": [200, 1000, 2000, 10000],
"show_bets": [200, 1000, 2000, 10000],
"levels": [
{"row_size": 5, "col_size": 5, "mines": [{"number_of_mines": 3, "init_multiplier": 1.12}], "quick_mines": [1, 3, 5]}
],
"is_playing": true,
"opened_positions": [0, 3, 6, 12],
"number_of_mines": 3,
"current_multiplier": 1.48,
"next_multiplier": 1.72,
"current_row_size": 5,
"current_col_size": 5,
"multipliers": [1.12, 1.28, 1.48, 1.72]
}
}
5. POST /api/v1/start
Debit bet ngay. Không gọi khi is_playing.
| Request | Type | Ý nghĩa |
|---|---|---|
bet | int64 | Phải thuộc bets |
row_size, col_size | int | Một level từ levels |
number_of_mines | int | Một giá trị trong levels[].mines |
cheat_mine_positions | int[]? | Chỉ non-prod / cheater. Index tuyến tính. |
| Response | Ý nghĩa |
|---|---|
user_money | Chip sau khi trừ bet |
bet, number_of_mines, row_size, col_size | Echo config ván |
current_multiplier | 0 lúc mới start (chưa mở ô) |
next_multiplier | Hệ số gem đầu = multipliers[0] |
multipliers | Toàn bộ nấc; length = cells − mines |
POST /api/v1/start
{ "bet": 1000, "row_size": 5, "col_size": 5, "number_of_mines": 3 }
{
"code": 0,
"msg": {
"user_money": 499000,
"bet": 1000,
"number_of_mines": 3,
"current_multiplier": 0,
"next_multiplier": 1.12,
"multipliers": [1.12, 1.28, 1.48, 1.72],
"col_size": 5,
"row_size": 5
}
}
6. POST /api/v1/open
| Field | Khi nào có | Ý nghĩa |
|---|---|---|
position | luôn | Ô vừa mở |
multiplier | gem | = current_multiplier sau gem này |
next_multiplier | còn chơi | Hệ số gem kế |
is_mine | nổ | true → thua, win = 0 |
is_stopped | hết ván | Nổ mìn hoặc đã mở hết ô an toàn |
mine_positions | hết ván | Lộ toàn bộ mìn để vẽ |
win_amount, user_money | clear board | Credit WIN END. Nổ mìn thì không có win |
POST /api/v1/open
{ "position": 6 }
{
"code": 0,
"msg": {
"position": 6,
"multiplier": 1.28,
"next_multiplier": 1.48,
"is_stopped": false,
"is_mine": false,
"user_money": 499000
}
}
{
"code": 0,
"msg": {
"position": 18,
"is_stopped": true,
"is_mine": true,
"mine_positions": [8, 18, 22],
"user_money": 499000
}
}
Mở ô đã mở / ngoài bàn / không đang chơi → code 69. Client disable ô trong
opened_positions.7. POST /api/v1/stop
Cashout. Cần đã mở ≥ 1 gem. Credit round(current_multiplier × bet) reason WIN STOP. Lộ mine_positions.
POST /api/v1/stop
{
"code": 0,
"msg": {
"win_amount": 1480,
"user_money": 500480,
"mine_positions": [8, 18, 22]
}
}
8. GET /top-win · GET /history
GET /api/v1/top-win
{ "code": 0, "msg": { "winners": [{ "rank": 1, "user_id": 1001, "username": "alice", "total_win": 880000 }] } }
GET /api/v1/history
{ "code": 0, "msg": { "logs": [{ "user_money": 500480, "win_amount": 1480, "bet": 1000, "multiplier": 1.48, "row_size": 5, "col_size": 5, "created_at": 1720000000 }] } }
9. Luồng ghép
- Mở game →
GET /gameplay. Render levels, bets, money. Nếuis_playing: vẽ gem theoopened_positions, enable Stop. - User chọn bet + size + số mìn →
POST /start. Cập nhậtuser_money, vẽ lưới trống, hiệnnext_multiplier. - Tap ô →
POST /open {position}. Gem: highlight, cập nhật multiplier. Mine: lộmine_positions, kết thúc, win = 0. - Stop bất kỳ lúc đã có gem, hoặc đợi clear hết ô an toàn (server tự credit).
- Luôn lấy chip từ
user_moneycủa response vừa nhận.
10. Error & tiền
| Tình huống | Hành vi client |
|---|---|
| HTTP 401 | Token hết hạn — relogin |
| code 69 | GET /gameplay lại, sync state, đừng spam open |
| code -1 khi start | Có thể hết tiền — refresh money |
HTTP 400 blocked | User đang PvP — không cho start |
11. Checklist client
- Vào game:
GET /gameplaytrước mọi start/open. - Index =
row * col_size + col. Hiện số index lúc debug. - Bet chỉ gửi giá trị trong
bets; size/mines chỉ từlevels. - Không
/startkhiis_playing; restore thay vì ván mới. - Nổ mìn: không cộng chip. Clear / stop: tin
win_amount. - Cheat
cheat_mine_positionschỉ non-prod. - Không gọi song song 2 open — đợi response + animation.