commit 53e0de4be30f1fbe6ed44e26bd99f61b14105df9 parent e39f4824efd9cf11deaaaf82b5da27f400c01f14 Author: Christos Margiolis <christos@margiolis.net> Date: Sat, 4 Apr 2020 03:16:12 +0300 updated submodule Diffstat:
25 files changed, 202 insertions(+), 207 deletions(-)
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/include/audio.h b/assignment-1.5-arrays-pointers-files/minecurses/include/audio.h @@ -7,8 +7,8 @@ #define AUDIO_PATH "audio/detective-8bit.wav" -void *play_audio(void *); -void volume(char); -void pause_audio(); +void *play_audio(void *threadid); +void volume (char); +void pause_audio(void); -#endif- \ No newline at end of file +#endif /* AUDIO_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/include/gameplay.h b/assignment-1.5-arrays-pointers-files/minecurses/include/gameplay.h @@ -3,14 +3,14 @@ #include "minesweeper.h" -void play_minesweeper(struct _win_st*, char **, char **, int, int, int); -bool open_cell(struct _win_st*, char **, char **, int, int, bool); -void handle_flags(struct _win_st*, char **, char **, int, int); -void defuse_mine(struct _win_st*, char **, char **, int, int); -void transfer(char **, char **, int, int); -void reveal(struct _win_st*, char **, int, int, int, int); -bool is_defused(char **, char **, int, int); -void handle_gameover(struct _win_st*, char **, int, int, int, int, int, int); -void handle_win(struct _win_st*, char **, int, int, int, int, int, int, int); +void play_minesweeper (struct _win_st* gamew, char **dboard, char **mboard, int COLS, int ROWS, int NMINES); +bool open_cell (struct _win_st* gamew, char **dboard, char **mboard, int mby, int mbx, bool gameover); +void handle_flags (struct _win_st* gamew, char **dboard, char **mboard, int mby, int mbx); +void defuse_mine (struct _win_st* gamew, char **dboard, char **mboard, int mby, int mbx); +void transfer (char **dboard, char **mboard, int mby, int mbx); +void reveal (struct _win_st* gamew, char **dboard, int mby, int mbx, int y, int x); +bool is_defused (char **dboard, char **mboard, int mby, int mbx); +void handle_gameover (struct _win_st* gamew, char **mboard, int ymid, int xmid, int COLS, int ROWS, int mby, int mbx); +void handle_win (struct _win_st* gamew, char **mboard, int ymid, int xmid, int COLS, int ROWS, int mby, int mbx, int ndefused); -#endif +#endif /* GAMEPLAY_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/include/minesweeper.h b/assignment-1.5-arrays-pointers-files/minecurses/include/minesweeper.h @@ -33,15 +33,14 @@ #define VOLUME_DOWN '-' #define QUIT 'q' -char **init_dispboard(struct _win_st*, int, int); -void fill_dispboard(char **, int, int); -char **init_mineboard(struct _win_st*, int, int, int); +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); +void place_mines (char **mboard, int COLS, int ROWS, int NMINES); +void add_adj (char **mboard, int COLS, int ROWS); +bool is_mine (char **mboard, int row, int col); +bool outof_bounds (int row, int col, int ROWS, int COLS); +int8_t adj_mines (char **mboard, int row, int col, int COLS, int ROWS); +void fill_spaces (char **mboard, int COLS, int ROWS, int NMINES); -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 +#endif /* MINESWEEPER_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/include/navigation.h b/assignment-1.5-arrays-pointers-files/minecurses/include/navigation.h @@ -3,12 +3,12 @@ #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 *); -void mvdown(int *, int); -void mvleft(int *); -void mvright(int *, int); -void update_curs(struct _win_st*, int, int); +void navigate (struct _win_st* gamew, char **mboard, char *move, int *mbx, int *mby); +void getmv (struct _win_st* gamew, char *move, int *y, int *x, int ymax, int xmax); +void mvup (int *y); +void mvdown (int *y, int ymax); +void mvleft (int *x); +void mvright (int *x, int xmax); +void update_curs(struct _win_st* gamew, int y, int x); -#endif- \ No newline at end of file +#endif /* NAVIGATION_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/include/outputs.h b/assignment-1.5-arrays-pointers-files/minecurses/include/outputs.h @@ -6,13 +6,13 @@ #define SESSION_PATH "txt/mnsout.txt" #define SCORE_LOG_PATH "txt/scorelog.txt" -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 session_write(char **, int, int, int, int, const char *); -void score_write(int, int, int); -char *get_pname(); -void sort_scorelog(FILE *); +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_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 game_won (struct _win_st* gamew, int ymid, int xmid); +void game_over (struct _win_st* gamew, char **mboard, int ymid, int xmid); -#endif +#endif /* OUTPUTS_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/include/settings.h b/assignment-1.5-arrays-pointers-files/minecurses/include/settings.h @@ -7,9 +7,8 @@ #define ROWS_CHAR_LENGTH strlen("Rows (Min = 5, Max = YYY): ") + 1 #define NMINES_CHAR_LENGTH strlen("Mines (Max = MMM): ") + 1 -int set_cols(struct _win_st*, int); -int set_rows(struct _win_st*, int); -int set_nmines(struct _win_st*, int); -void init_colors(); +int set_cols (struct _win_st* menuw, int xmax); +int set_rows (struct _win_st* menuw, int ymax); +int set_nmines (struct _win_st* menuw, int DIMENSIONS); -#endif- \ No newline at end of file +#endif /* SETTINGS_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/include/wins.h b/assignment-1.5-arrays-pointers-files/minecurses/include/wins.h @@ -3,10 +3,10 @@ #include "minesweeper.h" -void main_win(); -WINDOW *menu_win(int *, int *); -WINDOW *game_win(int, int, int); -void options_menu(); -void options_win(); +void main_win (void); +WINDOW *menu_win (int *ymax, int *xmax); +WINDOW *game_win (int COLS, int ROWS, int NMINES); +void options_menu (void); +void options_win (void); -#endif +#endif /* WINS_H */ 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/src/audio.c b/assignment-1.5-arrays-pointers-files/minecurses/src/audio.c @@ -1,8 +1,8 @@ #include "audio.h" -void *play_audio(void *threadID) +void *play_audio(void *threadid) { - int tID = (long)threadID; + int tid = (long)threadid; Mix_Music *music = NULL; SDL_Init(SDL_INIT_AUDIO); Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 4096); @@ -31,7 +31,7 @@ void volume(char option) } } -void pause_audio() +void pause_audio(void) { if(Mix_PausedMusic() == 1) Mix_ResumeMusic(); else Mix_PauseMusic(); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c b/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c @@ -1,100 +1,100 @@ #include "gameplay.h" -void play_minesweeper(WINDOW *gameWin, char **dispboard, char **mineboard, int COLS, int ROWS, int NMINES) +void play_minesweeper(WINDOW *gamew, char **dboard, char **mboard, int COLS, int ROWS, int NMINES) { int mbx = 0, mby = 0; - bool gameOver = false; - int numDefused = 0; + bool gameover = false; + int ndefused = 0; int ymax, xmax, ymid, xmid; char move; getmaxyx(stdscr, ymax, xmax); ymid = ymax/2; xmid = xmax/2; - print_board(gameWin, dispboard, COLS, ROWS); + print_board(gamew, dboard, COLS, ROWS); do { - navigate(gameWin, dispboard, &move, &mbx, &mby); + navigate(gamew, dboard, &move, &mbx, &mby); if (move == ENTER || move == OPEN_LOWER || move == OPEN_UPPER) // handle cell opening - gameOver = open_cell(gameWin, dispboard, mineboard, mby, mbx, gameOver); + gameover = open_cell(gamew, dboard, mboard, mby, mbx, gameover); else if (move == FLAG_LOWER || move == FLAG_UPPER) // handle falgs - handle_flags(gameWin, dispboard, mineboard, mby, mbx); + handle_flags(gamew, dboard, mboard, mby, mbx); else if (move == DEFUSE_LOWER || move == DEFUSE_UPPER) // check for defuse { - if (dispboard[mby][mbx] == FLAG && mineboard[mby][mbx] == MINE) + if (dboard[mby][mbx] == FLAG && mboard[mby][mbx] == MINE) { - numDefused++; - defuse_mine(gameWin, dispboard, mineboard, mby, mbx); + ndefused++; + defuse_mine(gamew, dboard, mboard, mby, mbx); } - else if (dispboard[mby][mbx] == FLAG && mineboard[mby][mbx] != MINE) gameOver = true; + else if (dboard[mby][mbx] == FLAG && mboard[mby][mbx] != MINE) gameover = true; } else if (move == PAUSE_AUDIO) pause_audio(); // handle audio else if (move == VOLUME_UP || move == VOLUME_DOWN) volume(move); - mvprintw(1, xmid-8, "Defused mines: %d/%d", numDefused, NMINES); + mvprintw(1, xmid-8, "Defused mines: %d/%d", ndefused, NMINES); } while (((mby >= 0 && mby < ROWS) && (mbx >= 0 && mbx < COLS)) && - numDefused < NMINES && !gameOver && move != QUIT); + ndefused < NMINES && !gameover && move != QUIT); - if (gameOver == true) - handle_gameover(gameWin, mineboard, ymid, xmid, COLS, ROWS, mby, mbx); - if (numDefused == NMINES) - handle_win(gameWin, mineboard, ymid, xmid, COLS, ROWS, mby, mbx, numDefused); + if (gameover == true) + handle_gameover(gamew, mboard, ymid, xmid, COLS, ROWS, mby, mbx); + if (ndefused == NMINES) + handle_win(gamew, mboard, ymid, xmid, COLS, ROWS, mby, mbx, ndefused); } -bool open_cell(WINDOW *gameWin, char **dispboard, char **mineboard, int mby, int mbx, bool gameOver) +bool open_cell(WINDOW *gamew, char **dboard, char **mboard, int mby, int mbx, bool gameover) { - transfer(dispboard, mineboard, mby, mbx); - reveal(gameWin, dispboard, mby, mbx, mby+1, 3*mbx+2); - if (dispboard[mby][mbx] == MINE) gameOver = true; - return gameOver; + transfer(dboard, mboard, mby, mbx); + reveal(gamew, dboard, mby, mbx, mby+1, 3*mbx+2); + if (dboard[mby][mbx] == MINE) gameover = true; + return gameover; } -void handle_flags(WINDOW *gameWin, char **dispboard, char **mineboard, int mby, int mbx) +void handle_flags(WINDOW *gamew, char **dboard, char **mboard, int mby, int mbx) { - if (dispboard[mby][mbx] == FLAG) dispboard[mby][mbx] = BLANK; // undo flag - else if (dispboard[mby][mbx] != FLAG && dispboard[mby][mbx] != BLANK) return; // dont flag an already opened mine - else dispboard[mby][mbx] = FLAG; // flag if not flagged already - reveal(gameWin, dispboard, mby, mbx, mby+1, 3*mbx+2); + if (dboard[mby][mbx] == FLAG) dboard[mby][mbx] = BLANK; // undo flag + else if (dboard[mby][mbx] != FLAG && dboard[mby][mbx] != BLANK) return; // dont flag an already opened mine + else dboard[mby][mbx] = FLAG; // flag if not flagged already + reveal(gamew, dboard, mby, mbx, mby+1, 3*mbx+2); } -void defuse_mine(WINDOW *gameWin, char **dispboard, char **mineboard, int mby, int mbx) +void defuse_mine(WINDOW *gamew, char **dboard, char **mboard, int mby, int mbx) { refresh(); - dispboard[mby][mbx] = mineboard[mby][mbx] = DEFUSED; - reveal(gameWin, dispboard, mby, mbx, mby+1, 3*mbx+2); + dboard[mby][mbx] = mboard[mby][mbx] = DEFUSED; + reveal(gamew, dboard, mby, mbx, mby+1, 3*mbx+2); } -void transfer(char **dispboard, char **mineboard, int mby, int mbx) +void transfer(char **dboard, char **mboard, int mby, int mbx) { - dispboard[mby][mbx] = mineboard[mby][mbx]; + dboard[mby][mbx] = mboard[mby][mbx]; } -void reveal(WINDOW *gameWin, char **dispboard, int mby, int mbx, int yLoc, int xLoc) +void reveal(WINDOW *gamew, char **dboard, int mby, int mbx, int y, int x) { - mvwaddch(gameWin, yLoc, xLoc, dispboard[mby][mbx]); - wrefresh(gameWin); + mvwaddch(gamew, y, x, dboard[mby][mbx]); + wrefresh(gamew); } -bool is_defused(char **dispboard, char **mineboard, int mby, int mbx) +bool is_defused(char **dboard, char **mboard, int mby, int mbx) { - return ((dispboard[mby][mbx] == DEFUSED)) ? true : false; + return ((dboard[mby][mbx] == DEFUSED)) ? true : false; } -void handle_gameover(WINDOW *gameWin, char **mineboard, int ymid, int xmid, int COLS, int ROWS, int mby, int mbx) +void handle_gameover(WINDOW *gamew, char **mboard, int ymid, int xmid, int COLS, int ROWS, int mby, int mbx) { - game_over(gameWin, mineboard, ymid, xmid); + game_over(gamew, mboard, ymid, xmid); getchar(); - print_board(gameWin, mineboard, COLS, ROWS); - session_write(mineboard, COLS, ROWS, mbx, mby, "lost"); + print_board(gamew, mboard, COLS, ROWS); + session_write(mboard, COLS, ROWS, mbx, mby, "lost"); } -void handle_win(WINDOW *gameWin, char **mineboard, int ymid, int xmid, int COLS, int ROWS, int mby, int mbx, int numDefused) +void handle_win(WINDOW *gamew, char **mboard, int ymid, int xmid, int COLS, int ROWS, int mby, int mbx, int ndefused) { - game_won(gameWin, ymid, xmid); + game_won(gamew, ymid, xmid); getchar(); - session_write(mineboard, COLS, ROWS, mbx, mby, "won"); - score_write(numDefused, COLS, ROWS); + session_write(mboard, COLS, ROWS, mbx, mby, "won"); + score_write(ndefused, COLS, ROWS); } diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/main.c b/assignment-1.5-arrays-pointers-files/minecurses/src/main.c @@ -13,17 +13,17 @@ int main(int argc, char **argv) int NMINES = set_nmines(menuw, COLS*ROWS); WINDOW *gamew = game_win(COLS, ROWS, NMINES); - char **dispboard = init_dispboard(gamew, COLS, ROWS); - char **mineboard = init_mineboard(gamew, COLS, ROWS, NMINES); + char **dboard = init_dboard(gamew, COLS, ROWS); + char **mboard = init_mboard(gamew, COLS, ROWS, NMINES); - pthread_t audioThread; - long threadID = 1; - pthread_create(&audioThread, NULL, play_audio, (void *)threadID); - play_minesweeper(gamew, dispboard, mineboard, COLS, ROWS, NMINES); + pthread_t audiothread; + long threadid = 1; + pthread_create(&audiothread, NULL, play_audio, (void *)threadid); + play_minesweeper(gamew, dboard, mboard, COLS, ROWS, NMINES); - pthread_cancel(audioThread); - free(dispboard); - free(mineboard); + pthread_cancel(audiothread); + free(dboard); + free(mboard); endwin(); return 0; diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.c @@ -1,40 +1,40 @@ #include "minesweeper.h" -char **init_dispboard(WINDOW *gamew, int COLS, int ROWS) +char **init_dboard(WINDOW *gamew, int COLS, int ROWS) { int i; - char **dispboard = (char **)malloc(ROWS * sizeof(char *)); + char **dboard = (char **)malloc(ROWS * sizeof(char *)); for (i = 0; i < ROWS; i++) - dispboard[i] = (char *)malloc(COLS); + dboard[i] = (char *)malloc(COLS); - if (dispboard == NULL) + if (dboard == NULL) { mvprintw(1, 1, "Error, not enough memory, exiting..."); refresh(); exit(EXIT_FAILURE); } - else fill_dispboard(dispboard, COLS, ROWS); + else fill_dboard(dboard, COLS, ROWS); - return dispboard; + return dboard; } -void fill_dispboard(char **dispboard, int COLS, int ROWS) +void fill_dboard(char **dboard, int COLS, int ROWS) { int i, j; for (i = 0; i < ROWS; i++) for (j = 0; j < COLS; j++) - dispboard[i][j] = BLANK; + dboard[i][j] = BLANK; } -char **init_mineboard(WINDOW *gamew, int COLS, int ROWS, int NMINES) +char **init_mboard(WINDOW *gamew, int COLS, int ROWS, int NMINES) { int i; - char **mineboard = (char **)malloc(ROWS * sizeof(char *)); + char **mboard = (char **)malloc(ROWS * sizeof(char *)); for (i = 0; i < ROWS; i++) - mineboard[i] = (char *)malloc(COLS); + mboard[i] = (char *)malloc(COLS); - if (mineboard == NULL) + if (mboard == NULL) { mvprintw(1, 1, "Error, not enough memory, exiting..."); refresh(); @@ -42,41 +42,41 @@ char **init_mineboard(WINDOW *gamew, int COLS, int ROWS, int NMINES) } else { - place_mines(mineboard, COLS, ROWS, NMINES); - add_adj(mineboard, COLS, ROWS); - fill_spaces(mineboard, COLS, ROWS, NMINES); + place_mines(mboard, COLS, ROWS, NMINES); + add_adj(mboard, COLS, ROWS); + fill_spaces(mboard, COLS, ROWS, NMINES); } - return mineboard; + return mboard; } -void place_mines(char **mineboard, int COLS, int ROWS, int NMINES) +void place_mines(char **mboard, int COLS, int ROWS, int NMINES) { - int i, wRand, hRand; + int i, wrand, hrand; srand(time(NULL)); for (i = 0; i < NMINES; i++) { - wRand = rand() % ROWS; - hRand = rand() % COLS; - mineboard[wRand][hRand] = MINE; + wrand = rand() % ROWS; + hrand = rand() % COLS; + mboard[wrand][hrand] = MINE; } } -void add_adj(char **mineboard, int COLS, int ROWS) +void add_adj(char **mboard, int COLS, int ROWS) { int i, j; for (i = 0; i < ROWS; i++) for (j = 0; j < COLS; j++) - if (!is_mine(mineboard, i, j)) - mineboard[i][j] = adj_mines(mineboard, i, j, COLS, ROWS) + '0'; + if (!is_mine(mboard, i, j)) + mboard[i][j] = adj_mines(mboard, i, j, COLS, ROWS) + '0'; } -bool is_mine(char **mineboard, int row, int col) +bool is_mine(char **mboard, int row, int col) { - return (mineboard[row][col] == MINE) ? true : false; + return (mboard[row][col] == MINE) ? true : false; } bool outof_bounds(int row, int col, int COLS, int ROWS) @@ -84,28 +84,28 @@ bool outof_bounds(int row, int col, int COLS, int ROWS) return (row < 0 || row > ROWS-1 || col < 0 || col > COLS-1) ? true : false; } -int8_t adj_mines(char **mineboard, int row, int col, int COLS, int ROWS) +int8_t adj_mines(char **mboard, 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; + int8_t nadj = 0; + + if (!outof_bounds(row, col-1, COLS, ROWS) && mboard[row][col-1] == MINE) nadj++; // North + if (!outof_bounds(row, col+1, COLS, ROWS) && mboard[row][col+1] == MINE) nadj++; // South + if (!outof_bounds(row+1, col, COLS, ROWS) && mboard[row+1][col] == MINE) nadj++; // East + if (!outof_bounds(row-1, col, COLS, ROWS) && mboard[row-1][col] == MINE) nadj++; // West + if (!outof_bounds(row+1, col-1, COLS, ROWS) && mboard[row+1][col-1] == MINE) nadj++; // North-East + if (!outof_bounds(row-1, col-1, COLS, ROWS) && mboard[row-1][col-1] == MINE) nadj++; // North-West + if (!outof_bounds(row+1, col+1, COLS, ROWS) && mboard[row+1][col+1] == MINE) nadj++; // South-East + if (!outof_bounds(row-1, col+1, COLS, ROWS) && mboard[row-1][col+1] == MINE) nadj++; // South-West + + return nadj; } -void fill_spaces(char **mineboard, int COLS, int ROWS, int NMINES) +void fill_spaces(char **mboard, int COLS, int ROWS, int NMINES) { int i, j; for (i = 0; i < ROWS; i++) for (j = 0; j < COLS; j++) - if (mineboard[i][j] != MINE && mineboard[i][j] == '0') - mineboard[i][j] = '-'; + if (mboard[i][j] != MINE && mboard[i][j] == '0') + mboard[i][j] = '-'; } diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/navigation.c b/assignment-1.5-arrays-pointers-files/minecurses/src/navigation.c @@ -1,15 +1,15 @@ #include "navigation.h" -void navigate(WINDOW *gamew, char **mineboard, char *move, int *mboardx, int *mboardy) +void navigate(WINDOW *gamew, char **mboard, char *move, int *mbx, int *mby) { int ymax, xmax; static int y = 1, x = 2; getmaxyx(gamew, ymax, xmax); update_curs(gamew, y, x); - *mboardx = (x-2)/3; - *mboardy = y-1; - mvprintw(1, 1, "Current position: (%d, %d) ", *mboardx, *mboardy); + *mbx = (x-2)/3; + *mby = y-1; + mvprintw(1, 1, "Current position: (%d, %d) ", *mbx, *mby); refresh(); getmv(gamew, move, &y, &x, ymax, xmax); } diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.c b/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.c @@ -1,6 +1,6 @@ #include "outputs.h" -void print_board(WINDOW *gamew, char **board, int COLS, int ROWS) +void print_board(WINDOW *gamew, char **dboard, int COLS, int ROWS) { int i, j, x, y = 1; @@ -12,7 +12,7 @@ void print_board(WINDOW *gamew, char **board, int COLS, int ROWS) for (j = 0; j < COLS; j++) { wattron(gamew, A_BOLD); - mvwaddch(gamew, y, x, board[i][j]); + mvwaddch(gamew, y, x, dboard[i][j]); x += 3; } y++; @@ -36,12 +36,12 @@ void print_grid(WINDOW *gamew, int ROWS, int COLS) wrefresh(gamew); } -void session_write(char **mineboard, int COLS, int ROWS, int hitRow, int hitCol, const char *status) +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"); + FILE *mnsout = fopen(SESSION_PATH, "w"); - if (mnsOut == NULL) + if (mnsout == NULL) { mvprintw(1, 1, "Error opening file, exiting..."); refresh(); @@ -50,15 +50,15 @@ void session_write(char **mineboard, int COLS, int ROWS, int hitRow, int hitCol, 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(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[i][j]); - fprintf(mnsOut, "\n"); + fprintf(mnsout, "%c ", mboard[i][j]); + fprintf(mnsout, "\n"); } mvprintw(1, 1, "Session written to file "); @@ -66,17 +66,17 @@ void session_write(char **mineboard, int COLS, int ROWS, int hitRow, int hitCol, getchar(); } - fclose(mnsOut); + fclose(mnsout); } -void score_write(int numDefused, int COLS, int ROWS) +void score_write(int ndefused, int COLS, int ROWS) { - FILE *scoreLog = fopen(SCORE_LOG_PATH, "a"); - char *playerName = get_pname(); + FILE *scorelog = fopen(SCORE_LOG_PATH, "a"); + char *playername = get_pname(); // add titles etc - if (scoreLog == NULL) + if (scorelog == NULL) { mvprintw(1, 1, "Error opening file, exiting..."); refresh(); @@ -84,21 +84,21 @@ void score_write(int numDefused, int COLS, int ROWS) } else { - fprintf(scoreLog, "\n%s\t\t\t\t%d\t\t\t\t\t%dx%d", playerName, numDefused, COLS, ROWS); - sort_scorelog(scoreLog); // pending + fprintf(scorelog, "\n%s\t\t\t\t%d\t\t\t\t\t%dx%d", playername, ndefused, COLS, ROWS); + sort_scorelog(scorelog); // pending mvprintw(1, 1, "New score written to score log"); refresh(); getchar(); } - fclose(scoreLog); - free(playerName); + fclose(scorelog); + free(playername); } -char *get_pname() +char *get_pname(void) { char buffer[20]; - char *playerName; + char *playername; move(1, 1); echo(); @@ -109,11 +109,11 @@ char *get_pname() noecho(); refresh(); - playerName = (char *)malloc(strlen(buffer) + 1); - return (strcpy(playerName, buffer)); + playername = (char *)malloc(strlen(buffer) + 1); + return (strcpy(playername, buffer)); } -void sort_scorelog(FILE *scoreLog) +void sort_scorelog(FILE *scorelog) { } @@ -130,7 +130,7 @@ void game_won(WINDOW *gamew, int ymid, int xmid) wattroff(stdscr, A_BOLD); } -void game_over(WINDOW *gamew, char **mineboard, int ymid, int xmid) +void game_over(WINDOW *gamew, char **mboard, int ymid, int xmid) { wclear(gamew); wrefresh(gamew); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/wins.c b/assignment-1.5-arrays-pointers-files/minecurses/src/wins.c @@ -1,6 +1,6 @@ #include "wins.h" -void main_win() +void main_win(void) { initscr(); noecho(); @@ -16,9 +16,9 @@ void main_win() WINDOW *menu_win(int *ymax, int *xmax) { - int numSettings = 3; + int nsettings = 3; getmaxyx(stdscr, *ymax, *xmax); - WINDOW *menuw = newwin(numSettings+2, *xmax-8, *ymax-8, 4); + WINDOW *menuw = newwin(nsettings+2, *xmax-8, *ymax-8, 4); wattron(menuw, A_BOLD); box(menuw, 0, 0); wrefresh(menuw); @@ -38,7 +38,7 @@ WINDOW *game_win(int COLS, int ROWS, int NMINES) return gameWin; } -void options_menu() +void options_menu(void) { int ymax = getmaxy(stdscr); mvprintw(ymax-3, 5, "q Quit w/k Move up s/j Move down a/h Move Left d/l Move Right [ENTER]/o Open cell"); diff --git a/assignment-2.3-operoverloading/src/main.cpp b/assignment-2.3-operoverloading/src/main.cpp @@ -7,7 +7,7 @@ std::ostream& operator<< (std::ostream& stream, const Student& s) << "Semester: " << s.get_semester() << std::endl; } -static void cont(); +static void cont(void); static void constructor1(const Student& s1); static void ostream_overload(const Student& s1); static void constructor2(const Student& s2); @@ -59,7 +59,7 @@ int main(int argc, char **argv) return 0; } -static void cont() +static void cont(void) { std::cout << std::endl; std::cout << "Press <ENTER> to continue. . ."; diff --git a/assignment-2.3-operoverloading/src/student.cpp b/assignment-2.3-operoverloading/src/student.cpp @@ -21,7 +21,7 @@ Student::Student(const Student& s) std::copy(s.grades, s.grades+psubj, grades); } -Student::~Student() +Student::~Student(void) { delete[] this->AM; delete[] this->grades; @@ -56,14 +56,14 @@ Student& Student::operator= (const Student& s) return *this; } -float *Student::get_grades() const +float *Student::get_grades(void) const { float *ret = new float[psubj]; std::copy(grades, grades+psubj, ret); return ret; } -std::string *Student::get_submitted_subjects() const +std::string *Student::get_submitted_subjects(void) const { std::string *ret = new std::string[numSubmittedSubjects]; std::copy(submittedSubjects, submittedSubjects+numSubmittedSubjects, ret); @@ -103,7 +103,7 @@ void Student::add_grade(float grade) delete[] tmp; } -void Student::detailed_print() const +void Student::detailed_print(void) const { for (unsigned int i = 0; i < psubj; i++) { @@ -113,7 +113,7 @@ void Student::detailed_print() const std::cout << "Average grade: " << std::setprecision(2) << calc_average() << std::endl; } -float Student::calc_average() const +float Student::calc_average(void) const { float sum = 0; for (unsigned int i = 0; i < psubj; i++) diff --git a/assignment-2.3-operoverloading/src/student.h b/assignment-2.3-operoverloading/src/student.h @@ -35,13 +35,13 @@ class Student inline bool operator> (const Student& s) const {return (this->semester > s.semester) ? true : false;} inline bool operator>= (const Student& s) const {return (this->semester >= s.semester) ? true : false;} - inline const char *get_AM() const {return this->AM;} - inline const std::string& get_name() const {return this->name;} - inline unsigned int get_semester() const {return this->semester;} - inline unsigned int get_psubj() const {return this->psubj;} - float *get_grades() const; - inline unsigned int get_num_submitted_subjects() const {return this->numSubmittedSubjects;} - std::string *get_submitted_subjects() const; + inline const char *get_AM(void) const {return this->AM;} + inline const std::string& get_name(void) const {return this->name;} + inline unsigned int get_semester(void) const {return this->semester;} + inline unsigned int get_psubj(void) const {return this->psubj;} + float *get_grades(void) const; + inline unsigned int get_num_submitted_subjects(void) const {return this->numSubmittedSubjects;} + std::string *get_submitted_subjects(void) const; inline void set_AM(const char *AM) {this->AM = convert_AM(AM);} inline void set_name(const std::string& name) {this->name = name;} @@ -54,6 +54,6 @@ class Student char *convert_AM(const char *AM); float *convert_PSG(const float *grades); void add_grade(float grade); - void detailed_print() const; - float calc_average() const; + void detailed_print(void) const; + float calc_average(void) const; }; diff --git a/assignment-2.3-operoverloading/src/subject.h b/assignment-2.3-operoverloading/src/subject.h @@ -11,9 +11,9 @@ class Subject public: Subject(const std::string& code, const std::string& sname, unsigned int subjsemester); - inline const std::string& get_code() const {return this->code;} - inline const std::string& get_sname() const {return this->sname;} - inline unsigned int get_subjsemester() const {return this->subjsemester;} + inline const std::string& get_code(void) const {return this->code;} + inline const std::string& get_sname(void) const {return this->sname;} + inline unsigned int get_subjsemester(void) const {return this->subjsemester;} inline void set_code(const std::string& code) {this->code = code;} inline void set_sname(const std::string& sname) {this->sname = sname;}