/
minesweeper.c
57 lines (47 loc) · 1.73 KB
/
minesweeper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Final Product
// Project 4: Minesweeper
// Brandon Vowell
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
#include "io.h"
// This file contains the main function and the game loop titled "runProgram"
void runProgram(char **, char **, int, int);
int main(int argc,char *argv[]) {
int width = atoi(argv[1]);
int height = atoi(argv[2]);
int number = atoi(argv[3]);
char **mine = createBoard(width, height);
setMines(mine, width, height, number);
char **status = createBoard(width, height);
numberFill(mine, width, height);
setStatus(status, width, height);
printBoard(status, width, height);
runProgram(mine, status, width, height);
return 0;
}
void runProgram(char ** mine, char ** status, int width, int height) {
int w, h;
char **composite;
int endGame = 0;
while(endGame != 1) {
// Takes in original move. If invalid, changed in "placeMove" function
printf("Which square do you wish to uncover?\n");
printf("Enter a row and column: ");
scanf(" %d %d", &h, &w);
placeMove(status, width, height, w, h);
system("clear");
composite = makeCompositeBoard(mine, status, width, height);
uncoverSquares(composite, mine, status, width, height, w, h);
printf(" -------MINESWEEPER-------\n");
printBoard(composite, width, height);
printf("\n");
endGame = boardClear(status, mine, width, height);
// If there is a winner, the game loop breaks and prints out winning statement
if(endGame == 1)
break;
endGame = bombChosen(composite, width, height);
// If a bomb is chosen, "endGame" changes to 1 and the loop breaks
}
}