This repository was archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.c
More file actions
64 lines (53 loc) · 1.33 KB
/
Game.c
File metadata and controls
64 lines (53 loc) · 1.33 KB
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
58
59
60
61
62
63
64
#include "Game.h"
void InitGrid(struct s_grid* grid) {
int i,j;
for(i=0; i<6; i++)
for(j=0; j<6; j++)
grid->grid[i][j]=0;
}
int FlipValue(int i) {
if(i==0)
i=1;
else
i=0;
return i;
}
void ClickOnGrid(struct s_grid* grid, int column, int line) {
grid->grid[line][column]=FlipValue(grid->grid[line][column]);
if(line!=0)
grid->grid[line-1][column]=FlipValue(grid->grid[line-1][column]);
if(line!=5)
grid->grid[line+1][column]=FlipValue(grid->grid[line+1][column]);
if(column!=0)
grid->grid[line][column-1]=FlipValue(grid->grid[line][column-1]);
if(column!=5)
grid->grid[line][column+1]=FlipValue(grid->grid[line][column+1]);
}
void GenerateGrid(struct s_grid* grid, struct s_options* options) {
int computerClick;
int column, line;
int i;
srand(time(NULL));
if(options->difficulty==0) {
computerClick=rand()%5+3;
} else if(options->difficulty==1) {
computerClick=rand()%10+6;
} else if(options->difficulty==2) {
computerClick=rand()%13+8;
}
options->maxClick=computerClick;
for(i=0; i<computerClick; i++) {
column=rand()%6;
line=rand()%6;
ClickOnGrid(grid, column, line);
}
}
int GameWon(struct s_grid* grid) {
int i,j;
int gameWon=1;
for(i=0; i<6; i++)
for(j=0; j<6; j++)
if(grid->grid[i][j]!=0)
gameWon=0;
return gameWon;
}