https://github.com/burakjs/online-xox-nodejs
https://github.com/burakjs/online-xox-nodejs
nodejs socket-io tic-tac-toe typescript xox
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/burakjs/online-xox-nodejs
- Owner: burakJs
- License: mit
- Created: 2025-01-02T20:08:52.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-02T22:43:41.000Z (over 1 year ago)
- Last Synced: 2025-01-23T22:23:46.598Z (over 1 year ago)
- Topics: nodejs, socket-io, tic-tac-toe, typescript, xox
- Language: TypeScript
- Homepage:
- Size: 7.07 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Online XOX Game - Backend Service ๐ฎ
[](https://nodejs.org)
[](https://expressjs.com)
[](https://socket.io)
[](https://typescriptlang.org)
[](https://opensource.org/licenses/MIT)
Real-time multiplayer Tic-tac-toe game server built with Node.js and Socket.IO. Designed to work seamlessly with the Flutter mobile client.
## โจ Features
- ๐ฎ Real-time multiplayer gameplay
- ๐ WebSocket-based communication
- ๐ฏ Game session management
- ๐ก๏ธ Move validation
- ๐ Reconnection support
- ๐งน Automatic cleanup
## ๐ ๏ธ Tech Stack
- **Runtime:** Node.js
- **Framework:** Express.js
- **WebSocket:** Socket.IO
- **Language:** TypeScript
- **Logging:** Winston
- **Utils:** UUID
## ๐๏ธ Project Structure
```
backend/
โโโ src/
โ โโโ config/ # Configuration
โ โโโ models/ # Data models
โ โโโ services/ # Business logic
โ โโโ types/ # TypeScript types
โ โโโ utils/ # Utilities
โ โโโ app.ts # App entry
โโโ package.json
โโโ tsconfig.json
```
## ๐ Getting Started
1. **Clone and Install**
```bash
npm install
```
2. **Environment Setup**
```bash
cp .env.example .env
```
3. **Development**
```bash
npm run dev
```
4. **Production**
```bash
npm run build
npm start
```
## ๐ก WebSocket Events
### Server to Client
```typescript
interface ServerToClientEvents {
game_update: (data: GameState) => void;
game_created: (data: { gameId: string }) => void;
game_joined: (data: GameState) => void;
game_over: (data: { winner?: string, gameState: GameState }) => void;
player_left: (data: { playerId: string }) => void;
error: (data: { message: string, code: string }) => void;
move_error: (data: { message: string }) => void;
}
```
### Client to Server
```typescript
interface ClientToServerEvents {
create_game: (data: { playerName: string }) => void;
join_game: (data: { gameId: string, playerName: string }) => void;
make_move: (data: PlayerMove) => void;
cancel_game: (data: { gameId: string }) => void;
leave_game: (data: { gameId: string }) => void;
disconnect_game: () => void;
}
```
## ๐ฏ Game Rules
1. Two players take turns (X and O)
2. First to get 3 in a row wins
3. Game ends on:
- Win condition met
- Board full (draw)
- Player disconnection
- Game cancellation
## ๐ฑ Mobile Support
- App lifecycle handling
- Efficient reconnection
- Network state management
- Background state handling
## ๐ง Available Scripts
```json
{
"dev": "ts-node-dev --respawn src/app.ts",
"build": "tsc",
"start": "node dist/app.js",
"lint": "eslint . --ext .ts",
"format": "prettier --write \"src/**/*.ts\""
}
```
## ๐งช Testing
To test with Flutter client:
1. Start the backend server
2. Configure client WebSocket URL
3. Test scenarios:
- Game creation/joining
- Move validation
- Disconnection handling
- Game completion
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.