commit 3ecf3e75f493c09cff5ad09ae4e8ac48758db59b parent 9889701c8a5668c403ccae8868841e250889bd9f Author: Christos Margiolis <christos@margiolis.net> Date: Wed, 22 Jan 2020 05:12:41 +0200 improved minesweeper Diffstat:
47 files changed, 317 insertions(+), 789 deletions(-)
diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/bin/minesweeper b/assignment-1.5-arrays-pointers-files/minesweeper/bin/minesweeper Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/gameplay.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/gameplay.h @@ -3,11 +3,11 @@ #include "minesweeper.h" -#define DEFUSEKEY 'd' - -void selection(struct _win_st*, char **, char **, int, int, int); -bool transfer(char **, char **, int, int, int, int *); -void reveal(struct _win_st*, char **, int, int); -bool defused(char **, char **, int, int, int, int *); +void play_minesweeper(struct _win_st*, char **, char **, int, int, int); +void transfer(char **, char **, int, int, int, int *); +void reveal(struct _win_st*, char **, int, int, int, int); +void flag_handler(); +bool is_flagged(); +bool is_defused(char **, 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 @@ -14,14 +14,14 @@ #include "settings.h" #include "gameplay.h" +#include "navigation.h" #include "outputs.h" +#include "wins.h" -#define HIDDEN '#' +#define BLANK ' ' #define MINE '*' #define CLEAR " " -void start(); -void game_win(int, int, int); char **init_dispboard(struct _win_st*, int, int); void fill_dispboard(char **, int, int); char **init_mineboard(struct _win_st*, int, int, int); @@ -33,4 +33,4 @@ bool outof_bounds(int, int, int, int); int8_t adj_mines(char **, int, int, int, int); void fill_spaces(char **, int, int, int); -#endif- \ No newline at end of file +#endif diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/navigation.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/navigation.h @@ -0,0 +1,14 @@ +#ifndef NAVIGATION_H +#define NAVIGATION_H + +#include "minesweeper.h" + +void navigate(struct _win_st*, char **, char *, int *, int *); +void getmv(struct _win_st*, char *, int *, int *, int, int); +void mvup(int *, int *); +void mvdown(int *, int *, int, int); +void mvleft(int *, int *); +void mvright(int *, int *, int, int); +void update_curs(struct _win_st*, int, int); + +#endif+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/outputs.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/outputs.h @@ -3,10 +3,11 @@ #include "minesweeper.h" -void game_won(struct _win_st*, char **, int, int); -void game_over(struct _win_st*, char **, int, int); - +void print_grid(struct _win_st*, int, int); void print_board(struct _win_st*, char **, int, int); + +void game_won(struct _win_st*, int, int); +void game_over(struct _win_st*, char **, int, int); void filewrite(char **, int, int, int, int, const char *); #endif \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/settings.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/settings.h @@ -3,10 +3,10 @@ #include "minesweeper.h" -void main_win(); -void set_mode(struct _win_st*); + int set_cols(struct _win_st*, int); int set_rows(struct _win_st*, int); int set_nmines(struct _win_st*, int); +void init_colors(); #endif \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/wins.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/wins.h @@ -0,0 +1,10 @@ +#ifndef WINS_H +#define WINS_H + +#include "minesweeper.h" + +void main_win(); +WINDOW *menu_win(int *, int *); +WINDOW *game_win(int, int, int); + +#endif diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/man b/assignment-1.5-arrays-pointers-files/minesweeper/man diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt b/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt @@ -1,9 +1,34 @@ -Mine hit at position (1, 5) +Mine hit at position (15, 24) Board overview -- - - - - -- - - - - -- - - 1 1 -- - - 1 D -- - - 1 1 +- - - - - - - - - 1 1 1 - - - - - - 1 * * 1 - - - - - 1 1 1 +- - - - - - - - - 1 * 1 - 1 1 1 - - 1 2 2 1 - - - - - 1 * 1 +- - - - - - - - - 1 1 1 - 1 * 1 - - - - - - - - - 1 1 2 1 1 +- - - - - - - - - - - - - 1 1 1 - - - - - - - - - 1 * 1 - - +- - - - - - - - - - - - - - - - - - - - - 1 1 1 - 2 2 2 - - +- - - - - - - - - - - - - - - - - - - - - 1 * 1 - 1 * 1 - - +- - - - - - - - - - - - - - - - - - - - - 2 2 2 - 1 1 1 - - +- - - - - - - - - 1 1 1 - - - - - - - - - 1 * 1 - - 1 1 1 - +- 1 1 1 - - - - - 2 * 2 - - - - - - - - - 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 - - - +- - 1 1 1 - - - - - - - - - - - - - - - - - - - 1 1 1 - - - +- - 1 * 1 - - - - - - - - - - - - - - - - - - - - - - - - - +- - 1 1 1 - - - - - - - - - - - - - - - - - - - - - - - - - +- - 1 2 2 1 - - - - - - - - - - - - - - - - - - - - - - - - +- - 1 * * 1 - 1 1 1 - - - - - - - - - - - - - - - - 1 1 1 - +- - 1 2 2 2 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 1 1 - - - - 1 1 1 - - - - - - - - - - - - - - 1 1 1 - - - +- - - - - - - 1 * 1 - - - - - - - - - - - - - - - 1 1 1 - - +- - - - - - - 1 1 1 - - - - - - - - - - - - - - - 1 * 1 - - +- - - - - - - - - - - - - - - - - - - - - - - - - 1 1 1 - - diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/gameplay.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/gameplay.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/main.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/main.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/minesweeper.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/minesweeper.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/navigation.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/navigation.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/outputs.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/outputs.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/settings.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/settings.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/wins.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/wins.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c @@ -1,70 +1,72 @@ #include "gameplay.h" -void selection(WINDOW *gameWin, char **dispboard, char **mineboard, int COLS, int ROWS, int NMINES) +void play_minesweeper(WINDOW *gameWin, char **dispboard, char **mineboard, int COLS, int ROWS, int NMINES) { - int chRow, chCol; - bool gameOver; - int numDefused = 0; + int mboardXLoc = 0, mboardYLoc = 0; + bool gameOver = false; + int numDefused = 0, numFlagged = 0; int yMax, xMax, yMiddle, xMiddle; + char move; getmaxyx(stdscr, yMax, xMax); yMiddle = yMax / 2; xMiddle = xMax / 2; do { - mvprintw(1, 1, "Choice (col, row): "); - scanw("%d %d", &chCol, &chRow); - mvprintw(1, strlen("Choice (col, row): ") + 1, "(%d,%d)", chCol, chRow); - refresh(); - mvprintw(1, 1, CLEAR); - gameOver = transfer(dispboard, mineboard, chCol, chRow, NMINES, &numDefused); - mvprintw(1, xMiddle-9, "Defused mines: %d/%d", numDefused, NMINES); - reveal(gameWin, dispboard, chCol, chRow); - getchar(); - } while (((chCol >= 0 && chCol < COLS) && (chRow >= 0 && chRow < ROWS)) && numDefused < NMINES && !gameOver); + navigate(gameWin, dispboard, &move, &mboardXLoc, &mboardYLoc); + + if (move == '\n') + { + transfer(dispboard, mineboard, mboardYLoc, mboardXLoc, NMINES, &numDefused); + reveal(gameWin, dispboard, mboardYLoc, mboardXLoc, mboardYLoc + 1, 3*mboardXLoc + 2); + if (dispboard[mboardYLoc][mboardXLoc] == MINE) gameOver = true; + } + } while (((mboardYLoc >= 0 && mboardYLoc < COLS) && (mboardXLoc >= 0 && mboardXLoc < ROWS)) + && numDefused < NMINES && !gameOver && move != 'q'); if (gameOver == true) { game_over(gameWin, mineboard, yMiddle, xMiddle); getchar(); print_board(gameWin, mineboard, COLS, ROWS); - filewrite(mineboard, COLS, ROWS, chCol, chRow, "lost"); + filewrite(mineboard, COLS, ROWS, mboardXLoc, mboardYLoc, "lost"); } if (numDefused == NMINES) { - game_won(gameWin, mineboard, yMiddle, xMiddle); + game_won(gameWin, yMiddle, xMiddle); getchar(); - filewrite(mineboard, COLS, ROWS, chCol, chRow, "won"); + filewrite(mineboard, COLS, ROWS, mboardXLoc, mboardYLoc, "won"); } } -bool transfer(char **dispboard, char **mineboard, int chCol, int chRow, int NMINES, int *numDefused) +void transfer(char **dispboard, char **mineboard, int mboardYLoc, int mboardXLoc, int NMINES, int *numDefused) { - dispboard[chCol][chRow] = mineboard[chCol][chRow]; - return (!defused(dispboard, mineboard, chCol, chRow, NMINES, numDefused)) ? true : false; + dispboard[mboardYLoc][mboardXLoc] = mineboard[mboardYLoc][mboardXLoc]; } -bool defused(char **dispboard, char **mineboard, int chCol, int chRow, int NMINES, int *numDefused) + +void reveal(WINDOW *gameWin, char **dispboard, int mboardYLoc, int mboardXLoc, int yLoc, int xLoc) +{ + mvwaddch(gameWin, yLoc, xLoc, dispboard[mboardYLoc][mboardXLoc]); + wrefresh(gameWin); +} + + +void flag_handler() { - char c = getchar(); - if (dispboard[chCol][chRow] == MINE) - { - if (c == DEFUSEKEY) - { - dispboard[chCol][chRow] = mineboard[chCol][chRow] = 'D'; - (*numDefused)++; - return true; - } - else return false; - } } -void reveal(WINDOW *gameWin, char **dispboard, int chCol, int chRow) +bool is_flagged() { - mvwaddch(gameWin, chRow+1, chCol+1, dispboard[chCol][chRow]); - wrefresh(gameWin); + } + + +bool is_defused(char **dispboard, char **mineboard, int mboardYLoc, int mboardXLoc) +{ + return ((dispboard[mboardYLoc][mboardXLoc] == 'D')) ? true : false; +}+ \ 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,9 +1,25 @@ #include "minesweeper.h" int main(int argc, char **argv) -{ +{ + main_win(); - start(); + options_menu(); + int yMax, xMax; + WINDOW *menuWin = menu_win(&yMax, &xMax); + + int COLS = set_cols(menuWin, xMax); + int ROWS = set_rows(menuWin, yMax); + int NMINES = set_nmines(menuWin, COLS*ROWS); + + WINDOW *gameWin = game_win(COLS, ROWS, NMINES); + char **dispboard = init_dispboard(gameWin, COLS, ROWS); + char **mineboard = init_mineboard(gameWin, COLS, ROWS, NMINES); + play_minesweeper(gameWin, dispboard, mineboard, COLS, ROWS, NMINES); + + free(dispboard); + free(mineboard); + endwin(); return 0; diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c @@ -1,49 +1,5 @@ #include "minesweeper.h" -void start() -{ - int yMax, xMax; - int numSettings = 3; - getmaxyx(stdscr, yMax, xMax); - - WINDOW *menuWin = newwin(numSettings+2, xMax-10, yMax-7, 5); - box(menuWin, 0, 0); - refresh(); - wrefresh(menuWin); - keypad(menuWin, true); - - set_mode(menuWin); - - int COLS = set_cols(menuWin, xMax); - int ROWS = set_rows(menuWin, yMax); - int NMINES = set_nmines(menuWin, COLS * ROWS); - - game_win(COLS, ROWS, NMINES); - getchar(); -} - - -void game_win(int COLS, int ROWS, int NMINES) -{ - int yMax, xMax; - getmaxyx(stdscr, yMax, xMax); - - WINDOW *gameWin = newwin(43, xMax-10, (yMax/2) - 24, 5); // fix 43 - box(gameWin, 0, 0); - refresh(); - wrefresh(gameWin); - keypad(gameWin, true); - - char **dispboard = init_dispboard(gameWin, COLS, ROWS); - char **mineboard = init_mineboard(gameWin, COLS, ROWS, NMINES); - - selection(gameWin, dispboard, mineboard, COLS, ROWS, NMINES); - - free(dispboard); - free(mineboard); -} - - char **init_dispboard(WINDOW *gameWin, int COLS, int ROWS) { int i; @@ -60,7 +16,6 @@ char **init_dispboard(WINDOW *gameWin, int COLS, int ROWS) { fill_dispboard(dispboard, COLS, ROWS); print_board(gameWin, dispboard, COLS, ROWS); - getchar(); } return dispboard; @@ -73,7 +28,7 @@ void fill_dispboard(char **dispboard, int COLS, int ROWS) for (i = 0; i < COLS; i++) for (j = 0; j < ROWS; j++) - dispboard[i][j] = HIDDEN; + dispboard[i][j] = BLANK; } @@ -94,8 +49,6 @@ char **init_mineboard(WINDOW *gameWin, int COLS, int ROWS, int NMINES) place_mines(mineboard, COLS, ROWS, NMINES); add_adj(mineboard, COLS, ROWS); fill_spaces(mineboard, COLS, ROWS, NMINES); - - // tests //print_board(gameWin, mineboard, COLS, ROWS); //filewrite(mineboard, COLS, ROWS, 1, 2); } @@ -112,8 +65,8 @@ void place_mines(char **mineboard, int COLS, int ROWS, int NMINES) for (i = 0; i < NMINES; i++) { - wRand = rand() % COLS; - hRand = rand() % ROWS; + wRand = rand() % ROWS; + hRand = rand() % COLS; mineboard[wRand][hRand] = MINE; } } diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/navigation.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/navigation.c @@ -0,0 +1,80 @@ +#include "navigation.h" + +void navigate(WINDOW *gameWin, char **mineboard, char *move, int *mboardXLoc, int *mboardYLoc) +{ + int yMax, xMax; + static int yLoc = 1, xLoc = 2; + getmaxyx(gameWin, yMax, xMax); + wmove(gameWin, yLoc-1, xLoc); + + update_curs(gameWin, yLoc, xLoc); + *mboardYLoc = yLoc-1; + *mboardXLoc = (xLoc-2)/3; + mvprintw(1, 1, "Current position: (%d, %d) ", *mboardXLoc+1, *mboardYLoc+1); + refresh(); + getmv(gameWin, move, &yLoc, &xLoc, yMax, xMax); +} + + +void getmv(WINDOW *gameWin, char *move, int *yLoc, int *xLoc, int yMax, int xMax) +{ + *move = wgetch(gameWin); + switch (*move) // vim keys support!! + { + case 'k': case 'K': + case 'w': case 'W': + mvup(yLoc, xLoc); + break; + case 'j': case 'J': + case 's': case 'S': + mvdown(yLoc, xLoc, yMax, xMax); + break; + case 'h': case 'H': + case 'a': case 'A': + mvleft(yLoc, xLoc); + break; + case 'l': case 'L': + case 'd': case 'D': + mvright(yLoc, xLoc, yMax, xMax); + break; + case 'f': case 'F': + break; + case '\n': + break; + default: break; + } +} + + +void mvup(int *yLoc, int *xLoc) +{ + (*yLoc)--; + if (*yLoc < 1) *yLoc = 1; +} + + +void mvdown(int *yLoc, int *xLoc, int yMax, int xMax) +{ + (*yLoc)++; + if (*yLoc > yMax-2) *yLoc = yMax-2; +} + + +void mvleft(int *yLoc, int *xLoc) +{ + *xLoc -= 3; + if (*xLoc < 2) *xLoc = 2; +} + + +void mvright(int *yLoc, int *xLoc, int yMax, int xMax) +{ + *xLoc += 3; + if (*xLoc > xMax-3) *xLoc = xMax-3; +} + + +void update_curs(WINDOW *gameWin, int yLoc, int xLoc) +{ + wmove(gameWin, yLoc, xLoc); +}+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/outputs.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/outputs.c @@ -1,41 +1,42 @@ #include "outputs.h" -void game_won(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) -{ - wclear(gameWin); - mvwprintw(gameWin, yMiddle-11, xMiddle-18, "You defused all the mines!"); - mvwprintw(gameWin, yMiddle-10, xMiddle-10, "You won :)"); - wrefresh(gameWin); - wclear(gameWin); -} +void print_board(WINDOW *gameWin, char **board, int COLS, int ROWS) +{ + int i, j, x, y = 1; + print_grid(gameWin, ROWS, COLS); + + for (i = 0; i < ROWS; i++) + { + x = 2; + for (j = 0; j < COLS; j++) + { + mvwaddch(gameWin, y, x, board[i][j]); + x += 3; + } + y++; + } -void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) -{ - wclear(gameWin); - mvwprintw(gameWin, yMiddle-11, xMiddle-11, "You hit a mine!"); - mvwprintw(gameWin, yMiddle-10, xMiddle-10, "Game over :("); wrefresh(gameWin); - wclear(gameWin); } -void print_board(WINDOW *gameWin, char **mineboard, int COLS, int ROWS) -{ +void print_grid(WINDOW *gameWin, int ROWS, int COLS) +{ int i, j; - for (i = 0; i < ROWS; i++) + for (i = 1; i <= ROWS; i++) { + wmove(gameWin, i, 1); for (j = 0; j < COLS; j++) - { - mvwaddch(gameWin, j+1, i+1, mineboard[i][j]); - wrefresh(gameWin); - } + wprintw(gameWin, "[ ]"); } -} + wrefresh(gameWin); +} -void filewrite(char **mineboard, int COLS, int ROWS, int hitCol, int hitRow, const char *status) +// fix +void filewrite(char **mineboard, int COLS, int ROWS, int hitRow, int hitCol, const char *status) { int i, j; FILE *mnsOut = fopen("mnsout.txt", "w"); @@ -48,20 +49,43 @@ void filewrite(char **mineboard, int COLS, int ROWS, int hitCol, int hitRow, con else { strcmp(status, "won") - ? fprintf(mnsOut, "Mine hit at position (%d, %d)\n\n", hitCol, hitRow) - : fprintf(mnsOut, "Last mine defused at position (%d, %d)\n\n", hitCol, hitRow); + ? fprintf(mnsOut, "Mine hit at position (%d, %d)\n\n", hitRow+1, hitCol+1) + : fprintf(mnsOut, "Last mine defused at position (%d, %d)\n\n", hitRow+1, hitCol+1); fprintf(mnsOut, "Board overview\n\n"); for (i = 0; i < ROWS; i++) { for (j = 0; j < COLS; j++) - fprintf(mnsOut, "%c ", mineboard[j][i]); + fprintf(mnsOut, "%c ", mineboard[i][j]); fprintf(mnsOut, "\n"); } - mvprintw(1, 1, "Session written to file"); + mvprintw(1, 1, "Session written to file %s", CLEAR); refresh(); + getchar(); } fclose(mnsOut); +} + + +void game_won(WINDOW *gameWin, int yMiddle, int xMiddle) +{ + wclear(gameWin); + wrefresh(gameWin); + mvwprintw(stdscr, yMiddle-2, xMiddle-7, "You defused all the mines!"); + mvwprintw(stdscr, yMiddle-1, xMiddle-6, "You won :)"); + mvwprintw(stdscr, yMiddle, xMiddle-11, "Press any key to continue"); + refresh(); +} + + +void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) +{ + wclear(gameWin); + wrefresh(gameWin); + mvwprintw(stdscr, yMiddle-2, xMiddle-6, "You hit a mine!"); + mvwprintw(stdscr, yMiddle-1, xMiddle-4, "Game over :("); + mvwprintw(stdscr, yMiddle, xMiddle-11, "Press any key to continue"); + refresh(); } \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/settings.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/settings.c @@ -1,60 +1,17 @@ #include "settings.h" -void main_win() -{ - initscr(); - noecho(); - cbreak(); - - WINDOW *mainWin = newwin(0, 0, 0, 0); - box(mainWin, 0, 0); - refresh(); - wrefresh(mainWin); - keypad(mainWin, true); -} - - -void set_mode(WINDOW *menuWin) // loop -{ - char mode; - mvwprintw(menuWin, 1, 1, "Keyboard or text mode (k/t): "); - wrefresh(menuWin); - scanw("%c", &mode); - mvwprintw(menuWin, 1, strlen("Keyboard or text mode (k/t): ") + 1, "%c", mode); - wrefresh(menuWin); - mvwprintw(menuWin, 1, 1, CLEAR); // thanks stefastra && spyrosROUM!!!! :-DDDD - wrefresh(menuWin); - - switch (mode) - { - case 'k': - case 'K': - mvwprintw(menuWin, 2, 1, "Keyboard mode"); - wrefresh(menuWin); - break; - case 't': - case 'T': - mvwprintw(menuWin, 2, 1, "Text mode"); - wrefresh(menuWin); - break; - default: - break; - } -} - - int set_cols(WINDOW *menuWin, int xMax) { int COLS; do { - mvwprintw(menuWin, 1, 1, "Columns (Max = %d): ", xMax-12); + mvwprintw(menuWin, 1, 1, "Columns (Max = %d): ", (xMax-2)/3 - 2); wrefresh(menuWin); scanw("%d", &COLS); mvwprintw(menuWin, 1, strlen("Columns (Max = XXX): ") + 1, "%d", COLS); wrefresh(menuWin); - } while (COLS < 5 || COLS > xMax - 12); + } while (COLS < 5 || COLS > (xMax-2)/3 - 2); return COLS; } @@ -66,12 +23,12 @@ int set_rows(WINDOW *menuWin, int yMax) do { - mvwprintw(menuWin, 2, 1, "Rows (Max = %d): ", yMax-12); + mvwprintw(menuWin, 2, 1, "Rows (Max = %d): ", yMax-14); wrefresh(menuWin); scanw("%d", &ROWS); mvwprintw(menuWin, 2, strlen("Rows (Max = YYY): ") + 1, "%d", ROWS); wrefresh(menuWin); - } while (ROWS < 5 || ROWS > yMax - 12); + } while (ROWS < 5 || ROWS > yMax - 14); return ROWS; } @@ -91,4 +48,10 @@ int set_nmines(WINDOW *menuWin, int DIMENSIONS) } while (NMINES < 1 || NMINES > DIMENSIONS-10); return NMINES; +} + + +void init_colors() +{ + } \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/wins.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/wins.c @@ -0,0 +1,43 @@ +#include "wins.h" + +void main_win() +{ + initscr(); + noecho(); + cbreak(); + + WINDOW *mainWin = newwin(0, 0, 0, 0); + box(mainWin, 0, 0); + refresh(); + wrefresh(mainWin); +} + + +WINDOW *menu_win(int *yMax, int *xMax) +{ + int numSettings = 3; + getmaxyx(stdscr, *yMax, *xMax); + WINDOW *menuWin = newwin(numSettings+2, *xMax-8, *yMax-7, 4); + box(menuWin, 0, 0); + wrefresh(menuWin); + return menuWin; +} + + +WINDOW *game_win(int COLS, int ROWS, int NMINES) +{ + int winRows = ROWS + 2; + int winCols = COLS*3 + 2; + WINDOW *gameWin = newwin(winRows, winCols, 2, 4); + box(gameWin, 0, 0); + wrefresh(gameWin); + return gameWin; +} + + +void options_menu() +{ + int yMax = getmaxy(stdscr); + mvprintw(yMax-2, 1, "q Quit m Manual"); // bold letters + refresh(); +}+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/Makefile b/assignment-1.5-arrays-pointers-files/mns/Makefile @@ -1,36 +0,0 @@ -TARGET = minesweeper - -SRC_DIR = src -OBJ_DIR = obj -BIN_DIR = bin - -SRC = $(wildcard $(SRC_DIR)/*.c) -OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) - -MOVE = mv -MKDIR_P = mkdir -p - -CC = gcc -CPPFLAGS += -Iinclude -CFLAGS += -Wall -LDFLAGS += -Llib -LDLIBS += -lm -lncurses - -.PHONY: all clean - -all: $(TARGET) - -$(TARGET): $(OBJ) - $(MKDIR_P) $(BIN_DIR) - $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ - $(MOVE) $(TARGET) $(BIN_DIR) - -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c - $(MKDIR_P) $(OBJ_DIR) - $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ - -run: - ./$(BIN_DIR)/$(TARGET) - -clean: - $(RM) $(OBJ) $(BIN_DIR)/$(TARGET)- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/bin/minesweeper b/assignment-1.5-arrays-pointers-files/mns/bin/minesweeper Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/include/gameplay.h b/assignment-1.5-arrays-pointers-files/mns/include/gameplay.h @@ -1,13 +0,0 @@ -#ifndef GAMEPLAY_H -#define GAMEPLAY_H - -#include "minesweeper.h" - -#define DEFUSEKEY 'd' - -void selection(struct _win_st*, char **, char **, int, int, int); -bool transfer(char **, char **, int, int, int, int *); -void reveal(struct _win_st*, char **, int, int); -bool defused(char **, char **, int, int, int, int *); - -#endif- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/include/minesweeper.h b/assignment-1.5-arrays-pointers-files/mns/include/minesweeper.h @@ -1,36 +0,0 @@ -#ifndef MINESWEEPER_H -#define MINESWEEPER_H - -#if defined linux || defined __unix__ -#include <ncurses.h> -#elif defined _WIN32 || defined _WIN64 -#include <pdcurses.h> -#include <stdint.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include "settings.h" -#include "gameplay.h" -#include "navigation.h" -#include "outputs.h" -#include "wins.h" - -#define HIDDEN '#' -#define MINE '*' -#define CLEAR " " - -char **init_dispboard(struct _win_st*, int, int); -void fill_dispboard(char **, int, int); -char **init_mineboard(struct _win_st*, int, int, int); - -void place_mines(char **, int, int, int); -void add_adj(char **, int, int); -bool is_mine(char **, int, int); -bool outof_bounds(int, int, int, int); -int8_t adj_mines(char **, int, int, int, int); -void fill_spaces(char **, int, int, int); - -#endif diff --git a/assignment-1.5-arrays-pointers-files/mns/include/navigation.h b/assignment-1.5-arrays-pointers-files/mns/include/navigation.h @@ -1,8 +0,0 @@ -#ifndef NAVIGATION_H -#define NAVIGATION_H - -#include "minesweeper.h" - -void navigate(struct _win_st*, int, int); - -#endif- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/include/outputs.h b/assignment-1.5-arrays-pointers-files/mns/include/outputs.h @@ -1,13 +0,0 @@ -#ifndef OUTPUTS_H -#define OUTPUTS_H - -#include "minesweeper.h" - -void print_grid(struct _win_st*, int, int); -void game_won(struct _win_st*, char **, int, int); -void game_over(struct _win_st*, char **, int, int); - -void print_board(struct _win_st*, char **, int, int); -void filewrite(char **, int, int, int, int, const char *); - -#endif- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/include/settings.h b/assignment-1.5-arrays-pointers-files/mns/include/settings.h @@ -1,10 +0,0 @@ -#ifndef SETTINGS_H -#define SETTINGS_H - -#include "minesweeper.h" - -int set_cols(struct _win_st*, int); -int set_rows(struct _win_st*, int); -int set_nmines(struct _win_st*, int); - -#endif- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/include/wins.h b/assignment-1.5-arrays-pointers-files/mns/include/wins.h @@ -1,10 +0,0 @@ -#ifndef WINS_H -#define WINS_H - -#include "minesweeper.h" - -void main_win(); -void start(); -void game_win(int, int, int); - -#endif diff --git a/assignment-1.5-arrays-pointers-files/mns/mnsout.txt b/assignment-1.5-arrays-pointers-files/mns/mnsout.txt @@ -1,14 +0,0 @@ -Mine hit at position (3, 2) - -Board overview - -- - - - 1 * 1 - 1 * -- - 1 1 3 2 2 - 1 1 -- - 1 * 2 * 1 - - - -- - 1 1 2 1 1 - - - -- - 1 1 1 - - - - - -- - 1 * 1 - - - 1 1 -- - 1 1 1 - 1 1 2 * -- 1 1 2 1 1 1 * 2 1 -- 1 * 2 * 2 2 2 1 - -- 1 1 2 1 2 * 1 - - diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/gameplay.o b/assignment-1.5-arrays-pointers-files/mns/obj/gameplay.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/main.o b/assignment-1.5-arrays-pointers-files/mns/obj/main.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/minesweeper.o b/assignment-1.5-arrays-pointers-files/mns/obj/minesweeper.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/navigation.o b/assignment-1.5-arrays-pointers-files/mns/obj/navigation.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/outputs.o b/assignment-1.5-arrays-pointers-files/mns/obj/outputs.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/settings.o b/assignment-1.5-arrays-pointers-files/mns/obj/settings.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/obj/wins.o b/assignment-1.5-arrays-pointers-files/mns/obj/wins.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/mns/src/gameplay.c b/assignment-1.5-arrays-pointers-files/mns/src/gameplay.c @@ -1,70 +0,0 @@ -#include "gameplay.h" - -void selection(WINDOW *gameWin, char **dispboard, char **mineboard, int COLS, int ROWS, int NMINES) -{ - int chRow, chCol; - bool gameOver; - int numDefused = 0; - int yMax, xMax, yMiddle, xMiddle; - getmaxyx(stdscr, yMax, xMax); - yMiddle = yMax / 2; - xMiddle = xMax / 2; - - do - { - mvprintw(1, 1, "Choice (col, row): "); - scanw("%d %d", &chCol, &chRow); - mvprintw(1, strlen("Choice (col, row): ") + 1, "(%d,%d)", chCol, chRow); - refresh(); - mvprintw(1, 1, CLEAR); - gameOver = transfer(dispboard, mineboard, chCol, chRow, NMINES, &numDefused); - mvprintw(1, xMiddle-9, "Defused mines: %d/%d", numDefused, NMINES); - reveal(gameWin, dispboard, chCol, chRow); - getchar(); - } while (((chCol >= 0 && chCol < COLS) && (chRow >= 0 && chRow < ROWS)) && numDefused < NMINES && !gameOver); - - if (gameOver == true) - { - game_over(gameWin, mineboard, yMiddle, xMiddle); - getchar(); - print_board(gameWin, mineboard, COLS, ROWS); - filewrite(mineboard, COLS, ROWS, chCol, chRow, "lost"); - } - - if (numDefused == NMINES) - { - game_won(gameWin, mineboard, yMiddle, xMiddle); - getchar(); - filewrite(mineboard, COLS, ROWS, chCol, chRow, "won"); - } -} - - -bool transfer(char **dispboard, char **mineboard, int chCol, int chRow, int NMINES, int *numDefused) -{ - dispboard[chCol][chRow] = mineboard[chCol][chRow]; - return (!defused(dispboard, mineboard, chCol, chRow, NMINES, numDefused)) ? true : false; -} - -bool defused(char **dispboard, char **mineboard, int chCol, int chRow, int NMINES, int *numDefused) -{ - char c = getchar(); - - if (dispboard[chCol][chRow] == MINE) - { - if (c == DEFUSEKEY) - { - dispboard[chCol][chRow] = mineboard[chCol][chRow] = 'D'; - (*numDefused)++; - return true; - } - else return false; - } -} - - -void reveal(WINDOW *gameWin, char **dispboard, int chCol, int chRow) -{ - mvwaddch(gameWin, chRow+1, chCol+1, dispboard[chCol][chRow]); - wrefresh(gameWin); -} diff --git a/assignment-1.5-arrays-pointers-files/mns/src/main.c b/assignment-1.5-arrays-pointers-files/mns/src/main.c @@ -1,10 +0,0 @@ -#include "minesweeper.h" - -int main(int argc, char **argv) -{ - main_win(); - start(); - endwin(); - - return 0; -} diff --git a/assignment-1.5-arrays-pointers-files/mns/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/mns/src/minesweeper.c @@ -1,121 +0,0 @@ -#include "minesweeper.h" - -char **init_dispboard(WINDOW *gameWin, int COLS, int ROWS) -{ - int i; - char **dispboard = (char **)malloc(COLS * sizeof(char *)); - for (i = 0; i < COLS; i++) - dispboard[i] = (char *)malloc(ROWS); - - if (dispboard == NULL) - { - mvprintw(1, 1, "Error, not enough memory, exiting..."); - exit(EXIT_FAILURE); - } - else fill_dispboard(dispboard, COLS, ROWS); - - return dispboard; -} - - -void fill_dispboard(char **dispboard, int COLS, int ROWS) -{ - int i, j; - - for (i = 0; i < COLS; i++) - for (j = 0; j < ROWS; j++) - dispboard[i][j] = HIDDEN; -} - - -char **init_mineboard(WINDOW *gameWin, int COLS, int ROWS, int NMINES) -{ - int i; - char **mineboard = (char **)malloc(COLS * sizeof(char *)); - for (i = 0; i < COLS; i++) - mineboard[i] = (char *)malloc(ROWS); - - if (mineboard == NULL) - { - mvprintw(1, 1, "Error, not enough memory, exiting..."); - exit(EXIT_FAILURE); - } - else - { - place_mines(mineboard, COLS, ROWS, NMINES); - add_adj(mineboard, COLS, ROWS); - fill_spaces(mineboard, COLS, ROWS, NMINES); - - // tests - //print_board(gameWin, mineboard, COLS, ROWS); - //filewrite(mineboard, COLS, ROWS, 1, 2); - } - - return mineboard; -} - - -void place_mines(char **mineboard, int COLS, int ROWS, int NMINES) -{ - int i, wRand, hRand; - - srand(time(NULL)); - - for (i = 0; i < NMINES; i++) - { - wRand = rand() % COLS; - hRand = rand() % ROWS; - mineboard[wRand][hRand] = MINE; - } -} - - -void add_adj(char **mineboard, int COLS, int ROWS) -{ - int i, j; - - for (i = 0; i < COLS; i++) - for (j = 0; j < ROWS; j++) - if (!is_mine(mineboard, i, j)) - mineboard[i][j] = adj_mines(mineboard, i, j, COLS, ROWS) + '0'; -} - - -bool is_mine(char **mineboard, int row, int col) -{ - return (mineboard[row][col] == MINE) ? true : false; -} - -bool outof_bounds(int row, int col, int COLS, int ROWS) -{ - return (row < 0 || row > COLS-1 || col < 0 || col > ROWS-1) ? true : false; -} - - - -int8_t adj_mines(char **mineboard, int row, int col, int COLS, int ROWS) -{ - int8_t numAdj = 0; - - if (!outof_bounds(row, col - 1, COLS, ROWS) && mineboard[row][col-1] == MINE) numAdj++; // North - if (!outof_bounds(row, col + 1, COLS, ROWS) && mineboard[row][col+1] == MINE) numAdj++; // South - if (!outof_bounds(row + 1, col, COLS, ROWS) && mineboard[row+1][col] == MINE) numAdj++; // East - if (!outof_bounds(row - 1, col, COLS, ROWS) && mineboard[row-1][col] == MINE) numAdj++; // West - if (!outof_bounds(row + 1, col - 1, COLS, ROWS) && mineboard[row+1][col-1] == MINE) numAdj++; // North-East - if (!outof_bounds(row - 1, col - 1, COLS, ROWS) && mineboard[row-1][col-1] == MINE) numAdj++; // North-West - if (!outof_bounds(row + 1, col + 1, COLS, ROWS) && mineboard[row+1][col+1] == MINE) numAdj++; // South-East - if (!outof_bounds(row - 1, col + 1, COLS, ROWS) && mineboard[row-1][col+1] == MINE) numAdj++; // South-West - - return numAdj; -} - - -void fill_spaces(char **mineboard, int COLS, int ROWS, int NMINES) -{ - int i, j; - - for (i = 0; i < COLS; i++) - for (j = 0; j < ROWS; j++) - if (mineboard[i][j] != MINE && mineboard[i][j] == '0') - mineboard[i][j] = '-'; -} diff --git a/assignment-1.5-arrays-pointers-files/mns/src/navigation.c b/assignment-1.5-arrays-pointers-files/mns/src/navigation.c @@ -1,46 +0,0 @@ -#include "navigation.h" - -void navigate(WINDOW *gameWin, int COLS, int ROWS) -{ - keypad(gameWin, true); - int move, i, j; - int highlight = 0; - - - for (i = 0; i < ROWS*COLS; i++) - { - if (i == highlight) - wattron(gameWin, A_REVERSE); - wattroff(gameWin, A_REVERSE); - } - - switch (move) - { - case 'k': - case 'K': - case KEY_UP: - highlight--; - if (highlight == -1) highlight = 0; - break; - case 'j': - case 'J': - case KEY_DOWN: - highlight++; - if (highlight == COLS) highlight = COLS-1; - break; - case 'h': - case 'H': - case KEY_LEFT: - highlight--; - if (highlight == -1) highlight = 0; - break; - case 'l': - case 'L': - case KEY_RIGHT: - highlight++; - if (highlight == ROWS) highlight = ROWS-1; - break; - - //if (move == 10) reveal(gameWin, dispboard, chCol, chRow); - } -}- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/src/outputs.c b/assignment-1.5-arrays-pointers-files/mns/src/outputs.c @@ -1,80 +0,0 @@ -#include "outputs.h" - -void print_grid(WINDOW *gameWin, int ROWS, int COLS) -{ - int i, j; - for (j = 1; j <= ROWS; j++) - { - wmove(gameWin, j, 1); - for (i = 0; i < COLS; i++) - wprintw(gameWin, "[ ]"); - } - wrefresh(gameWin); -} - - -void game_won(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) -{ - wclear(gameWin); - mvwprintw(gameWin, yMiddle-11, xMiddle-18, "You defused all the mines!"); - mvwprintw(gameWin, yMiddle-10, xMiddle-10, "You won :)"); - wrefresh(gameWin); - wclear(gameWin); -} - - -void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) -{ - wclear(gameWin); - mvwprintw(gameWin, yMiddle-11, xMiddle-11, "You hit a mine!"); - mvwprintw(gameWin, yMiddle-10, xMiddle-10, "Game over :("); - wrefresh(gameWin); - wclear(gameWin); -} - - -void print_board(WINDOW *gameWin, char **board, int COLS, int ROWS) -{ - int i, j, x, y; - - for (i = 0; i < ROWS; i++) - { - for (j = 0; j < COLS; j++) - { - mvwaddch(gameWin, j+1, i+1, board[i][j]); - wrefresh(gameWin); - } - } -} - - -void filewrite(char **mineboard, int COLS, int ROWS, int hitCol, int hitRow, const char *status) -{ - int i, j; - FILE *mnsOut = fopen("mnsout.txt", "w"); - - if (mnsOut == NULL) - { - mvprintw(1, 1, "Error opening file, exiting..."); - exit(EXIT_FAILURE); - } - else - { - strcmp(status, "won") - ? fprintf(mnsOut, "Mine hit at position (%d, %d)\n\n", hitCol, hitRow) - : fprintf(mnsOut, "Last mine defused at position (%d, %d)\n\n", hitCol, hitRow); - fprintf(mnsOut, "Board overview\n\n"); - - for (i = 0; i < ROWS; i++) - { - for (j = 0; j < COLS; j++) - fprintf(mnsOut, "%c ", mineboard[j][i]); - fprintf(mnsOut, "\n"); - } - - mvprintw(1, 1, "Session written to file"); - refresh(); - } - - fclose(mnsOut); -}- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/src/settings.c b/assignment-1.5-arrays-pointers-files/mns/src/settings.c @@ -1,51 +0,0 @@ -#include "settings.h" - -int set_cols(WINDOW *menuWin, int xMax) -{ - int COLS; - - do - { - mvwprintw(menuWin, 1, 1, "Columns (Max = %d): ", xMax-12); - wrefresh(menuWin); - scanw("%d", &COLS); - mvwprintw(menuWin, 1, strlen("Columns (Max = XXX): ") + 1, "%d", COLS); - wrefresh(menuWin); - } while (COLS < 5 || COLS > xMax - 12); - - return COLS; -} - - -int set_rows(WINDOW *menuWin, int yMax) -{ - int ROWS; - - do - { - mvwprintw(menuWin, 2, 1, "Rows (Max = %d): ", yMax-12); - wrefresh(menuWin); - scanw("%d", &ROWS); - mvwprintw(menuWin, 2, strlen("Rows (Max = YYY): ") + 1, "%d", ROWS); - wrefresh(menuWin); - } while (ROWS < 5 || ROWS > yMax - 12); - - return ROWS; -} - - -int set_nmines(WINDOW *menuWin, int DIMENSIONS) -{ - int NMINES; - - do - { - mvwprintw(menuWin, 3, 1, "Mines (Max = %d): ", DIMENSIONS-10); // -10 so the player has a chance to win - wrefresh(menuWin); - scanw("%d", &NMINES); - mvwprintw(menuWin, 3, strlen("Mines (Max = MMMM): ") + 1, "%d", NMINES); - wrefresh(menuWin); - } while (NMINES < 1 || NMINES > DIMENSIONS-10); - - return NMINES; -}- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/mns/src/wins.c b/assignment-1.5-arrays-pointers-files/mns/src/wins.c @@ -1,58 +0,0 @@ -#include "wins.h" - -void main_win() -{ - initscr(); - noecho(); - cbreak(); - - WINDOW *mainWin = newwin(0, 0, 0, 0); - box(mainWin, 0, 0); - refresh(); - wrefresh(mainWin); - keypad(mainWin, true); -} - - -void start() -{ - int yMax, xMax; - int numSettings = 3; - getmaxyx(stdscr, yMax, xMax); - - WINDOW *menuWin = newwin(numSettings+2, xMax-10, yMax-7, 5); - box(menuWin, 0, 0); - refresh(); - wrefresh(menuWin); - keypad(menuWin, true); - - int COLS = set_cols(menuWin, xMax); - int ROWS = set_rows(menuWin, yMax); - int NMINES = set_nmines(menuWin, COLS * ROWS); - - delwin(menuWin); - game_win(COLS, ROWS, NMINES); - getchar(); -} - - -void game_win(int COLS, int ROWS, int NMINES) -{ - int yMax, xMax; - getmaxyx(stdscr, yMax, xMax); - - WINDOW *gameWin = newwin(COLS, ROWS, 2, 3); - - box(gameWin, 0, 0); - //mvwin(gameWin, (yMax/2) - 12, xMax/2); - wrefresh(gameWin); - refresh(); - - char **dispboard = init_dispboard(gameWin, COLS, ROWS); - char **mineboard = init_mineboard(gameWin, COLS, ROWS, NMINES); - print_grid(gameWin, ROWS, COLS); - selection(gameWin, dispboard, mineboard, COLS, ROWS, NMINES); - - free(dispboard); - free(mineboard); -} diff --git a/assignment-1.5-arrays-pointers-files/mns/todo.md b/assignment-1.5-arrays-pointers-files/mns/todo.md @@ -1,21 +0,0 @@ -* limits -* resizing -* ```selection()``` -* ```transfer()``` -* ```reveal()``` -* ```is_mine()``` -* ```game_over()``` -* Game over menu - * Press key to continue - * Dialog menu - -* Export to text - - * Get file name - * Write to file - -```c -pin = (char **)malloc(M*sizeof(char *)); -for (int i = 0; i < M; i++) - *(pin + i) = (char *)malloc(N); -```- \ No newline at end of file