commit ec304a1cd62337ba25cb14f2e7aaac100a2434f6 parent 6c80a7fb76603993479864a3ed1600015661490d Author: Christos Margiolis <christos@margiolis.net> Date: Thu, 23 Apr 2020 19:08:46 +0300 updated submodule Diffstat:
23 files changed, 93 insertions(+), 91 deletions(-)
diff --git a/assignment-1.5-arrays-pointers-files/minecurses/README.md b/assignment-1.5-arrays-pointers-files/minecurses/README.md @@ -26,14 +26,15 @@ Additional controls ## To Do -* Handle resizing +* ~~Handle resizing~~ * Add restart option * Add quit option right when game opens * Load score log to ui -* Improve score log -* Add macros for the scaled board dimensions +* ~~Improve score log~~ * Add colors -* Add unicode support +* Add UTF-8 support +* Fix wrong mine spawning bug +* (Perhaps) pack board info into a `struct` ## Execution diff --git a/assignment-1.5-arrays-pointers-files/minecurses/bin/minecurses b/assignment-1.5-arrays-pointers-files/minecurses/bin/minecurses Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/log/scorelog.csv b/assignment-1.5-arrays-pointers-files/minecurses/log/scorelog.csv @@ -0,0 +1,19 @@ +PLAYER,MINES DEFUSED,BOARD +christos,1.00,5x5 +christos,1.00,5x5 +aa,1.00,5x5 +chris,1.00,5x5 +hristos,1.00,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 +christos,1,5x5 diff --git a/assignment-1.5-arrays-pointers-files/minecurses/log/session.txt b/assignment-1.5-arrays-pointers-files/minecurses/log/session.txt @@ -0,0 +1,9 @@ +Last mine defused at position (4, 1) + +Board overview + +- - 1 D 1 +- - 1 1 1 +- - - - - +- - - - - +- - - - - diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/audio.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/audio.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/gameplay.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/gameplay.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/main.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/main.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/minesweeper.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/minesweeper.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/navigation.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/navigation.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/outputs.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/outputs.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/settings.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/settings.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/wins.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/wins.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c b/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c @@ -5,16 +5,19 @@ void play_minesweeper(WINDOW *gamew, char **dboard, char **mboard, int COLS, int int mbx = 0, mby = 0; int gameover = FALSE; int ndefused = 0; - int ymax, xmax, ymid, xmid; + int ymid, xmid; char move; - getmaxyx(stdscr, ymax, xmax); - ymid = ymax/2; - xmid = xmax/2; - print_board(gamew, dboard, COLS, ROWS); + ymid = YMAX/2; + xmid = XMAX/2; do { - session_info(mbx, mby, xmax, xmid, ndefused, NMINES); + erase(); + delwin(gamew); + refresh(); + gamew = game_win(COLS, ROWS, NMINES); + print_board(gamew, dboard, COLS, ROWS); + session_info(mbx, mby, xmid, ndefused, NMINES); navigate(gamew, dboard, &move, &mbx, &mby); switch (move) { diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/main.c b/assignment-1.5-arrays-pointers-files/minecurses/src/main.c @@ -3,13 +3,11 @@ int main(int argc, char **argv) { - int ymax, xmax; init_curses(); - getmaxyx(stdscr, ymax, xmax); echo(); - int COLS = set_cols(ymax, xmax); - int ROWS = set_rows(ymax); - int NMINES = set_nmines(ymax, COLS*ROWS); + int COLS = set_cols(); + int ROWS = set_rows(); + int NMINES = set_nmines(COLS*ROWS); noecho(); options_menu(); erase(); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.h b/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.h @@ -33,6 +33,9 @@ #define VOLUME_DOWN '-' #define QUIT 'q' +#define YMAX getmaxy(stdscr) +#define XMAX getmaxx(stdscr) + char **init_dboard (struct _win_st* gamew, int COLS, int ROWS); void fill_dboard (char **dboard, int COLS, int ROWS); char **init_mboard (struct _win_st* gamew, int COLS, int ROWS, int NMINES); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/navigation.c b/assignment-1.5-arrays-pointers-files/minecurses/src/navigation.c @@ -2,9 +2,9 @@ void navigate(WINDOW *gamew, char **mboard, char *move, int *mbx, int *mby) { - int ymax, xmax; + int ymax, xmax; + getmaxyx(gamew, ymax, xmax); static int y = 1, x = 2; - getmaxyx(gamew, ymax, xmax); update_curs(gamew, y, x); *mbx = (x-2)/3; *mby = y-1; diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.c b/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.c @@ -30,19 +30,18 @@ void print_grid(WINDOW *gamew, int ROWS, int COLS) wrefresh(gamew); } -void session_info(int mbx, int mby, int xmax, int xmid, int ndefused, int NMINES) +void session_info(int mbx, int mby, int xmid, int ndefused, int NMINES) { mvprintw(0, 0, "Current position: (%d, %d) ", mbx, mby); mvprintw(0, xmid-strlen("Defused mines: x/x")/2, "Defused mines: %d/%d", ndefused, NMINES); - mvprintw(0, xmax-strlen("m Controls"), "m Controls"); + mvprintw(0, XMAX-strlen("m Controls"), "m Controls"); } void session_write(char **mboard, int COLS, int ROWS, int hitrow, int hitcol, const char *status) { int i, j; - FILE *mnsout = fopen(SESSION_PATH, "w"); - - if (mnsout == NULL) + FILE *fsession = fopen(SESSION_PATH, "w"); + if (fsession == NULL) { mvprintw(0, 0, "Error opening file, exiting..."); refresh(); @@ -51,32 +50,23 @@ void session_write(char **mboard, int COLS, int ROWS, int hitrow, int hitcol, co else { strcmp(status, "won") - ? 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"); - + ? fprintf(fsession, "Mine hit at position (%d, %d)\n\n", hitrow+1, hitcol+1) + : fprintf(fsession, "Last mine defused at position (%d, %d)\n\n", hitrow+1, hitcol+1); + fprintf(fsession, "Board overview\n\n"); for (i = 0; i < ROWS; i++) { for (j = 0; j < COLS; j++) - fprintf(mnsout, "%c ", mboard[i][j]); - fprintf(mnsout, "\n"); + fprintf(fsession, "%c ", mboard[i][j]); + fprintf(fsession, "\n"); } - - mvprintw(0, 0, "Session written to file "); - refresh(); - getchar(); } - - fclose(mnsout); + fclose(fsession); } void score_write(int ndefused, int COLS, int ROWS) { FILE *scorelog = fopen(SCORE_LOG_PATH, "a"); char *playername = get_pname(); - - // add titles etc - if (scorelog == NULL) { mvprintw(0, 0, "Error opening file, exiting..."); @@ -85,13 +75,14 @@ void score_write(int ndefused, int COLS, int ROWS) } else { - fprintf(scorelog, "\n%s\t\t\t\t%d\t\t\t\t\t%dx%d", playername, ndefused, COLS, ROWS); + fprintf(scorelog, "%s,%d,%dx%d\n", playername, ndefused, COLS, ROWS); sort_scorelog(scorelog); // pending + clrtoeol(); + show_scorelog(scorelog); mvprintw(0, 0, "New score written to score log"); refresh(); getchar(); } - fclose(scorelog); free(playername); } @@ -100,7 +91,6 @@ char *get_pname(void) { char buffer[20]; char *playername; - move(0, 0); echo(); clrtoeol(); @@ -109,7 +99,6 @@ char *get_pname(void) scanw("%s", buffer); noecho(); refresh(); - playername = (char *)malloc(strlen(buffer) + 1); return (strcpy(playername, buffer)); } @@ -119,6 +108,16 @@ void sort_scorelog(FILE *scorelog) } +void show_scorelog(FILE *scorelog) +{ + +} + +void parse_data(FILE *scorelog) +{ + +} + void game_won(WINDOW *gamew, int ymid, int xmid) { wclear(gamew); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.h b/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.h @@ -3,16 +3,18 @@ #include "minesweeper.h" -#define SESSION_PATH "txt/mnsout.txt" -#define SCORE_LOG_PATH "txt/scorelog.txt" +#define SESSION_PATH "log/session.txt" +#define SCORE_LOG_PATH "log/scorelog.csv" void print_board (struct _win_st* gamew, char **dboard, int COLS, int ROWS); void print_grid (struct _win_st* gamew, int ROWS, int COLS); -void session_info (int mbx, int mby, int xmax, int xmid, int ndefused, int NMINES); +void session_info (int mbx, int mby, int xmid, int ndefused, int NMINES); void session_write (char **mboard, int COLS, int ROWS, int hitrow, int hitcol, const char *status); void score_write (int ndefused, int COLS, int ROWS); char *get_pname (void); void sort_scorelog (FILE *scorelog); +void show_scorelog (FILE *scorelog); +void parse_data (FILE *scorelog); void game_won (struct _win_st* gamew, int ymid, int xmid); void game_over (struct _win_st* gamew, char **mboard, int ymid, int xmid); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/settings.c b/assignment-1.5-arrays-pointers-files/minecurses/src/settings.c @@ -1,37 +1,37 @@ #include "settings.h" -int set_cols(int ymax, int xmax) +int set_cols() { int COLS; do { - mvprintw(ymax-4, 1, "Columns (Min = 5, Max = %d): ", (xmax-2)/3-2); + mvprintw(YMAX-4, 1, "Columns (Min = 5, Max = %d): ", (XMAX-2)/3-2); refresh(); scanw("%d", &COLS); refresh(); - } while (COLS < 5 || COLS > (xmax-2)/3-2); + } while (COLS < 5 || COLS > (XMAX-2)/3-2); return COLS; } -int set_rows(int ymax) +int set_rows() { int ROWS; do { - mvprintw(ymax-3, 1, "Rows (Min = 5, Max = %d): ", ymax-4); + mvprintw(YMAX-3, 1, "Rows (Min = 5, Max = %d): ", YMAX-4); refresh(); scanw("%d", &ROWS); refresh(); - } while (ROWS < 5 || ROWS > ymax-4); + } while (ROWS < 5 || ROWS > YMAX-4); return ROWS; } -int set_nmines(int ymax, int DIMENSIONS) +int set_nmines(int DIMENSIONS) { int NMINES; do { - mvprintw(ymax-2, 1, "Mines (Max = %d): ", DIMENSIONS-15); // -10 so the player has a chance to win + mvprintw(YMAX-2, 1, "Mines (Max = %d): ", DIMENSIONS-15); // -10 so the player has a chance to win refresh(); scanw("%d", &NMINES); refresh(); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/settings.h b/assignment-1.5-arrays-pointers-files/minecurses/src/settings.h @@ -3,8 +3,8 @@ #include "minesweeper.h" -int set_cols (int ymax, int xmax); -int set_rows (int ymax); -int set_nmines (int ymax, int DIMENSIONS); +int set_cols (); +int set_rows (); +int set_nmines (int DIMENSIONS); #endif /* SETTINGS_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/wins.c b/assignment-1.5-arrays-pointers-files/minecurses/src/wins.c @@ -9,12 +9,10 @@ void init_curses(void) WINDOW *game_win(int COLS, int ROWS, int NMINES) { - int ymax, xmax; - getmaxyx(stdscr, ymax, xmax); int wrows = ROWS+2; int wcols = COLS*3+2; - int wy = ymax/2 - wrows/2; - int wx = xmax/2 - wcols/2; + int wy = YMAX/2 - wrows/2; + int wx = XMAX/2 - wcols/2; WINDOW *gamew = newwin(wrows, wcols, wy, wx); wattron(gamew, A_BOLD); box(gamew, 0, 0); @@ -25,11 +23,9 @@ WINDOW *game_win(int COLS, int ROWS, int NMINES) void options_menu(void) { - int ymax, xmax; - getmaxyx(stdscr, ymax, xmax); int w = 33, h = 15; - int wy = ymax/2 - h/2; - int wx = xmax/2 - w/2; + int wy = YMAX/2 - h/2; + int wx = XMAX/2 - w/2; WINDOW *opts = newwin(h, w, wy, wx); werase(opts); box(opts, 0, 0); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/txt/mnsout.txt b/assignment-1.5-arrays-pointers-files/minecurses/txt/mnsout.txt @@ -1,19 +0,0 @@ -Mine hit at position (6, 4) - -Board overview - -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 * 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/minecurses/txt/scorelog.txt b/assignment-1.5-arrays-pointers-files/minecurses/txt/scorelog.txt @@ -1,9 +0,0 @@ ----------- -Score log ----------- - ------------------------------------------------------- -Player Mines Defused Dimensions ------------------------------------------------------- -christos 1 5x5 -christos 1 5x5