uni

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

commit c9843e6b904d0b3122682e2f8d9e72f786139033
parent 12427612e25be73785cdeef2727b54921d428cc0
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed, 22 Jan 2020 20:25:54 +0200

almost finished

Diffstat:
Massignment-1.5-arrays-pointers-files/minesweeper/bin/minesweeper | 0
Massignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt | 45+++++++++++++++++++++++++++++++++++++++------
Massignment-1.5-arrays-pointers-files/minesweeper/obj/gameplay.o | 0
Massignment-1.5-arrays-pointers-files/minesweeper/obj/outputs.o | 0
Massignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c | 15++++++---------
Massignment-1.5-arrays-pointers-files/minesweeper/src/outputs.c | 2+-
6 files changed, 46 insertions(+), 16 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/mnsout.txt b/assignment-1.5-arrays-pointers-files/minesweeper/mnsout.txt @@ -1,9 +1,42 @@ -Last mine defused at position (1, 2) +Mine hit at position (4, 7) Board overview -1 1 - - - -D 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 D 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 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 * 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/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/src/gameplay.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/gameplay.c @@ -4,7 +4,7 @@ void play_minesweeper(WINDOW *gameWin, char **dispboard, char **mineboard, int C { int mboardXLoc = 0, mboardYLoc = 0; bool gameOver = false, cantFlag = false; - int numDefused = 0, numFlagged = 0; + int numDefused = 0; int yMax, xMax, yMiddle, xMiddle; char move; getmaxyx(stdscr, yMax, xMax); @@ -19,16 +19,14 @@ void play_minesweeper(WINDOW *gameWin, char **dispboard, char **mineboard, int C { transfer(dispboard, mineboard, mboardYLoc, mboardXLoc); reveal(gameWin, dispboard, mboardYLoc, mboardXLoc, mboardYLoc + 1, 3*mboardXLoc + 2); - //cantFlag = true; + cantFlag = true; if (dispboard[mboardYLoc][mboardXLoc] == MINE) gameOver = true; } else if (move == 'f' || move == 'F') // handle falgs { - if (dispboard[mboardYLoc][mboardXLoc] == 'F') // undo flag - dispboard[mboardYLoc][mboardXLoc] = ' '; - else - dispboard[mboardYLoc][mboardXLoc] = 'F'; - // handle already defused mine + 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 @@ -40,8 +38,7 @@ void play_minesweeper(WINDOW *gameWin, char **dispboard, char **mineboard, int C dispboard[mboardYLoc][mboardXLoc] = mineboard[mboardYLoc][mboardXLoc] = 'D'; reveal(gameWin, dispboard, mboardYLoc, mboardXLoc, mboardYLoc + 1, 3*mboardXLoc + 2); } - // handle false defusal - // handle already defused mine + 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); diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/outputs.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/outputs.c @@ -89,7 +89,7 @@ void game_over(WINDOW *gameWin, char **mineboard, int yMiddle, int xMiddle) wclear(gameWin); wrefresh(gameWin); wattron(stdscr, A_BOLD); - mvwprintw(stdscr, yMiddle-2, xMiddle-6, "You hit a mine!"); + mvwprintw(stdscr, yMiddle-2, xMiddle-22, "You hit a mine! (or tried defused the wrong cell)"); mvwprintw(stdscr, yMiddle-1, xMiddle-4, "Game over :("); mvwprintw(stdscr, yMiddle, xMiddle-11, "Press any key to continue"); refresh();