This project is a simulation of a roulette game using Node.js, WebSocket, and a simple server-client architecture. The server handles the spinning of the roulette and the ball, broadcasts their positions to connected clients, and manages bets placed by clients.
- Roulette and Ball Simulation: Simulates the motion of a roulette and a ball with configurable friction and initial speeds.
- Real-time Updates: Broadcasts the current positions and velocity of the roulette and ball to all connected clients in real-time using WebSocket.
- Bet Management: Allows clients to place bets on specific numbers, colors, or even/odd outcomes. The server calculates and broadcasts the winnings or losses based on the final position of the ball.
- Reset and Restart: Clients can reset the simulation or start a new game.
- Node.js (v14 or higher recommended)
- npm (comes with Node.js)
-
Clone the Repository:
git clone ...
-
Install Dependencies:
npm install
-
Run the Server:
node index.js
The server will start on
http://localhost:3003
.
index.js
: The main server file that handles WebSocket connections, manages the simulation, and processes bets./src
:ball.js
: Contains theBall
class that simulates the motion of the ball on the roulette wheel.roulette.js
: Contains theRoulette
class that simulates the motion of the roulette wheel.
-
Start the Server: Use
npm start
to start the server. -
Connect Clients: Clients should connect to the WebSocket server at
ws://localhost:3003
. -
Place Bets: Clients can place bets by sending the appropriate WebSocket message.
-
Start Simulation: The simulation can be started by sending a
startSimulation
message. -
View Results: The server will broadcast the positions of the ball and roulette in real-time, and the final result will be sent when the ball stops.