uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit 2986e9e0ff23471d92783637672094af0ce256ca
parent 180355a8329df7d03acd78cc89d110123e78d2f0
Author: Christos Margiolis <christos@margiolis.net>
Date:   Fri, 17 Jan 2020 14:41:34 +0200

made minesweeper and actual game

Diffstat:
Dassignment-1.5-arrays-pointers-files/minesweeper/include/gamelogic.h | 20--------------------
Aassignment-1.5-arrays-pointers-files/minesweeper/include/gameplay.h | 19+++++++++++++++++++
Massignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h | 4++--
Massignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt | 210+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Dassignment-1.5-arrays-pointers-files/minesweeper/src/gamelogic.c | 56--------------------------------------------------------
Aassignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Massignment-1.5-arrays-pointers-files/minesweeper/src/main.c | 1-
Massignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c | 16+++++++---------
8 files changed, 264 insertions(+), 119 deletions(-)

diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/gamelogic.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/gamelogic.h @@ -1,19 +0,0 @@ -#ifndef GAMELOGIC_H -#define GAMELOGIC_H - -#if defined linux || defined __unix__ -#include <ncurses.h> -#elif defined _WIN32 || defined _WIN64 -#include <pdcurses.h> -#include <stdint.h> -#endif - -#include <stdbool.h> - -// Game logic -void selection(struct _win_st*, char **, char **, int, int); -bool transfer(char **, char **, int, int); -void reveal(struct _win_st*, char **, int, int); -void game_over(struct _win_st*, char **, int, int); - -#endif- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/gameplay.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/gameplay.h @@ -0,0 +1,18 @@ +#ifndef GAMEPLAY_H +#define GAMEPLAY_H + +#if defined linux || defined __unix__ +#include <ncurses.h> +#elif defined _WIN32 || defined _WIN64 +#include <pdcurses.h> +#include <stdint.h> +#endif + +#include <stdbool.h> + +void selection(struct _win_st*, char **, char **, int, int); +bool transfer(char **, char **, int, int); +void reveal(struct _win_st*, char **, int, int); +void game_over(struct _win_st*, char **, int, int); + +#endif+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h @@ -33,7 +33,7 @@ bool outof_bounds(int, int, int, int); int8_t adj_mines(char **, int, int, int, int); void fill_spaces(char **, int, int, int); -void print(struct _win_st*, char **, int, int); -void filewrite(char **, int, int); +void print_board(struct _win_st*, char **, int, int); +void filewrite(char **, int, int, int, int); #endif \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt b/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt @@ -1,34 +1,182 @@ -Mine hit at position (1, 2) +Mine hit at position (9, 10) Board overview -- - - - - - - - 1 1 1 - - - - - - - - - - - - - 1 * 1 - - - -- - - - - - - - 1 * 1 - - - - - - - - - - - - - 1 2 2 1 - - -- - - - - - - - 1 1 1 - - - 1 1 1 - - - - - - - - 1 * 1 - - -- - - - - - - - - - - - - - 1 * 1 - - - - - - - - 1 1 1 - - -- - - - - - - - - - - 1 1 1 1 1 1 - - 1 1 1 - - - - - - - - -- - - - - - - - - - - 1 * 1 - - - - - 1 * 1 - - - - - 1 1 1 -- - - - - - - 1 1 1 - 1 1 1 - - - - - 1 1 2 1 1 - - - 1 * 1 -- - - - - - - 1 * 1 - - - - - - - - - - - 2 * 2 - - - 1 1 1 -- - - - - - - 1 1 1 - - - - - - - - - - - 2 * 3 1 1 - - - - -- - - 1 1 2 1 1 - - - - - - - - - - - - - 1 1 2 * 1 - - - - -- - - 1 * 2 * 1 - - - - - - - - - - 1 1 1 - - 1 1 1 1 1 1 - -- - - 1 1 2 1 1 - - - - - - - - - - 1 * 1 - - - 1 1 2 * 1 - -- - - - - - - - - - - - - - - - - - 1 2 2 1 - - 1 * 2 1 1 - -- - - - - - - - - - - - - - - - - 1 1 3 * 2 - - 1 1 1 - - - -- - - - - - - - - 1 1 1 - - - - - 1 * 3 * 2 - - - - - - - - -- - - - - - - - - 1 * 1 - - - - - 1 1 2 1 1 - - - - - - - - -- - - - - - - - - 1 1 2 1 1 - - - - - - - - - - - - - - - - -- - - - - - - - - - - 1 * 1 - - - - - - - - - - - - - - - - -- - - - - - - - - - - 1 1 1 - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 1 -- - - - - - - 1 1 1 - - - - - - - - - - - - - - - - - - 1 * -1 1 1 - - - - 1 * 1 - - - - - - - - - - - - - - - - - - 1 1 -1 * 1 - - - - 1 1 1 - - - - - 1 1 1 - - - - - - - - - - - - -1 1 1 - - - - - - - - - - - - 1 * 1 - - - - - - - - - - - - -- - - - - - - - - - - - - - - 1 1 1 - 1 1 1 - - - - - - - - -- - - - - - - - - - - 1 1 1 - - - - - 1 * 2 1 - - - - - - - -- - - - - - - - - - - 1 * 1 - - - - - 2 3 * 1 - - - - - - - -- - - - - - - - - - - 1 1 1 - 1 1 1 - 1 * 2 1 - - - - - - - -- - - - - - - - - - - - - - - 1 * 1 - 1 1 1 - - - - - - - - -- - - - - - - - - - - - - - - 1 1 1 - - - - - - - - - - - - +2 * * 3 * 2 1 * * * * 4 * * * 3 2 1 2 2 * * 5 * 4 2 2 * 2 * * 2 1 2 * 4 * * * 1 +* 4 2 4 * 3 2 4 6 6 5 * * 7 * * 4 * 5 * 6 * * * * * 5 4 4 4 3 4 * 4 3 * * * 4 2 +* 4 2 4 * 4 3 * * * * 6 * * 6 * 7 * * * * 4 5 * * * * * * 5 * 4 * * 3 3 4 3 4 * +* * 2 * * 4 * * * 6 * 5 * * 5 * * * * * 6 4 * 5 6 * * 6 * * * 5 4 5 * 3 2 * 5 * +3 4 3 4 5 * 5 * 5 * 3 4 * 5 * 4 5 7 * * * * 5 * * 5 * 4 4 5 6 * * 4 * 4 * 4 * * +* 4 * 4 * * 3 2 * 4 * 4 3 * 4 5 * * * 7 * * * 5 * 4 2 * 2 * * * * 4 4 * 4 4 * 4 +3 * * 5 * 3 2 2 2 4 * 5 * 3 * * * 6 5 * * 6 3 3 * 3 3 4 4 5 * * 5 * 3 * * 3 3 * +2 * * 3 2 2 3 * 2 2 * * 3 4 4 5 * * 3 * * * 3 4 3 4 * * * 4 * * 5 3 5 6 * 5 5 * +2 4 4 2 2 * 4 * 2 2 3 4 4 * * 4 3 4 3 4 * 5 * * * 4 * 4 4 * 5 * 5 * * * * * * * +2 * * 1 3 * 5 2 2 1 * 4 * * * 5 * 3 * 4 3 5 * 6 5 * 4 2 4 * 5 3 * * * 7 * * 7 * +2 * 5 4 4 * 5 * 3 2 4 * * * * * 3 4 * * 2 * * * 5 * 5 * 6 * 4 * 5 6 * 4 * 4 * * +2 3 * * * 4 * * 6 * 4 * * * * 5 * 4 4 4 4 4 5 * 5 * 5 * * * 4 2 * * 3 2 2 4 6 * +* 3 4 * 6 * 7 * * * 6 5 7 * 4 4 * * 4 * * 4 * 3 3 * 4 5 * * 3 1 3 * 3 1 3 * * * +3 * 5 4 * * * * 7 * * * * * 4 4 * 4 * * * 5 * 4 3 3 4 * * * 3 1 3 2 3 * 4 * 7 4 +2 * * * 6 * * * 6 * * * 5 5 * * 5 5 6 * * 4 3 * * 5 * * 5 2 2 * 3 * 3 2 5 * * * +2 5 * * * 6 6 6 * * 6 4 3 * * * * * * * 7 * 3 4 * * * * 2 - 2 3 * 2 2 * 3 * 5 * +* 4 * * * * * * * 6 * * 3 4 6 * * 7 * * * * 3 3 * 6 5 4 2 1 3 * 3 1 1 2 4 4 4 2 +3 6 * 8 * * * * * 6 * 5 * 4 * * 6 * * 6 6 * 4 3 * 4 * * 2 1 * * 4 2 1 2 * * * 2 +* * * * * * * 7 * 5 * 5 4 * * 6 * * * * 5 * * 4 2 4 * * 3 1 3 4 * * 3 4 * * * 3 +4 5 6 * * 7 * 6 * 3 2 * * 6 * 6 * * * * * 6 * * 4 4 * * 3 2 4 * 7 * 5 * * 6 * 4 +* * 5 * * 5 * * 4 2 2 4 5 * * 6 * * 6 6 * 6 * * * * 5 3 2 * * * * * * 5 5 6 * * +2 4 * * 4 5 * * * 2 2 * * 6 6 * * * 4 * * 4 * 6 * * * 2 2 4 * 6 * 4 3 * * * * * +1 4 * 5 * 4 * * 4 * 2 4 * * * * 5 2 4 * 5 3 2 4 * * 6 * 4 4 * 4 2 2 2 5 * * 8 * +1 * * 5 3 * 4 3 4 3 3 4 * 7 7 * 3 - 3 * * 2 2 * 4 * 5 * * * 2 3 * 4 3 * * * * * +2 5 * * 2 2 4 * 5 * * 5 * * * * 4 2 4 * 6 * 2 2 3 3 5 * 7 4 2 2 * * * 6 7 * 7 * +3 * * 3 2 2 * * * * * 4 * * 7 * * 4 * * * 4 2 2 * 3 * * * * 3 3 5 6 * * * * * 3 +* * 5 3 4 * 4 4 * 5 4 5 5 * 5 * * * 6 6 * * 2 2 * 4 5 * 6 * 4 * * * 5 * 5 4 4 * +5 * 6 * * * 3 3 3 5 * * * 4 6 * 6 * * * 6 * 3 3 5 * 4 * 3 2 5 * 8 * 5 3 * 3 5 * +* * * * 7 5 * 2 * * * 6 4 * * * 4 2 4 * * 2 3 * * * 4 2 1 1 * * * * 4 * 4 * * * +* * 7 * * * 2 3 3 6 * * 2 4 * * 4 2 3 4 4 2 2 * * 6 * 4 2 3 4 6 6 * 4 4 * 6 * * +3 4 * * * 5 3 3 * 5 * 6 3 4 * 7 * * 5 * * 2 2 3 4 * * * * 3 * * * 6 * 6 * * 6 * +* 5 4 5 5 * * 6 * 5 * * * 6 * * * * * * 4 4 * 4 4 * * 5 3 * 4 6 * * * * * 4 * * +* * * 3 * * * * * 4 4 * * * * * * * * 4 3 * * * * 7 * 4 3 2 3 * * 5 6 * 5 4 5 * +3 5 5 6 * * 6 6 * 3 2 * 5 * * * 7 6 6 * 4 3 6 * * * * * 4 * 4 5 5 5 * * 5 * * 2 +2 * * * * * 5 * * 4 2 2 4 5 * * * * * * 3 * 4 * 8 * 6 * * 5 * * * * * 5 * * 6 3 +* 6 * * * 5 * * * * 3 3 * * 3 3 3 4 * 3 3 3 6 * * * 5 3 3 * * 8 * * 6 * 6 * * * +* 5 * 6 4 5 * 5 4 * * 5 * 5 2 1 1 2 2 2 2 * * * 6 * * 3 3 5 * * * 6 * * 6 * 7 * +3 * 3 * * 5 * 2 1 3 5 * * * 1 2 * 3 3 * 4 3 4 3 5 * 6 * * 5 * * * 6 * 5 * * * 4 +* 3 4 5 * * 3 3 2 3 * * * 4 2 4 * 4 * * 3 * 2 3 * * 6 * * * 4 6 * 7 * 6 5 * * * +2 * 3 * * 6 * 4 * * 5 * 4 2 * 5 * 6 4 4 4 4 * 3 * * 7 * * 4 3 * * * * * * 6 * * +3 5 * 5 * * 5 * * 6 5 * 3 3 3 * * * * 5 * * 4 3 4 * * * 4 * 4 5 7 * 5 4 5 * * * +* * * 4 5 * 5 * * * * 6 * 4 * 4 5 6 * * * * 4 * 3 5 * 6 5 4 * * * * 2 1 * * 7 4 +* * 4 3 * * 5 5 * 5 * * * * 2 3 * * 6 6 7 * 5 3 5 * * * * * 4 5 4 3 2 3 6 * * * +4 4 4 * 5 4 * * 4 4 3 4 5 4 3 3 * * * * * * 5 * * * * 7 * 5 * 2 * 1 1 * * * * 4 +* * 4 * 4 * 5 5 * * 3 2 * * 3 * 6 * 5 3 3 3 * * * 6 4 * * 6 3 4 3 3 3 4 6 * 6 * +* 6 * 4 5 * * 5 * * 4 * 4 4 * 3 * * 2 1 1 2 3 * * 5 * 5 * * * 3 * * 4 * * 3 * * +* 5 * 4 * * * * 4 4 * 3 3 * 4 5 5 4 2 2 * 2 2 4 * * 5 * 6 * 5 * 4 * * 5 4 5 5 4 +2 * 4 * 6 7 * 6 * 2 3 * 5 4 * * * * 3 3 * 3 2 * 5 6 * * 5 * 5 2 3 4 * 4 * * * * +2 2 4 * * * * * 4 2 3 * * * 6 6 6 * 3 * 3 * 3 4 * * * 5 4 * * 3 3 * 3 4 * * * * +* 2 4 * * 5 4 * 4 * 4 3 5 * * * * 4 4 4 4 4 * 5 * * * 5 * 5 5 * * 4 4 * 4 5 6 * +3 * 4 * * 4 2 1 4 * * 3 4 * 5 5 * 4 * * * 3 * * 4 * 5 * * * 4 * 6 * * 5 * 5 * * +* 3 5 * * * 4 3 5 * * * 3 * 3 3 * 3 3 * 4 3 2 2 3 3 5 * 5 4 5 * 5 * 6 * * * * * +2 3 * * * * * * * * 6 4 5 5 * 4 3 4 4 4 * 2 2 2 3 * * 5 * 4 * * 6 5 * * * 7 6 4 +3 * 6 * 6 5 5 5 7 * 6 * * * * 3 * * * * 6 * 4 * * 5 * * 3 * * * * * * 6 * * * * +* * * 4 * * 4 * * * * * * 6 4 4 3 4 * * * * 7 * 6 * 3 3 3 5 * * 6 * 5 6 * 8 * 4 +* 6 * 5 5 * 5 * * * * * * 5 * * 3 4 4 6 * * * * * 4 3 4 * 5 * 6 * 5 * * * * * 2 +2 4 * 5 * * 4 5 * 7 * 7 * * 4 3 * * * 5 * * * 7 * 6 * * * 5 * 5 * * 5 * * 4 2 1 +3 * 4 * * 4 4 * * 6 * 7 * * 3 2 2 5 * * 3 4 * 6 * * * * * 4 3 5 * 4 3 * 5 4 2 1 +* * 4 3 5 * 5 * 6 * * * * 6 * 2 1 4 * 6 4 3 4 * * * * 5 4 * 4 * * 3 3 3 * * * 3 +* 6 5 * 6 * 5 * * 6 * 7 * 5 * 4 2 * * * * * 5 * 6 * * 3 3 * * 5 5 * 3 * 5 * * * +* * * * * * 3 4 * 6 * * 2 4 * * 2 2 4 5 6 * * 5 5 * 5 * 2 3 * * 4 * 3 3 * 6 7 * +5 * 6 * * 4 3 4 * 5 * 5 4 4 * 3 2 2 4 * * 5 * * * 4 * 2 2 3 6 * 5 3 2 3 * * * * +* * 4 2 2 3 * * 5 * 4 * * * 2 2 3 * * * * 3 3 4 5 * 4 3 4 * * * * 3 * 4 5 * * * +4 * 3 2 3 4 * * * 6 * 5 5 4 3 2 * * * 5 3 3 3 * 3 * 5 * * * 6 * 5 4 * 4 * * 6 * +* 3 3 * * * 5 5 * * * 4 * * 3 * 4 6 * 4 2 * * 3 2 2 * * * 5 5 * 5 * 5 * 5 5 * 3 +2 4 * 7 * * 4 * 4 5 3 5 * 7 * 4 3 * * * 3 5 * 5 3 3 4 6 * * 4 * 4 * * 5 * * 4 * +* 6 * * * * 6 5 * 4 * 5 * * * 3 * 4 4 3 * 4 * * * * 3 * * 6 * 5 4 4 * 4 * 5 * 3 +* * * * * * * * * 5 * * 5 * 5 4 4 * 3 2 3 4 * 4 3 3 * 5 * 6 * * * 3 2 4 3 * 4 * +3 6 * * * 8 * * 4 5 * 7 * 4 * * 4 * 4 * 3 * 3 1 1 3 3 4 * 5 * 5 3 3 * 4 * 3 4 * +1 * * 7 * * * 6 * 5 * * * 5 5 * 5 4 * 5 5 * 3 1 2 * * 2 2 4 * 2 1 * 4 * * 4 5 * +3 4 5 * * * 5 * * 6 * 6 * * 4 * 5 * * * * 3 4 * 4 3 3 3 3 * 2 1 2 2 4 * 4 * * * +* * 6 * * 6 * 5 * * 3 4 * * 4 2 * * * 5 3 * 4 * * 1 1 * * 3 3 2 4 * 4 3 4 4 6 * +4 * * * 4 * * 5 4 * 3 3 * * 2 1 4 * * 3 2 3 * 6 5 4 3 3 4 * 4 * * * 4 * * 2 * * +* 4 3 2 3 5 * 6 * 5 * 3 2 2 1 - 2 * 5 * 2 3 * * * * * 2 3 * * 5 * 6 * 5 4 3 3 2 +* 4 2 2 2 * * * * 7 * 5 2 1 - - 1 2 4 * 3 4 * * * 5 4 3 * 3 3 * 3 * * * 4 * 4 2 +4 * * 4 * 7 * 6 * * * * * 4 2 1 1 2 * 4 * 5 * 6 5 * 4 * 3 1 2 2 4 5 * 6 * * * * +* * 5 * * * * 5 4 * * * * * * 3 4 * 6 * 5 * * * 5 * 6 * 5 2 2 * 4 * * 5 * 5 5 * +5 * 5 4 * 7 * 5 * 4 4 * 6 * 6 * * * * * 5 * 7 * 6 * 7 * * * 4 3 * * 4 4 * 2 3 * +* * 6 * 5 * * 5 * 5 3 4 * 4 * * * * * 6 * 3 * * 5 * * * 6 * * 2 2 4 * 5 4 3 4 * +* * * * 5 * 5 6 * * * 3 * 4 4 4 6 * * * 4 5 5 5 6 * * * 5 4 4 3 1 3 * * * * 5 * +5 * * * 6 5 * * * * 4 3 3 * 5 * 5 * * 5 * * * * * * * * * 3 * * 2 4 * * * * 5 * +* * 5 * * * * * * 7 * 3 4 * * * 6 * 5 * 5 * 8 * * 6 6 * * 6 5 6 * 5 * 5 * 5 * 2 +* 3 2 3 6 * * * * * * 5 * * 6 5 * * 5 3 4 * * * * 5 * * * * * * * * 2 2 3 * 3 1 +2 3 1 3 * * * 5 5 * * 6 * * 5 * * * * 4 * 5 * * * 6 * 5 * 5 6 * * 6 3 2 4 * 3 - +* 4 * 5 * 6 * 3 4 * * * 4 * * 7 * 8 * 6 * 5 4 5 * * 5 4 4 * 6 * * * * 3 * * 4 2 +* 6 * * 6 * 3 3 * * * 4 3 4 * * * * * * 4 * * 3 4 * * * 3 * * * * 5 3 5 * 7 * * +3 * * * * * 4 3 * * * 3 2 * 6 * * 6 5 3 4 * * 3 3 * 6 5 4 4 * 6 4 4 * 5 * * * 3 +* 5 * * 6 * 5 * 6 * * 3 4 * 5 * * * 3 * 3 3 4 * 3 3 * * * 4 3 * * 5 * * 4 * 4 2 +3 * 4 3 4 * 6 * 6 * 6 5 * * 6 6 * * 4 3 * 2 2 * 3 4 * 7 * * 3 4 * 6 * 3 3 4 * 2 +* 3 * 2 4 * * 5 * * * * * * * * * * 3 4 * 5 4 4 5 * * * 4 * 3 3 * * 3 3 4 * * 2 +3 5 5 * 6 * 6 * * 5 5 5 7 * 6 * * 5 * 5 * * * * * * 6 3 3 2 3 * 3 2 3 * * * 5 3 +* * * * * * 5 * 4 * 3 * * * 6 4 4 4 * 5 * * 6 * * * 4 * 2 2 * 2 2 1 3 * * 7 * * +5 * 7 6 6 * 5 4 5 4 5 * * * * * 3 * 5 6 * 6 6 * 5 4 * 4 * 3 3 4 3 * 4 6 * * * * +* * * * * 4 * * * * * 5 * 7 * 4 4 * * * * * * * 3 3 * 4 2 3 * * * 6 * * * 6 5 3 +4 6 7 * * 5 3 4 * * 3 4 * * 5 5 * 6 * 7 * * 5 4 * 4 4 * 3 4 * * * * * 7 * * 4 * +* * * * * * 3 4 5 5 4 5 * * * * * 5 * * 5 * 5 5 * * 4 * * 3 * * 7 * * * 5 * 5 * +* * 5 5 5 4 * * * * * * * 4 5 * * 6 4 4 4 * * * * 5 5 * 4 2 2 3 * * 5 4 * 3 5 * +3 3 3 * * 2 4 * 5 4 * * 5 3 4 * * * * 3 * 4 * 6 * * 4 * 2 1 2 4 4 4 * 4 4 5 * * +* 3 4 * 3 2 3 * 3 3 5 6 * * 4 * 6 * 5 * 4 5 5 * 6 6 * 5 4 4 * * * 3 2 * * * * 3 +4 * * 3 2 2 * 4 3 * * * * 4 5 * 5 4 * 5 * * * * * * * * * * * 5 * 3 2 4 * * 5 3 +* * 5 * 3 4 * 5 * 5 5 6 6 * 5 * 4 * * 7 * 6 4 3 4 * * 7 6 * 4 3 2 2 * 3 3 3 * * +4 4 5 * 5 * * 5 * 5 * * * * * 2 3 * * * * * 4 3 3 5 * * * 5 5 * 3 3 4 * 2 3 5 4 +* * 6 * 6 * 5 * 4 * * 5 3 3 2 1 1 3 * * * * * * * 5 * * * * * * 6 * * 5 4 * * * +4 * * * 5 * 4 3 5 * * 4 2 1 1 2 2 3 4 * 5 5 4 4 3 * * * * * * * * * * * * 5 * 3 +3 * * * 5 4 5 * * 5 4 * * 4 3 * * 5 * 4 * 4 * 3 3 4 4 4 5 * 7 * * * 8 * * 5 3 2 +* 4 5 5 * * * * * * 4 4 * * * 5 * * * 5 3 * * 5 * * 2 3 * 5 * * * * * * 5 * * 2 +2 4 * * 4 6 * * * * 4 * 4 * 5 * 6 * * * 4 6 * 5 * 4 3 * * * 3 5 * 5 4 4 5 * 5 * +2 * * 5 4 * * * 6 * 3 2 3 3 4 * * 6 * 7 * * * 4 4 * 5 5 * 4 2 2 * 4 3 * * 5 6 * +4 * 5 * * 5 5 * 4 2 2 2 * 4 * 3 4 * * * * 7 5 5 * * * * 6 * 3 2 3 * * 6 * * * * +* * 5 6 * 6 * 5 4 * 1 2 * * 3 2 3 * 7 * * * * * * * 7 * * * 5 * 4 4 * 6 * * * * +4 5 * * * * * * * 4 3 2 5 * 4 3 * 6 * * 8 * 7 * 5 * 5 * * 7 * * * 3 4 * * 5 4 3 +* * 5 6 * 6 6 * * * 3 * 6 * * 4 * * * * * * * 4 4 3 6 * * * * * 6 4 * * * 4 3 * +* * * 6 * 5 * * * 4 4 * * * 4 3 * * * * 5 5 * * 4 * * * * 5 4 * * * 4 5 6 * * 3 +4 * * * * 6 * 7 * 3 3 * * * 5 3 5 * * 5 * 2 4 * 7 * 7 * * 3 1 2 3 3 3 * * * * 2 +* 6 * 7 * 7 * * 4 * 3 5 * * * * 5 * * 4 3 3 4 * * * * 5 * 3 2 2 2 3 * 7 * 5 2 1 +3 * * 4 * * * * 5 2 2 * * 6 5 5 * * 5 * 3 * * 5 6 * * 5 3 4 * * 4 * * * * 3 1 1 +* 4 3 2 4 * * * * 3 2 4 * 6 * * 5 4 * 5 * 7 * * 4 * * * 4 * * * * 5 * * * 4 2 * +3 * 3 1 3 * 6 5 * * 1 3 * * * * 5 * 4 * * * * * 4 4 6 * * 6 6 7 * 5 4 5 * 4 * 4 +3 * * 2 3 * 3 * 4 4 3 3 * 5 5 5 * * 5 5 * 7 * 5 * 2 * * * * * * * * 4 * 4 4 * * +3 * 4 3 * 3 3 3 3 * * 4 5 * 5 * * 6 * * 6 * * 3 1 2 2 3 4 * * 7 * 5 * * 4 * 3 2 +* 3 * 2 2 3 * 3 * 5 5 * * * * * 6 * * * * * 4 3 2 2 1 1 3 4 4 * * 4 4 * 4 3 2 1 +2 3 2 1 1 * 5 * 6 * * 5 5 4 5 * 6 * * * 5 5 * 5 * * 2 3 * * 4 5 5 * 3 4 * 4 * 2 +2 * 3 3 3 4 * * * * 6 * * 2 4 * 6 * * 6 4 * * * * 5 5 * * 4 * * * 3 3 * * 7 * 3 +* 3 * * * 5 * 6 * * * 4 4 * 3 * * 7 * * * 4 3 4 4 * * * 6 4 3 4 5 * 3 3 * * * 4 +3 4 5 * * 5 * 5 4 * 4 * 2 2 3 4 * * * 5 * 2 1 3 * 7 * * * * 3 3 * * 5 3 4 * * * +* * 4 * 6 5 * * 5 4 4 3 2 2 * 3 4 * 3 2 2 3 3 * * * * 7 * 5 * * 6 * * * 3 3 4 2 +3 3 3 * * * 5 * * * * 3 * 4 4 * 3 2 2 - 1 * * 5 7 * * * 4 * 5 * 6 * * 4 3 * 2 - +* 2 2 4 * 4 * 4 5 6 * 6 4 * * 5 4 * 3 2 2 2 4 * * * 5 4 * 2 3 * * 7 * 4 3 * 4 2 +1 2 * 2 1 3 4 * 3 * * * * 4 * * * 5 * * 3 1 3 * * 6 * 4 3 2 1 4 * * * 5 * 5 * * +- 2 2 3 2 4 * * 5 4 6 * 6 5 6 * * 6 * * * 2 4 * * * 3 * * 4 3 4 * * * 7 * 6 * 5 +1 3 * 5 * * * * * 2 * * * * * * * 5 * * 7 * 5 * 5 2 2 4 * * * * 5 * * * * 6 * * +2 * * * * 6 6 * 4 4 4 5 6 * * 7 5 5 * * * * 4 * 4 2 1 3 * * * 6 * 7 * * * * 3 2 +* 6 * * 6 * * 5 * 2 * * 4 * * * * * 7 * * 4 4 5 * * 2 4 * 7 * 6 * * * * 5 3 3 1 +3 * * 5 * * * * 3 2 3 4 * 4 * 6 7 * * * 3 2 * * * 6 * 5 * 5 * 5 * * 4 2 3 * 3 * +* 6 * 5 4 5 * * 2 - 1 * 3 3 2 * * * 4 3 3 3 4 6 * 7 * 5 * 5 4 5 * 3 1 - 3 * 4 1 +* * 5 * * 3 2 2 2 1 2 3 * 4 4 5 6 4 2 2 * * 5 * * * * 4 4 * * * 3 2 2 3 5 * 4 1 +* 5 * * * 3 2 3 4 * 2 2 * * * * * * 3 4 * * * * * * 6 * 4 * * * 4 2 * * * * 4 * +1 4 * 7 5 4 * * * * 2 1 3 5 * * * * * 4 * * * 6 7 * 6 * 5 5 * * * 3 4 * * 5 * 3 +1 3 * * * * 6 * * 4 1 1 3 * 6 * 5 4 3 5 * * 4 * * * 7 * * 5 * 7 * 4 3 * 4 * 4 * +2 * 4 * 7 * 6 * * 4 3 3 * * * 4 * 1 2 * * 5 3 4 * * * * 6 * * 5 * * 3 1 3 2 4 * +* 4 4 5 * * * 4 4 * * * 4 3 4 * 4 3 3 * * 6 * 4 3 5 * 4 * * 7 * 6 * 3 1 2 * 3 2 +* 4 * * * 6 * 3 4 * * * 3 1 3 * * 2 * 5 * * * 5 * 3 3 4 5 * * * 6 * 4 2 * 4 5 * +* 5 4 5 * 4 2 3 * * * 5 4 * 3 3 3 3 2 * 5 * * * 4 * 3 * * 4 5 * 6 * 6 * 5 * * * +* * 3 * 4 5 * 4 3 4 * 5 * * 4 3 * 2 2 1 4 * 6 * 3 2 * 3 3 3 * 4 * * * * 5 * * 3 +* * 5 4 * * * * 3 3 4 * * 7 * * 4 * 2 2 5 * 5 2 2 2 3 2 3 * 4 4 * * 5 4 * 4 4 2 +2 3 * * 6 * * * * 4 * * * * * * 4 2 3 * * * * 2 2 * 2 * 5 * * 2 2 3 3 * 5 * 3 * +1 3 5 * 6 * 6 6 * * 7 * 6 * 6 * 3 3 * 7 * * 4 2 * 2 3 3 * * 5 4 2 2 * 5 * * 5 2 +2 * * 4 * * * 4 * * * * 4 4 * 5 * 5 * * * * 3 2 2 3 3 * 6 5 * * * 4 5 * * * * 2 +* 5 4 5 * * * 4 4 6 * 4 * 4 * 5 * * 5 6 * * 3 2 * 2 * * * * 6 * 4 * * * * * 5 * +* 5 * * 3 3 2 2 * * 5 4 4 * 4 4 * 6 * * 4 5 * 4 3 3 4 * 6 * * 4 4 4 5 * * 5 * 3 +* * 5 4 4 3 3 3 4 * * * 4 * 4 * 3 * * 5 * 5 * * 4 * 5 3 4 * * 5 * * 3 5 * 5 4 * +5 * 4 * * * * * 4 4 5 4 * 5 * 3 3 4 4 4 * * 6 5 * * * * 3 4 * * 5 4 3 * * 5 * * +* * 3 3 4 4 3 4 * * 3 * 4 * * 4 3 * * 3 4 * * * 5 6 * 4 2 * 6 * * 2 * 6 * 5 * * +4 4 3 3 * 3 1 2 * * 5 3 * 4 * * 4 * 5 * 4 4 * * 5 * * 2 1 3 * * 4 3 3 * * 4 2 2 +* * 4 * * * 3 4 6 * 4 * 3 4 3 4 * 2 4 * * 4 4 5 * * 5 3 2 4 * * 2 2 * 5 * 3 2 1 +3 4 * * 5 5 * * * * 4 3 * 4 * 4 3 3 4 * 4 * * 6 * * * 4 * * 5 4 3 3 * 4 4 * 3 * +1 * 3 3 3 * * 6 6 6 * 5 4 * * * 4 * * 3 3 5 * * * 6 * * 5 * 4 * * 5 4 * 3 * 4 2 +3 3 2 1 * 4 5 * * * * * * 4 5 * * 5 * 4 4 * * * 4 4 * 7 * 5 5 * * * * 5 5 4 5 * +* * 2 2 4 * 5 * * * 6 * * 5 5 * * 4 3 * * * * * 3 2 * * * * * 6 6 * * * * * * * +* * 5 3 * * 6 * * 3 4 * * * * * 4 * 3 3 5 * * * 3 3 5 * 7 * * * * 4 4 4 6 * * 3 +4 * * * 7 * 6 * 5 3 4 * 6 * * 4 3 3 * 1 3 * * 7 * 4 * * * 5 * 6 * 5 4 * 5 * 5 3 +* 5 * * * * 6 * * 4 * * 5 5 4 3 * 4 4 4 4 * * * * 4 * 5 * 5 3 5 * * * * * 5 * * +2 5 * * * * 6 * * 6 * 6 * * * 3 4 * * * * 4 4 * 4 3 3 3 4 * * 3 * 6 * * 4 * * * +* 4 * * 6 4 * * 5 * * * 5 6 5 * 4 * * * * 5 4 3 3 * 3 * 4 * 5 4 4 * 5 3 4 5 * * +* 6 5 * * 4 4 5 * 4 * 6 * * * 4 * 4 5 * * * * * 5 4 * 2 4 * * 2 * * 4 * 3 * * * +* * * 6 * 3 * * 4 4 4 * * * * 5 4 * 5 4 5 * * * * * 4 2 3 * 5 4 5 * 4 3 4 * * 3 +* * * * 3 2 4 * * 3 * * * * * 3 * * * * 3 3 * 6 6 * * 4 5 * 5 * * 3 * 3 * 6 4 2 +5 * 8 * 4 2 4 * 6 * 6 * 7 * 4 2 2 3 4 * 3 3 4 * * 6 * * * * 6 * 4 3 3 6 * * * 3 +* * * * * 3 * * * 5 * * 5 * 4 2 2 2 4 4 4 * * 5 * 4 * * * * 7 * 5 4 * * * 7 * * +* * * * 6 5 * 5 4 * * * 3 3 * * 3 * * * * 4 4 * 3 3 3 4 5 * * * * * * * * 5 * 4 +* * 5 * * * 4 * 2 4 * 5 3 4 * * 4 3 5 6 5 * 3 3 * 1 2 * 4 4 4 5 * * * * 5 4 * 2 +* 4 4 4 * 6 * 5 3 3 * 5 * * 6 * 5 3 * * * 5 * 5 4 3 4 * * 2 * 2 2 4 * * * 4 3 2 +3 * 4 * 5 * * * * 3 2 * * 6 * * * * 5 * * 4 * * * * 5 * 5 3 1 2 1 3 4 * * * 3 * +4 * 6 * 7 * 6 5 * 4 4 5 5 * * 6 * * 4 2 3 4 6 * 7 5 * * * 2 2 4 * 3 * 4 * 4 4 * +* * 5 * * * * 4 4 * * * * 6 5 5 * * 2 - 2 * * * * * 3 3 3 4 * * * 6 4 5 4 4 * 3 +3 4 4 * 5 * * * 5 * 6 * * * * * 5 4 3 1 3 * 7 * 6 3 3 1 3 * * * * * * * * * 6 * +* 2 * 3 3 3 4 * * 4 5 * 4 4 5 * 5 * * 4 5 * 5 * 4 * 4 * 6 * * 5 6 * * 7 * * * * +1 2 1 2 * 1 1 2 3 * * 2 1 1 * 3 * * * * * * 3 1 3 * 4 * * * 4 * 3 * * * 4 * * * diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/gamelogic.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/gamelogic.c @@ -1,55 +0,0 @@ -#include <string.h> -#include "minesweeper.h" -#include "gamelogic.h" - -void selection(WINDOW *gameWin, char **dispboard, char **mineboard, int WIDTH, int HEIGHT) -{ - int chrow, chcol; - bool gameOver = true; - int yMax, xMax, yMiddle, xMiddle; - getmaxyx(gameWin, yMax, xMax); - yMiddle = yMax / 2; - xMiddle = xMax / 2; - - do - { - mvprintw(1, 1, "Choice (row, col): "); - scanw("%d %d", &chrow, &chcol); - chrow++; - chcol++; - mvprintw(1, strlen("Choice (row, col): ") + 1, "(%d,%d)", chrow-1, chcol-1); - refresh(); - mvprintw(1, 1, CLEAR); - transfer(dispboard, mineboard, chrow, chcol); - reveal(gameWin, dispboard, chrow, chcol); - getchar(); - } while ((chrow < 0 || chrow > WIDTH-1 || chcol < 0 || chcol > HEIGHT-1) && !gameOver); - - if (gameOver) - { - game_over(gameWin, mineboard, yMiddle, xMiddle); - print(gameWin, mineboard, WIDTH, HEIGHT); - filewrite(mineboard, WIDTH, HEIGHT); - } -} - - -bool transfer(char **dispboard, char **mineboard, int chrow, int chcol) -{ - dispboard[chrow][chcol] = mineboard[chrow][chcol]; - return (dispboard[chrow][chcol] == MINE) ? true : false; -} - - -void reveal(WINDOW *gameWin, char **dispboard, int chrow, int chcol) -{ - mvwaddch(gameWin, chrow, chcol, dispboard[chrow][chcol]); - wrefresh(gameWin); -} - -void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) -{ - wclear(gameWin); - mvwprintw(gameWin, yMiddle, xMiddle, "Game over :("); - wrefresh(gameWin); -}- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c @@ -0,0 +1,56 @@ +#include <string.h> +#include "minesweeper.h" +#include "gameplay.h" + +void selection(WINDOW *gameWin, char **dispboard, char **mineboard, int WIDTH, int HEIGHT) +{ + int chrow, chcol; + bool gameOver; + int yMax, xMax, yMiddle, xMiddle; + getmaxyx(gameWin, yMax, xMax); + yMiddle = yMax / 2; + xMiddle = xMax / 2; + + do + { + mvprintw(1, 1, "Choice (row, col): "); + scanw("%d %d", &chrow, &chcol); + chrow++; + chcol++; + mvprintw(1, strlen("Choice (row, col): ") + 1, "(%d,%d)", chrow-1, chcol-1); + refresh(); + mvprintw(1, 1, CLEAR); + gameOver = transfer(dispboard, mineboard, chrow, chcol); + reveal(gameWin, dispboard, chrow, chcol); + getchar(); + } while ((chrow < 0 || chrow > WIDTH-1 || chcol < 0 || chcol > HEIGHT-1) || !gameOver); + + if (gameOver == true) + { + game_over(gameWin, mineboard, yMiddle, xMiddle); + getchar(); + print_board(gameWin, mineboard, WIDTH, HEIGHT); + filewrite(mineboard, WIDTH, HEIGHT, chrow, chcol); + } +} + + +bool transfer(char **dispboard, char **mineboard, int chrow, int chcol) +{ + dispboard[chrow][chcol] = mineboard[chrow][chcol]; + return (dispboard[chrow][chcol] == MINE) ? true : false; +} + + +void reveal(WINDOW *gameWin, char **dispboard, int chrow, int chcol) +{ + mvwaddch(gameWin, chrow, chcol, dispboard[chrow][chcol]); + wrefresh(gameWin); +} + +void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) +{ + wclear(gameWin); + mvwprintw(gameWin, yMiddle, xMiddle, "Game over :("); + wrefresh(gameWin); +}+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/main.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/main.c @@ -1,6 +1,5 @@ #include "minesweeper.h" - int main(int argc, char **argv) { main_win(); diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c @@ -2,8 +2,7 @@ #include <string.h> #include <time.h> #include "minesweeper.h" -#include "gamelogic.h" - +#include "gameplay.h" void main_win() { @@ -137,7 +136,6 @@ void game_win(int WIDTH, int HEIGHT, int NMINES) char **mineboard = init_mineboard(gameWin, WIDTH, HEIGHT, NMINES); selection(gameWin, dispboard, mineboard, WIDTH, HEIGHT); - filewrite(mineboard, WIDTH, HEIGHT); free(dispboard); free(mineboard); @@ -159,7 +157,7 @@ char **init_dispboard(WINDOW *gameWin, int WIDTH, int HEIGHT) else { fill_dispboard(dispboard, WIDTH, HEIGHT); - print(gameWin, dispboard, WIDTH, HEIGHT); + print_board(gameWin, dispboard, WIDTH, HEIGHT); getchar(); } @@ -265,7 +263,7 @@ void fill_spaces(char **mineboard, int WIDTH, int HEIGHT, int NMINES) } -void print(WINDOW *gameWin, char **mineboard, int WIDTH, int HEIGHT) +void print_board(WINDOW *gameWin, char **mineboard, int WIDTH, int HEIGHT) { int i, j; @@ -274,16 +272,16 @@ void print(WINDOW *gameWin, char **mineboard, int WIDTH, int HEIGHT) for (j = 0; j < HEIGHT; j++) { mvwaddch(gameWin, j + 1, i + 1, mineboard[i][j]); - wrefresh(gameWin); + wrefresh(gameWin); } } } -void filewrite(char **mineboard, int WIDTH, int HEIGHT) +void filewrite(char **mineboard, int WIDTH, int HEIGHT, int hitrow, int hitcol) { - FILE *mnsOut = fopen("mnsout.txt", "w"); int i, j; + FILE *mnsOut = fopen("mnsout.txt", "w"); if (mnsOut == NULL) { @@ -292,7 +290,7 @@ void filewrite(char **mineboard, int WIDTH, int HEIGHT) } else { - fprintf(mnsOut, "Mine hit at position (%d, %d)\n\n", 1, 2); // add actual position + fprintf(mnsOut, "Mine hit at position (%d, %d)\n\n", hitrow, hitcol); // add actual position fprintf(mnsOut, "Board overview\n\n"); for (i = 0; i < WIDTH; i++)