Project Overview
A multiplayer implementation of the classic Rock-Paper-Scissors game built with Python's socket programming and Pygame for the graphical interface. The project features secure user authentication, real-time network communication, and robust client-server architecture designed to handle multiple concurrent players.
This project demonstrates advanced networking concepts, security best practices with password hashing, and the implementation of a game protocol that maintains synchronization between multiple clients through a central server with an intuitive GUI interface.



Secure Authentication System
The game implements a comprehensive user authentication system with secure password handling and session management:
User Registration & Login:

Authentication Features:
- User Registration: New users can create accounts with username and password
 - Secure Login: bcrypt password hashing for enhanced security
 - Session Management: Persistent user sessions with reconnection capabilities
 - Login Validation: Proper error handling for failed authentication attempts
 - Multi-User Support: Concurrent user registration and login handling
 
Terminal-Based Interface:


Key Features
Secure Authentication
User registration and login system with bcrypt password hashing for enhanced security.
Pygame GUI Interface
Intuitive graphical user interface built with Pygame for smooth gameplay experience.
Real-Time Multiplayer
Synchronized game state between players with instant move validation and result processing.
Client-Server Architecture
Robust TCP socket communication handling multiple concurrent connections with threading.
Game State Management
Comprehensive tracking of player moves, wins, losses, and tie games with visual feedback.
Cross-Platform Compatibility
Works on Windows, macOS, and Linux with consistent gameplay experience.
Technical Implementation
The project utilizes Python's built-in socket library for network communication, Pygame for the graphical interface, and bcrypt for secure password hashing and user authentication.
Core Technologies:
- Python Sockets - TCP/IP network communication and client-server architecture
 - Pygame - Cross-platform graphics and user interface framework
 - Threading - Concurrent client handling and non-blocking server operations
 - bcrypt - Secure password hashing and verification system
 - JSON Protocol - Structured message formatting between client and server
 
Database & User Management:

# User database structure with secure password hashing
{
    "pjay": "$2b$12$IiI9AUBM61Hv6e38fDtYyjuO8v63jXZdK2FWaSHZIjCFGnKKXtmGy",
    "jenny": "$2b$12$HduIR7wIb/GsuQiYhJStY.yIK3tOpRTCX0jOiJ5eeVZXGr2XuzU40Q6"
}
# Server-side authentication handling
def authenticate_user(username, password):
    with open('users.json', 'r') as f:
        users = json.load(f)
    
    if username in users:
        stored_hash = users[username].encode('utf-8')
        return bcrypt.checkpw(password.encode('utf-8'), stored_hash)
    return False
def register_user(username, password):
    hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
    
    with open('users.json', 'r+') as f:
        users = json.load(f)
        users[username] = hashed_password.decode('utf-8')
        f.seek(0)
        json.dump(users, f, indent=4)
        f.truncate()Game Logic & UI Implementation
The Pygame interface provides an intuitive and responsive user experience with clear visual feedback:
UI Color Scheme & Visual Design:

Game Result Display System:

# Game logic and result display implementation
if (game.winner() == 1 and p == 1) or (game.winner() == 0 and p == 0):
    text = font.render("You Won!", 1, (0, 255, 0))  # Green for win
elif game.winner() == -1:
    text = font.render("Tie Game!", 1, (0, 0, 0))   # Black for tie
else:
    text = font.render("You Lost...", 1, (255, 0, 0))  # Red for loss
# Button creation for game choices
btns = [Button("Rock", 25, 250, (128, 128, 128)),     # Gray
        Button("Scissors", 125, 250, (255, 0, 0)),    # Red  
        Button("Paper", 225, 250, (0, 255, 0))]       # Green
# UI text display with proper positioning
font = pygame.font.SysFont("AvantGarde", 30)
text = font.render("Your Move", 1, (0, 155, 255))    # Blue headers
win.blit(text, (30, 100))
text = font.render("Opponents", 1, (0, 155, 255))
win.blit(text, (200, 100))Button Interaction System:

Multiplayer Gameplay Experience
The game supports real-time multiplayer interaction with smooth synchronization and immediate feedback:
Gameplay Flow:

