UNO Multiplayer Mini‑Game
Last Update:
Word Count:
Read Time:
Page View: loading...
我自己都没看懂 感觉运行完有些bug
UNO Multiplayer Mini‑Game (Browser + Node/WebSocket)
This project gives you a lightweight, self‑hostable UNO game that you can play with friends in real time. It uses:
- Node.js + Express + ws for a simple WebSocket backend (in‑memory rooms).
- Vanilla HTML/CSS/JS on the client (no build step required).
- Room code invite: Share the room URL or 6‑char room code.
- Standard UNO rules (core set) with user‑selectable house rules.
Good to know: This is a teaching/demo implementation — easy to read, hack, and extend. It is not production hardened (no auth, persistence, or cheating prevention beyond the bare minimum). Perfect for LAN play, study groups, or small friend circles.
1. Features at a Glance
Feature | Included | Notes |
---|---|---|
108‑card official deck | ✅ | 0×1 per color; 1‑9×2; Skip/Reverse/Draw2×2 each; 4 Wild; 4 Wild Draw4 |
Draw pile & discard pile | ✅ | Auto reshuffle when draw pile empty |
Turn order & direction | ✅ | Reverse flips direction (2 players: Reverse = Skip) |
Skip | ✅ | Next player skipped |
Draw Two | ✅ | Next player draws 2 & skips turn |
Wild | ✅ | Player chooses color |
Wild Draw Four | ✅ | Player chooses color, next draws 4 & skips turn (no challenge in core version) |
Call UNO | ✅ | Must click before confirming play when 1 card left; auto‑penalty if missed |
Auto penalty for failure to call UNO | ✅ | +2 cards if next player plays and you hadn’t called UNO |
House rules (optional toggles) | ⚙️ | Allow stacking Draws, 7‑swap, 0‑rotate — off by default |
In‑game chat | ✅ | Quick text chat per room |
Spectator mode | ✅ | Join as spectator (no hand) |
2. Quick Start
Prereqs
- Node.js >= 18
- npm (comes with Node)
Install
1 |
|
Run the Server
1 |
|
Default runs on http://localhost:3000
.
Invite Friends
- Start a room: open the site, enter a Display Name, click Create Room.
- Copy the Room Link (URL) or Room Code.
- Share with friends — they join, pick names, click Join.
- When all ready, host clicks Start Game.
You can also open multiple browser tabs/windows to simulate multiple players when testing.
3. Standard UNO Rules Implemented (Core)
Goal: Be first to shed all your cards. Optional scoring after each round (sum of opponents’ card points) — included as a post‑round summary, not cross‑round tally by default.
Setup
- Shuffle full UNO deck.
- Deal 7 cards each.
- Flip top card to start discard pile; if first card is Action/Wild Draw4, special handling (see implementation notes below).
On Your Turn
You may play a card from your hand that matches color or number/symbol of the top discard. Or play a Wild (any time). If you cannot play, click Draw: you draw 1; if playable, you may immediately play it (one chance). Otherwise turn ends.
Action Cards
- Skip → Next player’s turn is skipped.
- Reverse → Direction flips. With 2 players, Reverse works like Skip.
- Draw Two → Next player draws 2 and loses turn.
- Wild → Playable anytime; you pick new color.
- Wild Draw Four → Choose color; next player draws 4 & skips. No challenge check in core game; treat as always legal.
Calling UNO
If you will have 1 card left after playing, you must click the UNO! checkbox/button before confirming play. If you fail and another player (or system auto‑check) catches before next player completes a valid action, you draw 2 penalty cards.
Round End & Scoring (optional)
If enabled, winner gets sum of point values in others’ hands (standard UNO values: numbers face value; action cards 20; wilds 50). Otherwise just show winner and reset.
4. House Rules (Toggle in Lobby Before Game Starts)
Rule | Default | Description |
---|---|---|
Draw Stacking | Off | Allow stacking Draw2 on Draw2 (and optionally Draw4 on Draw4) so penalty accumulates until someone draws. |
Seven Swap | Off | Playing a 7 lets you swap hands with another player. |
Zero Rotate | Off | Playing a 0 rotates all hands in direction of play. |
Force Play After Draw | On | If drawn card playable, auto‑offer immediate play. |
5. Project Structure
1 |
|
For simplicity in this teaching version, all code appears in this single document below. When you set up the project, create the files as shown.
6. package.json
1 |
|
7. game-logic.js
Pure server‑side state + rules. No network calls here; just functions.
1 |
|
8. server.js
WebSocket room management + turn enforcement + broadcast state.
1 |
|
9. public/index.html
Minimal single‑page UI. Uses DOM views: Lobby, Game, RoundEnd.
1 |
|
10. public/style.css
Basic layout. Customize freely.
1 |
|
11. public/client.js
Handles UI, connects to server, sends actions.
1 |
|
12. Running on Local Network (LAN)
- Make sure all players are on the same Wi‑Fi.
- Start the server on one machine:
npm start
. - Determine that machine’s LAN IP (e.g.,
192.168.1.23
). - Others browse to
http://192.168.1.23:3000
. - Host creates room; others join using the 6‑char room code.
13. Deploying to the Internet (Optional)
- Use a small VPS (e.g., DigitalOcean, Lightsail).
- Install Node, copy project, run behind nginx reverse proxy with HTTPS.
- Or deploy via services like Render / Railway / Fly.io (all support Node + WebSocket).
14. How to Play Walkthrough (Step‑by‑Step)
A. Host Steps
- 打开站点 → 输入昵称 → 勾选或不勾选自定义规则 → 点击 创建。
- 复制房间码并发送给好友。
- 等所有人加入后点击 开始游戏。
B. 玩家步骤
- 打开链接或输入房间码加入。
- 选择是否旁观;点击 加入。
- 等待房主开始。
C. 游戏回合
- 轮到你时,点击一张可出的牌。如果是 Wild / +4,会弹出提示让你选择颜色。
- 没牌可出?点 摸牌。
- 出完倒数第二张牌时记得点 **UNO!**(或先点 UNO 再出牌)。
- 聊天框可发消息。
15. Extending the Game
- 断线重连(存储房间状态并按 playerId 重新连接)
- Github OAuth 登录 & 头像
- 观战界面显示所有牌(教学模式)
- 自动计分多轮比赛到 500 分
- 牌面 SVG 美化(当前使用文字简化)
16. Troubleshooting
问题 | 可能原因 | 解决 |
---|---|---|
加不进房间 | 房间码错 / 服务端未运行 | 确认终端里 server 正在运行;复制房间码重新输入 |
出不了牌 | 不匹配颜色/数字;轮次不对 | 确认是否轮到你;检查提示颜色 |
Wild 没换色 | 浏览器弹窗被拦截? | 关闭弹窗拦截;或改成内嵌颜色选择 UI |
UNO 罚牌 | 忘记点 UNO 按钮 | 出倒数第二张牌前养成点 UNO 的习惯 |
祝你和朋友玩得开心!
如果你希望我帮你:打包 zip、改中文界面、添加动画、或用 React 重构,请告诉我!
reward

