Skip to content

Latest commit

 

History

History
121 lines (99 loc) · 2.92 KB

README.md

File metadata and controls

121 lines (99 loc) · 2.92 KB

Basic CLI Minesweeper

...that I will probably never properly finish pretty much finished...

Quick little HowTo


NAQ (Never Asked Questions):
Why?
Because I wanted to do something in C and this seemed simple enough

Why not use a graphic library like ncurses?
Because I did not want to

Why do you cast your mallocs?
Modern C compilers usually don't care, but C++ compilers do and I don't really want to deal with CMake choosing a C++ compiler and throwing errors

Todo (After most basic stuff is finished):

  • Generate fields until valid input is found for first input
  • Clear adjacent fields if selected field has no adjacent bombs
  • Add row/column numbers to cli output
  • Game output should work on fields larger than 10x10
  • Add flags for marking
  • Rework how cells are selected
  • Disable all VT100 Terminal codes when selected

Build

Dependencies:
No external dependencies apart from the C99 standard library and libm (C Standard Math library)

Building:

sh build.sh

or

cd build
cmake ..
make

File Layout

jarm
├── build.sh        // Quick & dirty Linux build script
├── CMakeLists.txt  // Quick & probably dirty CMake build script
├── LICENSE         // MIT License
├── README.md       // this
└── src
    ├── main.c    // Main programm
    ├── config.h  // Build configuration macros
    ├── cli
    │   ├── Cli.c  // Command line interface interactions implementations
    │   └── Cli.h  // "                                 " declarations
    └── logic
        ├── GameLogic.c  // Game interactions/logic implementations
        └── GameLogic.h  // "                     " declarations

How the code does its thing

Internal state meaning:

Num Meaning
0 Nothing
1 Bomb
2 Checked by Player

Board internal state:

\ 0 1 2
0 0 1 1
1 0 2 0
2 1 1 2

Board as shown to player:

\ 0 1 2
0 ? ? ?
1 ? 4 ?
2 ? ? 1

Written explanation:
The game board (grid) in the Board_t is of type uint16_t*[] or uint16_t** and is dynamically allocated by creating it through msw_Init.
The initialised board can then be used to play the game with other msw_* function.
I/O is done through the cli_* functions.

Gameplay loop with "pseudo code":

Parse command line arguments
Initialise variables and game board

Do until game is not ongoing
    Print the gameboard
    Get command input
    Update game with command inputs
    Update game status (is ongoing etc.)

Give user feedback about win/loss
Free heap allocated memory if needed