Skip to content

A console-based Tic-Tac-Toe game built with modern C# and .NET 9

Notifications You must be signed in to change notification settings

kovalllllll/CourseWork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

๐ŸŽฎ MyCourseWork - Tic-Tac-Toe Console Game

C# .NET 9 Spectre.Console Platform

A console-based Tic-Tac-Toe game built with modern C# and .NET 9, featuring clean architecture, beautiful terminal UI with Spectre.Console, user authentication, and game history tracking.


๐Ÿ“‹ Table of Contents


๐Ÿ“– Description

MyCourseWork is a classic Tic-Tac-Toe game implemented as a console application with a modern terminal interface. The project demonstrates clean architecture principles by separating concerns into distinct layers:

  • Presentation Layer - Beautiful console UI powered by Spectre. Console
  • Business Layer - Contains game logic and authentication services
  • Data Layer - Manages data persistence with repository pattern

โœจ Key Features

Feature Description
๐Ÿ” User Authentication Register and login functionality with validation
๐ŸŽฏ Play vs Bot Challenge the AI opponent in Tic-Tac-Toe
๐Ÿ“Š Rating System Track your performance with ELO-like rating (starts at 1000)
๐Ÿ“œ Game History Record and view past games
๐ŸŽจ Beautiful UI Interactive menus with Spectre.Console
๐Ÿ—๏ธ Clean Architecture Three-layer architecture with Dependency Injection
๐Ÿ‘ฅ User Management List all registered users

๐Ÿ› ๏ธ Technologies

Core

Technology Version Description
C# 12 Primary programming language
.NET 9.0 Framework and runtime

Libraries & Packages

Package Version Purpose
Spectre.Console 0.49.1 Beautiful console UI components
Spectre.Console.Cli 0.49.1 Command-line interface builder
Microsoft.Extensions.DependencyInjection 9.0.0 Dependency Injection container

๐Ÿ“ Project Structure

CourseWork/
โ”œโ”€โ”€ ๐Ÿ“‚ MyCourseWork/                    # ๐Ÿ–ฅ๏ธ Presentation Layer (Console App)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Commands/                    # Command pattern implementations
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Extensions/                  # DI extension methods
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ CommandManager.cs            # Command dispatcher
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ GameFactory.cs               # Game instance factory
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ GameLogic.cs                 # Core game mechanics (3x3 board)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ ICommand.cs                  # Command interface
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ MyCourseWork.csproj          # Project configuration
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ Program.cs                   # Application entry point & menu
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ MyCourseWork. Business/           # ๐Ÿ’ผ Business Logic Layer
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Service/                     # Service implementations
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ AuthService.cs           # Registration, login, password update
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ GameService.cs           # Game recording logic
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Extensions/                  # DI extensions
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ IAuthService.cs              # Auth service contract
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ IGameService. cs              # Game service contract
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ MyCourseWork.Business.csproj
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ MyCourseWork.Data/               # ๐Ÿ’พ Data Access Layer
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Entity/                      # Domain entities (User, GameRecord)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ Interfaces/                  # Repository contracts
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ InMemoryUserRepository.cs    # In-memory user storage
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ InMemoryGameRepository.cs    # In-memory game storage
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ MyCourseWorkDbContext.cs     # Database context
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ MyCourseWork.Data.csproj
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ MyCourseWork.sln                 # Solution file
โ”œโ”€โ”€ ๐Ÿ“„ . gitignore                       # Git ignore rules
โ””โ”€โ”€ ๐Ÿ“„ README.md                        # This file

โš™๏ธ Installation

Prerequisites

Steps

  1. Clone the repository

    git clone https://github.com/kovalllllll/CourseWork.git
    cd CourseWork
  2. Restore dependencies

    dotnet restore
  3. Build the solution

    dotnet build

๐Ÿš€ Usage

Running the Application

dotnet run --project MyCourseWork

Main Menu Options

When you start the application, you'll see an interactive menu:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               Menu:                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  > Register                         โ”‚
โ”‚    Login                            โ”‚
โ”‚    List Users                       โ”‚
โ”‚    Exit                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Option Description
Register Create a new user account with username and password
Login Authenticate and access game features
List Users View all registered users and their ratings
Exit Close the application

Gameplay

  1. ๐Ÿ” Register or login to your account
  2. ๐ŸŽฎ Start a new Tic-Tac-Toe game
  3. โœ–๏ธ Choose your symbol (X or O)
  4. ๐Ÿ“ Enter coordinates (0-2) for row and column to place your mark
  5. ๐Ÿ† Try to get three in a row before the bot does!

Game Rules

  • The board is a 3x3 grid
  • Players take turns placing their symbol
  • First to align 3 symbols horizontally, vertically, or diagonally wins
  • If all cells are filled with no winner, it's a draw

๐Ÿค Contribution

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Commit your changes
    git commit -m 'Add some amazing feature'
  4. Push to the branch
    git push origin feature/amazing-feature
  5. Open a Pull Request

๐Ÿ“ Contribution Guidelines

  • โœ… Follow C# coding conventions and . NET best practices
  • โœ… Write meaningful commit messages
  • โœ… Add XML comments for public APIs
  • โœ… Keep the clean architecture structure
  • โœ… Update documentation as needed

๐Ÿ’ก Ideas for Contribution

  • Add difficulty levels for the bot (Easy/Medium/Hard)
  • Implement minimax algorithm for unbeatable AI
  • Add multiplayer mode (player vs player)
  • Persist data to a database (SQLite/PostgreSQL)
  • Add unit tests

๐ŸŒŸ Star this repo if you found it helpful!

Made with โค๏ธ by @kovalllllll

About

A console-based Tic-Tac-Toe game built with modern C# and .NET 9

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages