Code Monkey home page Code Monkey logo

hangman's Introduction

Hangman

Alt text

A Hangman (the old classic guess-the-word game) gaming API written in C# with ASP.NET core framework. This project comes with the following extra features (besides the game itself) that are important for production-ready scenarios:

  • Serilog logging configuration for sending logs to Elasticsearch
  • Elasticsearch instance to receive log messages
  • Sonarqube configuration which contains an MSBuild xml configuration for sonarqube along with the tools required to collect test coverage such as coverlet.collector Nuget package and a runsettings.xml file to setup coverage file formats.

API demo: winning (guessing) the word without being hanged

Alt text

API demo: losing a game (not guessing the word) by being hanged

Alt text

Hangman architecture

Alt text

This application's architecture uses layered-design that can roughly be divided into:

  • Controller layer
  • Application layer (use cases)
  • Business layer
  • Infra layer

This model is much simpler than other famous modelings approaches, such as Domain Driven Design, but that's not a problem! It's actually just a different architectural approach that is definitely effective for domains that are not so complex but, at the same time, require more than bare CRUD logic.

Hangman modeling (entities)

Alt text

The presented entities were used to model the Hangman game problem.

Running the project

As this project contains a dockerized application, it can be executed in development mode in two environments:

  1. locally via the dotnet command line tool;
  2. inside docker containers via docker-compose;

1. Locally via dotnet command line tool

Running locally has the huge advantage of being ultra easy to invoke the application and its tests with debug. Due to the easy-to-debug feature , this it the recommended option.

Run the following commands on a terminal:

# the database and other services must be running and bound to the localhost's port
docker-compose up -d db

 # start project on localhost
dotnet run --project ./Hangman/Hangman.csproj

2. In a docker container via docker-compose

Running with docker-compose allows one to run without having dotnet SDK or anything else installed on his machine.

The project is started with the watch option which rebuilds/reloads the container upon code changes. However, bear in mind that, as of now, debugging is not yet supported.

Run the following commands on a terminal:

docker-compose up app  # brings up the app and its required services

Running tests

Again, this can be done in two environments:

  1. locally via the dotnet command line tool;
  2. inside docker containers via docker-compose;

1. Locally via dotnet command line tool

Locally, they can be run with:

docker-compose up -d db
dotnet test

2. In a docker container via docker-compose

With a docker-compose:

docker-compose -f docker-compose-tests.yml up

Project structure creation (so far)

# solution creation
dotnet new sln -n Hangman
dotnet sln list  # shows no projects in the solution

# projects creation
dotnet new webapi -n Hangman
dotnet new xunit -n Tests

 # projects wrapping inside the solution
dotnet sln add ./Hangman/Hangman.csproj  # adds project to the solution
dotnet sln add ./Tests/Tests.csproj  # adds project to the solution

Adding migrations

dotnet ef migrations add MigrationName --project ./Hangman/Hangman.csproj --context HangmanDbContext -v

Removing a migration (non-applied)

dotnet ef migrations remove  # removes last applied migration

Applying migrations manually (done at runtime in this project)

dotnet ef database update --project  ./Hangman/Hangman.csproj

Rolling back (reverting) to a specific migration (applied)

dotnet ef database update MigrationName --project  ./Hangman/Hangman.csproj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.