Minesweeper assignment during my C-1 programming course.
Assignment: Minesweeper
A given number of bombs are hidden on an 8 x 8 field. Each field is invisible until you choose and activate it. Choosing the location is always by entering a letter with number or number with letter (both C5 and 5C and c5), the number goes from 1 to 8 and the letter from A to H. If a bomb is hidden there, the game ends and you are lost and show all other bombs. If there is no bomb, the number of bombs in the immediate vicinity is shown (top left, top, top right, left, right, bottom left, bottom and bottom right). If there are no bombs around, it will show all immediate neighbors as they cannot be bombs and repeat this functionality for all neighbors that also have no nearby bombs. The game is over once all the bombs are the only spaces that have not been cleared. You always show the progress in percentage of the game as number of fields unlocked / number of fields to be unlocked (= 8x8 fields - number of bombs) x 100%. It is always possible to save a running game (choose the word "save" when entering the location) and to load it with the help of. 2 hexadecimal numbers (1 bitmask with bomb location and 1 bitmask with unlocked fields).
Flow of the game:
Start the game by welcoming the user and asking for the number of bombs or "loads". During loading, 2 hexadecimal numbers are entered, which together represent both the 8 by 8 field with bombs and the field played. Test whether the entered values are possible, e.g. no bombs in the field, or bombs that have already exploded, or a field that has actually been played out. With the number of bombs, a new 8 by 8 field is filled with the number of bombs at random locations (make sure that the number of bombs is correct and that no bombs are duplicated). In both cases, a visual 2D array is filled or maintained (and loaded) with the correct representation. Then the game is played.
The game is played until a bomb activates or the game is over. As long as that is not the case, a location can be entered as "save". When saved, it shows the 2 64 bit hexadecimal numbers representing the bomb field and current state of cleared fields. A location, on the other hand, can be both a letter with a number and a number with a letter (case insensitive). At that entered location, the field (visual 2D array) is adjusted to show the correct content. This can be a bomb and then the game is over and you show the field with all the bombs. This can be a neighbor of a bomb and then you show the number of number of bombs as a neighbor. This can be a null field and then you flood fill the field from that point. Displays the field and progress as a percentage with 2 decimal places of number of fields shown to total number of good fields. Once the last non-bomb space is marked, congratulate the player.