Skip to content

DaoudSabat/targetNumberGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Target Number Game

C++ puzzle game on a 3×3 grid — select cells to increment rows and columns until all values equal 9. Supports unlimited undo, redo, and hints.

Overview

The game initialises a 3×3 grid of 9s and applies random decrementing moves at a chosen difficulty level. The player then selects cells to apply incrementing moves, aiming to restore every cell to 9. Every move is captured in a linked stack, enabling full undo/redo history. A hint engine evaluates all possible next moves and suggests the one that brings the grid closest to solved.

Architecture

targetNumberGame/
├── include/
│   ├── Stack.h        # Stack class — linked-list undo/redo storage
│   └── Game.h         # MoveHandler class — game state and move logic
├── src/
│   ├── stack.cpp      # Stack implementation
│   ├── game.cpp       # MoveHandler implementation
│   └── main.cpp       # CLI entry point
├── tests/
│   └── test_game.cpp  # Standalone test program (no framework needed)
└── CMakeLists.txt

Design Patterns

  • Memento — each Stack::push() captures a full grid snapshot; undo()/redo() restore them without exposing internal state
  • CommandapplyMove(), undo(), and redo() encapsulate reversible operations that operate on the same grid state
  • Single ResponsibilityStack handles only memory management; MoveHandler handles only game rules

Tech Stack

  • C++17
  • Standard Library only<iostream>, <iomanip>, <new>, <cstdlib>
  • CMake 3.14+ — cross-platform build system

Installation

git clone https://github.com/DaoudSabat/targetNumberGame.git
cd targetNumberGame
cmake -B build && cmake --build build
./build/target_game

Or open targetNumberGame.sln in Visual Studio.

Usage

Enter difficulty level (1-9): 3

Current Grid:
    0  1  2

0    8  9  8
1    9  8  9
2    8  9  8

Options:
1) Play move  2) Undo  3) Redo  4) Show hint  5) Exit

Tests

cmake --build build --target test_game
./build/test_game
Running targetNumberGame tests...

PASS: Stack push/pop round-trip
PASS: Stack underflow returns error code
PASS: New stack is empty
PASS: Difficulty-0 game starts solved
PASS: applyMove changes grid state
PASS: undo restores previous state

All tests passed.

License

MIT

About

A C++ puzzle game based on a 3x3 grid where the goal is to transform all numbers into 9 using minimal moves. Selecting a cell increases values in its row and column. Includes UNDO and REDO functionality using linked stacks, and a difficulty setting that controls the puzzle's complexity.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors