Code Monkey home page Code Monkey logo

jarm-c's Introduction

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

jarm-c's People

Contributors

jarpos avatar

Stargazers

Artem Mironov avatar Phanuel Kidakwa avatar Wolfgang Schuster avatar

Watchers

 avatar

Forkers

phanuell-365

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.