Skip to content

j-vinnal/Uno-Card-Game-in-C-Sharp

Repository files navigation

UNO Card Game

This project is a C# implementation of the UNO card game. The game supports both console and web-based play, with features including game state saving/loading, bot players, and multiplayer support. Work is still in progress.

Web gameplay
Console menu
Console gameplay

Project Overview

The UNO Card Game project is structured into several components:

  • ConsoleApp: The console-based application for playing UNO.
  • DAL: Data Access Layer, including Entity Framework context and repositories.
  • Domain: Domain models and enums representing the game entities.
  • GameEngine: Core game logic and rules implementation.
  • Helpers: Utility classes and methods.
  • MenuSystem: Console menu system.
  • UnoConsoleUI: Console UI components.
  • WebApp: Web application using Razor Pages for playing UNO online.

Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd uno-card-game
  2. Update .NET tools:

    dotnet tool update --global dotnet-ef
    dotnet tool update --global dotnet-aspnet-codegenerator

Database Setup

  1. Create a new migration:

    dotnet ef migrations add --project DAL --startup-project ConsoleApp InitialCreate

    or

    dotnet ef migrations add --project DAL --startup-project WebApp InitialCreate
  2. Update the database:

    dotnet ef database update --project DAL --startup-project WebApp

Running the Console App

Navigate to the ConsoleApp directory and run:

dotnet run

Running the Web App

Navigate to the WebApp directory and run:

dotnet run

Changing Data Repository

If you want to switch between using a database or JSON file repository, you need to update the Program.cs files in both the Web App and Console App.

Web App

In the Web App, modify the Program.cs file located in WebApp/Program.cs:

builder.Services.AddScoped<IGameRepository, GameRepositoryEF>();
//builder.Services.AddSingleton<IGameRepository, GameRepositoryFileSystem>();

Comment out the line for the repository you do not need.

Console App

In the Console App, modify the Program.cs file located in ConsoleApp/Program.cs:

//IGameRepository gameRepository = new GameRepositoryFileSystem();
IGameRepository gameRepository = new GameRepositoryEF(db);

Comment out the line for the repository you do not need.

Game Logic

Game Setup

The game setup involves initializing the game options, setting up players, and dealing cards. This is handled by the UnoGameEngine class.

Game Flow in Console

The game flow is managed by the GameController class, which handles player turns, card plays, and game state updates.

Bot Players

Bot players are supported and can be configured to play automatically. The bot logic is implemented within the UnoGameEngine class.

Saving and Loading Game State

The game state can be saved to and loaded from both JSON files and a database. The data access logic is implemented in the GameRepositoryFileSystem and GameRepositoryEF classes.

License

This project is licensed under the MIT License.

Acknowledgments

UNO (card game) on Wikipedia

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published