Skip to content

๐ŸŽฎ Real-time multiplayer Tic Tac Toe game with ASP.NET Core 9.0, SignalR & React 19. Features instant gameplay, glassmorphism UI, mobile-responsive design, game sharing, and seamless real-time communication. Showcases modern full-stack development with TypeScript and event-driven architecture.

Notifications You must be signed in to change notification settings

arsanjani/TicTacToe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

49 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Multiplayer Tic Tac Toe Game

A real-time multiplayer tic-tac-toe game built with ASP.NET Core 9.0, SignalR, and React 19. Players can create games, share links with friends, and play in real-time with beautiful, modern UI.

๐ŸŒ Live Demo

Try the game now: https://apponline.ir

โœจ Features

  • Real-time Multiplayer: Play with friends in real-time using SignalR
  • Multiple Board Sizes: Choose between 3x3 classic or 4x4 extended boards
  • AI Opponent: Single-player mode with intelligent AI for practice
  • Character Customization: 11 unique character icons including X/O and cute characters
  • Private Games: Create private games accessible only via share link
  • Game Sharing: Share game links to invite friends directly
  • Database Persistence: Complete game history and statistics tracking
  • Beautiful UI: Modern, responsive design with smooth animations
  • Auto-matching: Join available games or create new ones
  • Game Results: See detailed game statistics and play again
  • Mobile Friendly: Responsive design works perfectly on all devices

๐ŸŽฏ How to Play

  1. Enter your name and choose your character from 11 available options
  2. Select board size: Classic 3x3 or Extended 4x4
  3. Choose game type:
    • Multiplayer: Share the game link with a friend or wait for someone to join
    • AI Mode: Start playing immediately against an intelligent AI opponent
    • Private Game: Create a private game only accessible via share link
  4. Take turns clicking on the grid to place your character symbols
  5. Win by getting symbols in a row (3 for 3x3 board, 4 for 4x4 board)
  6. Play again with the same opponent or leave to start a new game

๐ŸŽจ Character Options

Choose from 11 unique character icons:

  • Classic: Cross (X), Circle (O)
  • Sanrio Characters: Hello Kitty, My Melody, Kuromi, Cinnamoroll, Badtz-Maru, Keroppi, Pochacco
  • Special: Spider-Man, AI Robot

๐Ÿ—๏ธ Architecture

  • Backend: ASP.NET Core 9.0 with SignalR for real-time communication
  • Database: Entity Framework Core with SQL Server for persistence
  • Frontend: React 19 with TypeScript and modern CSS
  • State Management: Custom React hooks for game state
  • Real-time: SignalR hubs for instant game updates
  • Data Layer: AutoMapper for DTO mapping and generic repository pattern
  • Styling: Beautiful gradient backgrounds with glassmorphism effects

๐Ÿš€ Getting Started

Prerequisites

Installation

  1. Clone the repository (if using git):

    git clone <repository-url>
    cd TicTacToe
  2. Install frontend dependencies:

    cd tictactoe.client
    yarn install
    cd ..
  3. Set up the database:

    cd TicTacToe.Server
    dotnet ef database update
    cd ..
  4. Build the application:

    dotnet build TicTacToe.Server

Running the Application

  1. Start the server (from the project root):

    dotnet run --project TicTacToe.Server
  2. Open your browser and navigate to:

The application will automatically serve both the backend API and the React frontend.

Database Setup

The application uses SQL Server LocalDB by default. The database will be created automatically when you run the application for the first time. To reset the database:

cd TicTacToe.Server
# Windows
.\reset-migrations.bat
# Or manually
dotnet ef database drop --force
dotnet ef database update

๐Ÿ“ Project Structure

TicTacToe/
โ”œโ”€โ”€ TicTacToe.Server/          # ASP.NET Core backend
โ”‚   โ”œโ”€โ”€ Models/                # Game, Player, and state models
โ”‚   โ”œโ”€โ”€ Entities/              # Entity Framework entities
โ”‚   โ”œโ”€โ”€ Data/                  # Database context and configurations
โ”‚   โ”œโ”€โ”€ Services/              # Game logic and AI implementation
โ”‚   โ”œโ”€โ”€ Hubs/                  # SignalR real-time communication
โ”‚   โ”œโ”€โ”€ Controllers/           # REST API controllers
โ”‚   โ”œโ”€โ”€ DTOs/                  # Data transfer objects
โ”‚   โ”œโ”€โ”€ Mappings/              # AutoMapper profiles
โ”‚   โ””โ”€โ”€ Migrations/            # Entity Framework migrations
โ”œโ”€โ”€ tictactoe.client/          # React frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/Game/   # Game UI components
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/             # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ services/          # SignalR client service
โ”‚   โ”‚   โ”œโ”€โ”€ types/             # TypeScript type definitions
โ”‚   โ”‚   โ”œโ”€โ”€ theme/             # Comprehensive CSS styling
โ”‚   โ”‚   โ””โ”€โ”€ utils/             # Utility functions
โ”‚   โ””โ”€โ”€ public/                # Static assets and character icons
โ”œโ”€โ”€ sql/                       # Database migration scripts
โ””โ”€โ”€ README.md                  # This file

๐Ÿ”ง Development

Backend Development

The backend uses:

  • ASP.NET Core 9.0 for the web framework
  • Entity Framework Core with SQL Server for data persistence
  • SignalR for real-time communication
  • AutoMapper for object mapping
  • Generic repository pattern for data access
  • AI implementation for single-player mode

Key files:

  • GameHub.cs - SignalR hub for real-time game events
  • GameService.cs - Game logic, AI implementation, and state management
  • Game.cs, Player.cs - Domain models with dynamic board size support
  • TicTacToeDbContext.cs - Entity Framework database context

Frontend Development

The frontend uses:

  • React 19 with TypeScript
  • Custom hooks for comprehensive state management
  • SignalR client for real-time updates
  • Modern CSS with extensive responsive design
  • Character icon system with 11 unique options

Key files:

  • useGameState.ts - Main game state hook with AI support
  • gameService.ts - SignalR client wrapper
  • GameBoard.tsx - Interactive game grid with character icons
  • GameLobby.tsx - Game creation with board size and AI options
  • WaitingRoom.tsx - Player lobby and game joining

AI Implementation

The AI opponent features:

  • Strategic gameplay: Win, block, center, corners, edges priority
  • Adaptive difficulty: Works with both 3x3 and 4x4 boards
  • Natural timing: Realistic move delays for better UX
  • Fair play: Random first player selection

Building for Production

# Build backend
dotnet build TicTacToe.Server --configuration Release

# Build frontend
cd tictactoe.client
yarn build
cd ..

# Publish (optional)
dotnet publish TicTacToe.Server --configuration Release

๐ŸŽจ Design Features

  • Gradient Backgrounds: Beautiful purple-to-blue gradients
  • Glassmorphism: Translucent panels with backdrop blur
  • Character Icons: 11 unique, colorful character options
  • Responsive Design: Optimized for all screen sizes (320px to 1440px+)
  • Smooth Animations: Hover effects, transitions, and loading spinners
  • Visual Feedback: Clear indicators for turns, wins, and game states
  • Board Size Adaptation: Dynamic layouts for 3x3 and 4x4 boards

๐Ÿ—„๏ธ Database Features

  • Game History: Complete tracking of all games played
  • Player Statistics: Win/loss records and game duration
  • Session Management: Proper cleanup and state management
  • Performance Optimized: Indexed queries and efficient data structure
  • Migration Support: Easy database updates and schema changes

๐Ÿš€ Deployment

The application can be deployed to:

  • Azure App Service with SQL Database
  • IIS with SQL Server
  • Docker containers with multi-container support
  • Any hosting platform supporting ASP.NET Core

For production deployment, ensure:

  • Database connection strings are configured
  • CORS settings are configured for your domain
  • SignalR is properly configured for your hosting environment
  • Static files are served correctly
  • SSL certificates are properly configured

๐Ÿ”ฎ Recent Updates (v2.0)

Major New Features

  • โœ… Multiple Board Sizes: 3x3 classic and 4x4 extended boards
  • โœ… AI Opponent: Intelligent single-player mode
  • โœ… Character Customization: 11 unique character icons
  • โœ… Database Persistence: Complete game history tracking
  • โœ… Private Games: Create private, link-only games
  • โœ… Enhanced UI: Improved responsive design for all devices

Technical Improvements

  • โœ… Entity Framework Integration: Full database persistence
  • โœ… Advanced AI Logic: Strategic gameplay for all board sizes
  • โœ… Performance Optimization: Indexed database queries
  • โœ… Code Architecture: Clean separation with DTOs and AutoMapper
  • โœ… Comprehensive Testing: Improved error handling and validation

๐Ÿ”ฎ Future Enhancements

  • User accounts and authentication
  • Player rankings and leaderboards
  • Tournament mode with brackets
  • Spectator mode for ongoing games
  • Game replay system
  • Custom character upload
  • Mobile app versions
  • Advanced AI difficulty levels

๐Ÿ“ License

This project is open source and available under the MIT License.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“ง Support

If you encounter any issues or have questions, please create an issue in the repository.


Built with โค๏ธ using ASP.NET Core, Entity Framework, and React

About

๐ŸŽฎ Real-time multiplayer Tic Tac Toe game with ASP.NET Core 9.0, SignalR & React 19. Features instant gameplay, glassmorphism UI, mobile-responsive design, game sharing, and seamless real-time communication. Showcases modern full-stack development with TypeScript and event-driven architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •