commit 4e66bd97c7a37c502fa26966efcfb2ed33acf7e4 parent 8a15841736af503f565916883f2dd7c309225b3a Author: Christos Margiolis <christos@margiolis.net> Date: Wed, 22 Jan 2020 22:26:58 +0200 added minesweeper as submodule Diffstat:
25 files changed, 4 insertions(+), 697 deletions(-)
diff --git a/.gitmodules b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "assignment-1.5-arrays-pointers-files/ncurses-minesweeper"] + path = assignment-1.5-arrays-pointers-files/ncurses-minesweeper + url = https://github.com/christosmarg/ncurses-minesweeper diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/Makefile b/assignment-1.5-arrays-pointers-files/minesweeper/Makefile @@ -1,54 +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) - -CC = gcc -CPPFLAGS += -Iinclude -CFLAGS += -Wall -LDFLAGS += -Llib - -ifeq ($(OS),Windows_NT) - detected_OS := Windows -else - detected_OS := $(shell uname) -endif -ifeq ($(OS),Linux) - detected_OS := Linux -else - detected_OS := $(shell uname) -endif - -ifeq ($(detected_OS),Linux) - LDLIBS += -lm -lncurses - MOVE = mv - MKDIR_P = mkdir -p -endif -ifeq ($(detected_OS),Windows) - LDLIBS += -lm -LC:\PDCurses\wincon -lpdcurses - MOVE = move - MKDIR_P = md -endif - -.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/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 @@ -1,13 +0,0 @@ -#ifndef GAMEPLAY_H -#define GAMEPLAY_H - -#include "minesweeper.h" - -void play_minesweeper(struct _win_st*, char **, char **, int, int, int); -void transfer(char **, char **, 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 @@ -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 BLANK ' ' -#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/minesweeper/include/navigation.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/navigation.h @@ -1,14 +0,0 @@ -#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 @@ -1,12 +0,0 @@ -#ifndef OUTPUTS_H -#define OUTPUTS_H - -#include "minesweeper.h" - -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 @@ -1,15 +0,0 @@ -#ifndef SETTINGS_H -#define SETTINGS_H - -#include "minesweeper.h" - -#define COLS_CHAR_LENGTH strlen("Columns (Max = XXX): ") + 1 -#define ROWS_CHAR_LENGTH strlen("Rows (Max = YYY): ") + 1 -#define NMINES_CHAR_LENGTH strlen("Mines (Max = MMMM): ") + 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(); - -#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 @@ -1,12 +0,0 @@ -#ifndef WINS_H -#define WINS_H - -#include "minesweeper.h" - -void main_win(); -WINDOW *menu_win(int *, int *); -WINDOW *game_win(int, int, int); -void options_menu(); -void options_win(); - -#endif diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt b/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt @@ -1,14 +0,0 @@ -Mine hit at position (2, 6) - -Board overview - -- - - - 1 1 1 - - - -- - - - 1 * 1 - - - -1 1 - - 1 1 1 - - - -* 1 1 1 1 - - - - - -2 2 3 * 2 - 1 1 1 - -1 * 3 * 2 - 1 * 1 - -2 2 2 1 1 - 1 1 1 - -* 1 - - 1 1 1 - - - -2 2 1 1 2 * 1 - - - -1 * 1 1 * 2 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,94 +0,0 @@ -#include "gameplay.h" - -void play_minesweeper(WINDOW *gameWin, char **dispboard, char **mineboard, int COLS, int ROWS, int NMINES) -{ - int mboardXLoc = 0, mboardYLoc = 0; - bool gameOver = false, cantFlag = false; - int numDefused = 0; - int yMax, xMax, yMiddle, xMiddle; - char move; - getmaxyx(stdscr, yMax, xMax); - yMiddle = yMax / 2; - xMiddle = xMax / 2; - - do - { - navigate(gameWin, dispboard, &move, &mboardXLoc, &mboardYLoc); - - if (move == '\n' || move == 'o' || move == 'O') // handle cell opening - { - transfer(dispboard, mineboard, mboardYLoc, mboardXLoc); - reveal(gameWin, dispboard, mboardYLoc, mboardXLoc, mboardYLoc + 1, 3*mboardXLoc + 2); - cantFlag = true; - if (dispboard[mboardYLoc][mboardXLoc] == MINE) gameOver = true; - } - else if (move == 'f' || move == 'F') // handle falgs - { - if (dispboard[mboardYLoc][mboardXLoc] == 'F') dispboard[mboardYLoc][mboardXLoc] = ' '; // undo flag - else if (dispboard[mboardYLoc][mboardXLoc] != 'F' && dispboard[mboardYLoc][mboardXLoc] != ' ') continue; // dont flag an already opened mine - else dispboard[mboardYLoc][mboardXLoc] = 'F'; // flag if not flagged already - reveal(gameWin, dispboard, mboardYLoc, mboardXLoc, mboardYLoc + 1, 3*mboardXLoc + 2); - } - else if (move == 'g' || move == 'G') // check for defuse - { - if (dispboard[mboardYLoc][mboardXLoc] == 'F' && mineboard[mboardYLoc][mboardXLoc] == MINE) // is_mine replace - { - numDefused++; - refresh(); - dispboard[mboardYLoc][mboardXLoc] = mineboard[mboardYLoc][mboardXLoc] = 'D'; - reveal(gameWin, dispboard, mboardYLoc, mboardXLoc, mboardYLoc + 1, 3*mboardXLoc + 2); - } - else if (dispboard[mboardYLoc][mboardXLoc] == 'F' && mineboard[mboardYLoc][mboardXLoc] != MINE) gameOver = true; // handle false defusal - } - - mvprintw(1, xMiddle-8, "Defused mines: %d/%d", numDefused, NMINES); - - } 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, mboardXLoc, mboardYLoc, "lost"); - } - - if (numDefused == NMINES) - { - game_won(gameWin, yMiddle, xMiddle); - getchar(); - filewrite(mineboard, COLS, ROWS, mboardXLoc, mboardYLoc, "won"); - } -} - - -void transfer(char **dispboard, char **mineboard, int mboardYLoc, int mboardXLoc) -{ - dispboard[mboardYLoc][mboardXLoc] = mineboard[mboardYLoc][mboardXLoc]; -} - - -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() -{ - -} - - -bool is_flagged() -{ - -} - - -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,26 +0,0 @@ -#include "minesweeper.h" - -int main(int argc, char **argv) -{ - - main_win(); - 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,123 +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); - print_board(gameWin, 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] = BLANK; -} - - -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); - //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() % ROWS; - hRand = rand() % COLS; - 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/minesweeper/src/navigation.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/navigation.c @@ -1,76 +0,0 @@ -#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; - 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,97 +0,0 @@ -#include "outputs.h" - -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++) - { - wattron(gameWin, A_BOLD); - mvwaddch(gameWin, y, x, board[i][j]); - x += 3; - } - y++; - } - - wrefresh(gameWin); - wattron(gameWin, A_BOLD); -} - - -void print_grid(WINDOW *gameWin, int ROWS, int COLS) -{ - int i, j; - - for (i = 1; i <= ROWS; i++) - { - wmove(gameWin, i, 1); - for (j = 0; j < COLS; j++) - wprintw(gameWin, "[ ]"); - } - - wrefresh(gameWin); -} - - -void filewrite(char **mineboard, int COLS, int ROWS, int hitRow, int hitCol, 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", 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"); - } - - 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); - wattron(stdscr, A_BOLD); - mvwprintw(stdscr, yMiddle-2, xMiddle-11, "You defused all the mines!"); - mvwprintw(stdscr, yMiddle-1, xMiddle-3, "You won :)"); - mvwprintw(stdscr, yMiddle, xMiddle-11, "Press any key to continue"); - refresh(); - wattroff(stdscr, A_BOLD); -} - - -void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) -{ - wclear(gameWin); - wrefresh(gameWin); - wattron(stdscr, A_BOLD); - mvwprintw(stdscr, yMiddle-2, xMiddle-24, "You hit a mine! (or tried to defuse the wrong cell)"); - mvwprintw(stdscr, yMiddle-1, xMiddle-4, "Game over :("); - mvwprintw(stdscr, yMiddle, xMiddle-11, "Press any key to continue"); - refresh(); - wattroff(stdscr, A_BOLD); -}- \ 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,51 +0,0 @@ -#include "settings.h" - -int set_cols(WINDOW *menuWin, int xMax) -{ - int COLS; - - do - { - mvwprintw(menuWin, 1, 1, "Columns (Max = %d): ", (xMax-2)/3 - 2); - wrefresh(menuWin); - scanw("%d", &COLS); - mvwprintw(menuWin, 1, COLS_CHAR_LENGTH, "%d", COLS); - wrefresh(menuWin); - } while (COLS < 5 || COLS > (xMax-2)/3 - 2); - - return COLS; -} - - -int set_rows(WINDOW *menuWin, int yMax) -{ - int ROWS; - - do - { - mvwprintw(menuWin, 2, 1, "Rows (Max = %d): ", yMax-14); - wrefresh(menuWin); - scanw("%d", &ROWS); - mvwprintw(menuWin, 2, ROWS_CHAR_LENGTH, "%d", ROWS); - wrefresh(menuWin); - } while (ROWS < 5 || ROWS > yMax - 14); - - 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, NMINES_CHAR_LENGTH, "%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/minesweeper/src/wins.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/wins.c @@ -1,50 +0,0 @@ -#include "wins.h" - -void main_win() -{ - initscr(); - noecho(); - cbreak(); - - WINDOW *mainWin = newwin(0, 0, 0, 0); - wattron(mainWin, A_BOLD); - box(mainWin, 0, 0); - refresh(); - wrefresh(mainWin); - wattroff(mainWin, A_BOLD); -} - - -WINDOW *menu_win(int *yMax, int *xMax) -{ - int numSettings = 3; - getmaxyx(stdscr, *yMax, *xMax); - WINDOW *menuWin = newwin(numSettings+2, *xMax-8, *yMax-8, 4); - wattron(menuWin, A_BOLD); - box(menuWin, 0, 0); - wrefresh(menuWin); - wattroff(menuWin, A_BOLD); - 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); - wattron(gameWin, A_BOLD); - box(gameWin, 0, 0); - wrefresh(gameWin); - wattroff(gameWin, A_BOLD); - return gameWin; -} - - -void options_menu() -{ - 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"); - mvprintw(yMax-2, 5, "f Flag cell g Defuse (if flagged only)"); - refresh(); -}- \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/ncurses-minesweeper b/assignment-1.5-arrays-pointers-files/ncurses-minesweeper @@ -0,0 +1 @@ +Subproject commit ca06188ea41b58028d10428da43bd00c8fd22501