Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

22 Commits

Folders and files

Repository files navigation

๐ŸŽฎ MemoryGame โ€“ Databasteknik och Webbaserade System

CI

A turn-based multiplayer Memory Game built with ASP.NET Core MVC and SQL Server as part of the course
๐Ÿ“˜ Databasteknik och webbaserade system at IT-Hรถgskolan Sverige AB.


๐Ÿ—๏ธ Project Overview

MemoryGame is a web-based multiplayer game where two players take turns flipping cards to find matching pairs.
The project demonstrates the use of relational databases, MVC architecture, CRUD operations, and session handling in a full-stack ASP.NET web application.


๐ŸŽ“ My Role & What I Built

This was an individual school project that I designed and implemented end-to-end. Everything in this repository was written by me.

What I built:

  • Database schema โ€“ designed from scratch: six normalized tables with composite foreign keys that enforce referential integrity at the DB level (e.g. a Move's tiles must belong to the same Game row).
  • Custom Repository layer using raw ADO.NET โ€“ no Entity Framework; all queries are hand-written parameterized SQL, which was a course requirement to demonstrate direct SQL knowledge.
  • Session-based authentication โ€“ including PBKDF2-SHA256 password hashing with a random salt (Security/PasswordHasher.cs), without relying on ASP.NET Identity.
  • Real-time turn polling โ€“ the game board auto-refreshes via AJAX so each player sees the opponent's last move without a full page reload.
  • Lobby system โ€“ Player A creates a game, Player B joins, and the game transitions automatically through Waiting โ†’ InProgress โ†’ Completed.
  • Card Admin CRUD interface โ€“ full create/read/update/delete for the card catalogue.
  • Azure deployment via Visual Studio's publish wizard.

What I learned:

  • Writing safe, parameterized ADO.NET queries without an ORM safety net.
  • Designing a turn-based state machine enforced by a SQL CHECK constraint.
  • Managing sessions in ASP.NET Core without the Identity middleware stack.
  • Structuring an MVC application with Dependency Injection for testability.

โœจ Features

โœ… Two-player turn-based gameplay
โœ… Login system with sessions
โœ… Lobby where users can create, join, or delete games
โœ… Real-time updates through AJAX polling
โœ… Card Admin CRUD interface (Create / Read / Update / Delete)
โœ… SQL database integration for all game entities
โœ… Card-table style UI with flip animations that also works on phones
โœ… Session-based authentication


๐Ÿงฑ Tech Stack

Layer Technology
Frontend HTML5, CSS3, Razor Views
Backend ASP.NET Core MVC (C#)
Database Microsoft SQL Server
Data Access Custom Repository Layer (ADO.NET)
Authentication Session-based login
Version Control Git & GitHub

๐Ÿ—‚๏ธ Architecture

Browser (Razor Views + jQuery AJAX)
           โ”‚
           โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚            Controllers                โ”‚
   โ”‚  AccountController ยท GameController   โ”‚
   โ”‚  CardAdminController ยท HomeController โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚  constructor-injected interfaces
                    โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚         Repositories (ADO.NET)        โ”‚
   โ”‚  UserRepository  ยท GameRepository     โ”‚
   โ”‚  CardRepository  ยท TileRepository     โ”‚
   โ”‚  MoveRepository                       โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚  SqlConnection via IDbConnectionFactory
                    โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚             SQL Server                โ”‚
   โ”‚  Tables: User ยท Game ยท GamePlayer     โ”‚
   โ”‚          Card ยท Tile ยท Move           โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Session cookies hold the logged-in UserID and Username. No Entity Framework โ€” all queries are hand-written parameterized SQL.


๐Ÿ“‚ Project Structure

image

๐Ÿš€ How to Run Locally

Prerequisites

  • .NET 8 SDK
  • SQL Server (any edition), SQL Server Express, or LocalDB (ships with Visual Studio)
  • SQL Server Management Studio (SSMS) or Azure Data Studio (optional)

1. Clone the repository

git clone https://github.com/sam-razavi/memorygame.git
cd memorygame

2. Create and populate the database

Open your SQL client and run:

CREATE DATABASE MemoryGameDb;

Then open MemoryGame/Database/01_CreateSchema.sql and execute it against MemoryGameDb.
The script drops and recreates all tables, so it is safe to re-run.

3. Configure the connection string

Copy the example file:

cp MemoryGame/appsettings.example.json MemoryGame/appsettings.json

Then edit appsettings.json and replace the MemoryGameDb value with your connection string:

Scenario Connection string
LocalDB (Visual Studio default) Server=(localdb)\\MSSQLLocalDB;Database=MemoryGameDb;Trusted_Connection=True;MultipleActiveResultSets=true
SQL Server Express Server=.\\SQLEXPRESS;Database=MemoryGameDb;Trusted_Connection=True;MultipleActiveResultSets=true
Named instance Server=YOUR_PC\\INSTANCE;Database=MemoryGameDb;Trusted_Connection=True;MultipleActiveResultSets=true
SQL auth Server=YOUR_SERVER;Database=MemoryGameDb;User Id=sa;Password=YOUR_PASSWORD;MultipleActiveResultSets=true

Note: appsettings.json is listed in .gitignore to keep credentials out of source control.
appsettings.example.json shows the required keys without real values.

4. Run the application

cd MemoryGame
dotnet run

The terminal prints the local URL (e.g. http://localhost:5013).
Open it in your browser, register two accounts (use a second browser window or incognito), and start a game.

5. Run the tests

cd MemoryGame.Tests
dotnet test

๐Ÿงช Tests

The MemoryGame.Tests project contains unit tests that run without a database connection.

Test class What it covers
PasswordHasherTests Hash format, verify correct password, reject wrong password, reject malformed stored string, unique salts per call
GameModelTests Default Status value, nullable defaults, property assignment for Game, Card, and Tile
dotnet test MemoryGame.Tests

These tests cover the pure-logic classes (PasswordHasher, model POCOs) that have no external dependencies. Integration tests against a live database are a natural next step.


๐Ÿ•น๏ธ Gameplay Flow

  1. Player A creates a new game in the lobby.
  2. Player B joins the same game.
  3. The game starts automatically; players alternate flipping two tiles per turn.
  4. Matching pairs score a point; a miss passes the turn to the opponent.
  5. When all tiles are matched, the system determines the winner automatically.

๐Ÿ–ผ๏ธ Screenshots

Gameplay

Alex finds the dogs and keeps the turn, then misses on apple and banana, so the turn passes to Sam.

Gameplay

Start page

Start page

Lobby

Create a game, join an open one, or delete games you created. The list refreshes on its own when someone joins.

Lobby

Your turn

The side panel shows whose turn it is, the score and every move so far.

Game in progress

Finished game

Finished game

Deck admin

Add, edit and remove the cards that new games are dealt from.

Deck admin

Log in

Log in

On a phone

Mobile


Deployed on

https://memorygame-sam-b4dbbha5anguhxbt.germanywestcentral-01.azurewebsites.net/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages