A classic Pong game implementation with real-time multiplayer networking support, built in C# using Windows Forms and TCP/IP communication.
- Real-time Multiplayer: Two players can connect and play over a network
- TCP/IP Networking: Reliable client-server architecture
- Smooth Graphics: Anti-aliased rendering with customizable colors
- Game Physics: Realistic ball physics with collision detection
- Score Tracking: Live score display for both players
- Countdown System: 3-second countdown before each game starts
- Auto-reconnection: Clients can reconnect after disconnection
- Cross-platform Server: Console-based server with management commands
The project follows a clean, modular architecture:
Pong/
โโโ Client/ # Client-side components
โ โโโ App/ # Application entry point
โ โโโ Graphics/ # Rendering and UI components
โโโ Server/ # Server-side components
โ โโโ App/ # Server application entry point
โโโ Game/ # Core game logic (shared)
โ โโโ Config/ # Game configuration
โ โโโ Logic/ # Game physics and rules
โ โโโ Network/ # Network communication
โ โโโ State/ # Game state management
โโโ Program.cs # Main application entry point
- .NET 8.0 or later
- Windows OS (for Windows Forms client)
- Visual Studio 2022 or VS Code with C# extension
- Clone the repository:
git clone [your-repository-url]
cd PongClient- Build the solution:
dotnet build- Or open
PongClient.slnin Visual Studio and build.
Run the server from command line:
dotnet run --project Pong -- serverOr from Visual Studio, set command line arguments to server.
The server will start and display:
=====================================
Pong Multiplayer Server v1.0
=====================================
โ Server started successfully!
โ Listening on port 12346
โ Ready to accept player connections
Run the client:
dotnet run --project PongOr simply run without arguments from Visual Studio.
When prompted, enter the server IP address (default: 127.0.0.1 for local play).
- Up Arrow: Move paddle up
- Down Arrow: Move paddle down
- Two players connect to the server
- A 3-second countdown begins
- The ball starts moving automatically
- Players control their paddles to hit the ball
- Score points when the ball passes the opponent's paddle
- Ball speed increases after each paddle hit
- Game continues until a player disconnects
- Player 1 (Blue paddle): Left side of the screen
- Player 2 (Red paddle): Right side of the screen
While the server is running, you can use these commands:
| Command | Description |
|---|---|
help or h |
Show available commands |
status or s |
Display server status |
restart or r |
Restart the server |
clear or cls |
Clear console screen |
quit or exit or q |
Stop server and exit |
Game settings can be modified in GameConfiguration.cs:
public const int FieldWidth = 800;
public const int FieldHeight = 520;public const int PaddleWidth = 10;
public const int PaddleHeight = 100;
public const int PaddleSpeed = 10;public const int BallSize = 20;
public const int BallInitialSpeed = 2;
public const int MaxBallSpeed = 12;public const int ServerPort = 12346;
public const string DefaultServerIP = "127.0.0.1";The game uses a simple text-based protocol over TCP:
MOVE:1- Move paddle downMOVE:-1- Move paddle up
ASSIGN:1- Assign player ID (1 or 2)COUNTDOWN:3- Countdown display (3, 2, 1)START- Game beginsSTATE:x,y,p1y,p2y,s1,s2- Game state updateQUIT- Other player disconnected
The server maintains the authoritative game state and broadcasts updates to all clients at 30 FPS. The state includes:
- Ball position (x, y)
- Ball velocity (x, y)
- Player 1 paddle Y position
- Player 2 paddle Y position
- Player scores
The game implements rectangle-based collision detection for:
- Ball-wall collisions (top/bottom walls)
- Ball-paddle collisions (left/right paddles)
- Goal detection (ball passes paddle boundaries)
-
Connection Failed
- Ensure the server is running
- Check firewall settings
- Verify the correct IP address and port
-
Game Lag
- Check network connection stability
- Ensure server has sufficient resources
-
Client Crashes
- Verify .NET 8.0 is installed
- Check Windows Forms dependencies
The application outputs debug information to the console:
- Connection status
- Player assignments
- Network errors
- Game state changes
Potential improvements for future versions:
- Sound effects and background music
- Multiple game modes (tournament, practice)
- AI opponent for single-player mode
- Improved graphics with animations
- Game replay system
- Player statistics tracking
- Custom paddle colors and themes
- Mobile client support
This project is open source and available under the MIT License.
Enjoy playing Pong Multiplayer! ๐