Game Features:
- Player Matching: Automatic pairing of players waiting in the lobby
 - Move Selection: Intuitive button-based interface for Rock, Paper, Scissors
 - Real-time Feedback: Immediate display of both player moves and results
 - Game Continuation: Seamless transition between rounds for continued play
 - Win/Loss Tracking: Visual indication of game outcomes with color coding
 
Synchronized Game States:


Network Architecture
The game follows a client-server model with the following communication flow:
Server Responsibilities:
- Connection Management - Accept and manage multiple client connections
 - Authentication - Verify user credentials and maintain secure sessions
 - Game Logic - Process moves, determine winners, and maintain game state
 - Player Matching - Pair players and create game instances
 - State Synchronization - Ensure consistent game state across all clients
 
Client Responsibilities:
- User Interface - Handle player input and display game state with Pygame
 - Network Communication - Send moves and receive updates from server
 - Session Management - Maintain connection and handle reconnection scenarios
 - Input Validation - Ensure valid moves before sending to server
 - Visual Feedback - Provide immediate response to user interactions
 
# Client-server communication structure
class GameClient:
    def __init__(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server_ip = "localhost"
        self.port = 5555
        
    def connect(self):
        try:
            self.socket.connect((self.server_ip, self.port))
            return self.socket.recv(2048).decode()
        except:
            return None
            
    def send_move(self, move):
        try:
            self.socket.send(str.encode(move))
            return self.socket.recv(2048).decode()
        except socket.error as e:
            print(f"Socket error: {e}")
            return None
# Server handling multiple clients
def threaded_client(conn, player_id):
    conn.send(str.encode(f"Connected as Player {player_id}"))
    
    while True:
        try:
            data = conn.recv(4096).decode()
            if not data:
                break
                
            # Process player move and update game state
            games[game_id].update_move(player_id, data)
            
            if games[game_id].both_players_moved():
                result = games[game_id].get_result()
                conn.sendall(str.encode(result))
                
        except Exception as e:
            print(f"Error: {e}")
            break
    
    conn.close()Security Implementation
Security was a key consideration in the project design, implementing several measures to protect user data and game integrity:
Password Security:
- bcrypt Hashing - Industry-standard password hashing with automatic salt generation
 - No Plain Text Storage - Passwords never stored in readable format
 - Secure Transmission - Password verification handled server-side
 - Registration Validation - Username uniqueness checking and password requirements
 
Network Security:
- Input Validation - All incoming data validated before processing
 - Session Management - Secure player identification and game state isolation
 - Connection Limits - Prevent spam connections and resource exhaustion
 - Graceful Error Handling - Proper cleanup when clients disconnect unexpectedly
 
Development Challenges & Solutions
Pygame Threading Integration:
Challenge: Integrating Pygame's main loop with network communication without blocking.
Solution: Implemented non-blocking socket operations and proper threading to maintain smooth GUI responsiveness while handling network events.
State Synchronization:
Challenge: Ensuring both players see consistent game state and moves simultaneously.
Solution: Developed a robust game state management system with server-side validation and synchronized message broadcasting.
Connection Management:
Challenge: Handling player disconnections gracefully without breaking ongoing games.
Solution: Implemented comprehensive error handling with automatic cleanup and game state preservation for reconnection scenarios.
Cross-Platform Compatibility:
Challenge: Ensuring consistent gameplay experience across different operating systems.
Solution: Used Python's cross-platform libraries and tested extensively on Windows, macOS, and Linux systems.
Future Enhancements
Several improvements could be made to expand the project's functionality and user experience:
- Tournament Mode - Support for multi-round tournaments with bracket systems and leaderboards
 - Spectator Mode - Allow users to watch ongoing games without participating
 - Statistics Tracking - Comprehensive win/loss records, player rankings, and historical data
 - Chat System - In-game messaging between players for social interaction
 - Custom Game Variants - Rock-Paper-Scissors-Lizard-Spock and other variations
 - SSL/TLS Encryption - Encrypted communication for enhanced network security
 - Replay System - Save and review previous games with move history
 - Mobile Client - Cross-platform mobile app using Kivy or similar framework