Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MLOD_ProjectC
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Erwan MERLY
MLOD_ProjectC
Commits
7a8c3fc0
Commit
7a8c3fc0
authored
Oct 31, 2020
by
Erwan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout de la condition de victoire fonctionnelle
/!\BESOIN DE FIC SUR LA GENERATION DES MINES/!\
parent
b1ab7ffa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
16 deletions
+37
-16
minesweeper.c
minesweeper.c
+37
-16
No files found.
minesweeper.c
View file @
7a8c3fc0
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdbool.h>
#include <
math
.h>
#include <
string
.h>
#define SIZE_OF_HEX 25
#define SIZE_OF_HEX 25
...
@@ -12,7 +12,7 @@ struct celluleDemineur{
...
@@ -12,7 +12,7 @@ struct celluleDemineur{
int
nearbyMine
;
int
nearbyMine
;
Vector2
pos
;
Vector2
pos
;
bool
isPressed
;
bool
isPressed
;
bool
i
sFla
ged
;
bool
i
fFlag
ged
;
bool
isNeareast
;
bool
isNeareast
;
Color
couleurCase
;
Color
couleurCase
;
};
};
...
@@ -94,7 +94,7 @@ bool revelerVoisins(int line, int column, CelluleDemineur** matriceMines, int nb
...
@@ -94,7 +94,7 @@ bool revelerVoisins(int line, int column, CelluleDemineur** matriceMines, int nb
bool
revelerCase
(
CelluleDemineur
**
matriceMines
,
int
line
,
int
column
,
int
nbLigneMatrice
,
int
nbColonneMatrice
){
bool
revelerCase
(
CelluleDemineur
**
matriceMines
,
int
line
,
int
column
,
int
nbLigneMatrice
,
int
nbColonneMatrice
){
bool
res
=
false
;
bool
res
=
false
;
if
(
!
matriceMines
[
line
][
column
]
->
i
sFla
ged
&&
!
matriceMines
[
line
][
column
]
->
isPressed
){
if
(
!
matriceMines
[
line
][
column
]
->
i
fFlag
ged
&&
!
matriceMines
[
line
][
column
]
->
isPressed
){
matriceMines
[
line
][
column
]
->
isPressed
=
true
;
matriceMines
[
line
][
column
]
->
isPressed
=
true
;
if
(
matriceMines
[
line
][
column
]
->
nearbyMine
==
0
){
if
(
matriceMines
[
line
][
column
]
->
nearbyMine
==
0
){
...
@@ -115,7 +115,7 @@ void generationMines(int nbMines, int nbLigneMatrice, int nbColonneMatrice, Cell
...
@@ -115,7 +115,7 @@ void generationMines(int nbMines, int nbLigneMatrice, int nbColonneMatrice, Cell
int
lineRand
=
rand
()
%
nbLigneMatrice
;
int
lineRand
=
rand
()
%
nbLigneMatrice
;
int
colRand
=
rand
()
%
nbColonneMatrice
;
int
colRand
=
rand
()
%
nbColonneMatrice
;
if
(
!
containsMine
(
lineRand
,
colRand
,
matriceMines
)){
while
(
!
containsMine
(
lineRand
,
colRand
,
matriceMines
)){
matriceMines
[
lineRand
][
colRand
]
->
hasMine
=
true
;
matriceMines
[
lineRand
][
colRand
]
->
hasMine
=
true
;
matriceMines
[
lineRand
][
colRand
]
->
nearbyMine
=
-
9
;
matriceMines
[
lineRand
][
colRand
]
->
nearbyMine
=
-
9
;
incrementationVoisinMine
(
lineRand
,
colRand
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
incrementationVoisinMine
(
lineRand
,
colRand
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
...
@@ -131,7 +131,7 @@ void initGrille(int nbLigneMatrice, int nbColonneMatrice, CelluleDemineur** matr
...
@@ -131,7 +131,7 @@ void initGrille(int nbLigneMatrice, int nbColonneMatrice, CelluleDemineur** matr
matriceMines
[
i
][
j
]
=
malloc
(
sizeof
(
struct
celluleDemineur
));
matriceMines
[
i
][
j
]
=
malloc
(
sizeof
(
struct
celluleDemineur
));
matriceMines
[
i
][
j
]
->
hasMine
=
false
;
matriceMines
[
i
][
j
]
->
hasMine
=
false
;
matriceMines
[
i
][
j
]
->
isPressed
=
false
;
matriceMines
[
i
][
j
]
->
isPressed
=
false
;
matriceMines
[
i
][
j
]
->
i
sFla
ged
=
false
;
matriceMines
[
i
][
j
]
->
i
fFlag
ged
=
false
;
matriceMines
[
i
][
j
]
->
isNeareast
=
false
;
matriceMines
[
i
][
j
]
->
isNeareast
=
false
;
matriceMines
[
i
][
j
]
->
nearbyMine
=
0
;
matriceMines
[
i
][
j
]
->
nearbyMine
=
0
;
matriceMines
[
i
][
j
]
->
line
=
i
;
matriceMines
[
i
][
j
]
->
line
=
i
;
...
@@ -156,7 +156,7 @@ int main(void)
...
@@ -156,7 +156,7 @@ int main(void)
// Initialization
// Initialization
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
const
int
screenWidth
=
1280
;
const
int
screenWidth
=
1280
;
const
int
screenHeight
=
1024
;
const
int
screenHeight
=
800
;
int
fontSizeBig
=
screenWidth
*
screenHeight
/
30000
;
int
fontSizeBig
=
screenWidth
*
screenHeight
/
30000
;
int
fontSizeSmall
=
screenWidth
*
screenHeight
/
35000
;
int
fontSizeSmall
=
screenWidth
*
screenHeight
/
35000
;
InitWindow
(
screenWidth
,
screenHeight
,
"HexaSweeper - Erwan MERLY"
);
InitWindow
(
screenWidth
,
screenHeight
,
"HexaSweeper - Erwan MERLY"
);
...
@@ -164,8 +164,8 @@ int main(void)
...
@@ -164,8 +164,8 @@ int main(void)
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
int
nbLigneMatrice
=
10
,
nbColonneMatrice
=
10
,
nbMines
=
2
0
;
int
nbLigneMatrice
=
10
,
nbColonneMatrice
=
10
,
nbMines
=
8
0
;
int
curCaseX
=
0
,
curCaseY
=
0
,
remainingMines
=
nbMines
;
int
curCaseX
=
0
,
curCaseY
=
0
,
flaggedMines
=
0
;
bool
lose
=
false
,
win
=
false
;
bool
lose
=
false
,
win
=
false
;
//CREATION DE LA MATRICE DES MINES
//CREATION DE LA MATRICE DES MINES
...
@@ -187,14 +187,14 @@ int main(void)
...
@@ -187,14 +187,14 @@ int main(void)
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
)
&&
!
lose
&&
!
win
){
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
)
&&
!
lose
&&
!
win
){
if
(
!
matriceMines
[
curCaseX
][
curCaseY
]
->
isPressed
){
if
(
!
matriceMines
[
curCaseX
][
curCaseY
]
->
isPressed
){
matriceMines
[
curCaseX
][
curCaseY
]
->
i
sFlaged
=
!
matriceMines
[
curCaseX
][
curCaseY
]
->
isFla
ged
;
matriceMines
[
curCaseX
][
curCaseY
]
->
i
fFlagged
=
!
matriceMines
[
curCaseX
][
curCaseY
]
->
ifFlag
ged
;
if
(
matriceMines
[
curCaseX
][
curCaseY
]
->
i
sFla
ged
){
if
(
matriceMines
[
curCaseX
][
curCaseY
]
->
i
fFlag
ged
){
matriceMines
[
curCaseX
][
curCaseY
]
->
couleurCase
=
GREEN
;
matriceMines
[
curCaseX
][
curCaseY
]
->
couleurCase
=
GREEN
;
remainingMines
--
;
flaggedMines
++
;
}
}
else
{
else
{
matriceMines
[
curCaseX
][
curCaseY
]
->
couleurCase
=
DARKGRAY
;
matriceMines
[
curCaseX
][
curCaseY
]
->
couleurCase
=
DARKGRAY
;
remainingMines
++
;
flaggedMines
--
;
}
}
}
}
}
}
...
@@ -218,11 +218,22 @@ int main(void)
...
@@ -218,11 +218,22 @@ int main(void)
}
}
}
}
if
(
flaggedMines
==
nbMines
){
int
trueFlagged
=
0
;
for
(
int
i
=
0
;
i
<
nbLigneMatrice
;
i
++
){
for
(
int
j
=
0
;
j
<
nbColonneMatrice
;
j
++
){
if
(
matriceMines
[
i
][
j
]
->
hasMine
&&
matriceMines
[
i
][
j
]
->
ifFlagged
)
trueFlagged
++
;
}
}
if
(
trueFlagged
==
nbMines
)
win
=
true
;
}
if
(
win
||
lose
){
if
(
win
||
lose
){
if
(
IsKeyPressed
(
'R'
)){
if
(
IsKeyPressed
(
'R'
)){
lose
=
false
;
lose
=
false
;
win
=
false
;
flaggedMines
=
0
;
initGrille
(
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
initGrille
(
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
generationMines
(
nbMines
,
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
generationMines
(
nbMines
,
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
}
}
...
@@ -244,11 +255,21 @@ int main(void)
...
@@ -244,11 +255,21 @@ int main(void)
}
}
}
}
DrawRectangle
(
0
,
screenHeight
-
75
,
screenWidth
,
75
,
Fade
(
LIGHTGRAY
,
0
.
5
f
));
DrawText
(
TextFormat
(
"MINE FLAGGED: %d/%d"
,
flaggedMines
,
nbMines
),
50
,
screenHeight
-
50
,
fontSizeBig
,
GRAY
);
if
(
lose
||
win
){
if
(
lose
||
win
){
DrawRectangle
(
0
,
screenHeight
*
0
.
55
,
screenWidth
,
screenHeight
/
8
,
Fade
(
GRAY
,
0
.
8
f
));
DrawRectangle
(
0
,
screenHeight
*
0
.
55
,
screenWidth
,
screenHeight
/
8
,
Fade
(
GRAY
,
0
.
8
f
));
if
(
lose
)
DrawText
(
"GAME OVER"
,
screenWidth
/
2
-
4
*
fontSizeBig
,
screenHeight
*
0
.
58
,
fontSizeBig
,
MAROON
);
if
(
lose
){
if
(
win
)
DrawText
(
"YOU WIN!"
,
screenWidth
/
2
-
3
*
fontSizeBig
,
screenHeight
*
0
.
57
,
fontSizeBig
,
LIME
);
DrawText
(
"GAME OVER"
,
screenWidth
/
2
-
strlen
(
"GAME OVER"
)
/
2
*
fontSizeBig
,
screenHeight
*
0
.
58
,
fontSizeBig
,
MAROON
);
DrawText
(
"PRESS R TO REPLAY"
,
screenWidth
/
2
-
6
*
fontSizeSmall
,
screenHeight
*
0
.
62
,
fontSizeSmall
,
DARKGRAY
);
for
(
int
i
=
0
;
i
<
nbLigneMatrice
;
i
++
){
for
(
int
j
=
0
;
j
<
nbColonneMatrice
;
j
++
){
if
(
containsMine
(
i
,
j
,
matriceMines
))
revelerCase
(
matriceMines
,
i
,
j
,
nbLigneMatrice
,
nbColonneMatrice
);
}
}
}
if
(
win
)
DrawText
(
"YOU WIN!"
,
screenWidth
/
2
-
strlen
(
"YOU WIN!"
)
/
2
*
fontSizeBig
,
screenHeight
*
0
.
57
,
fontSizeBig
,
LIME
);
DrawText
(
"PRESS R TO REPLAY"
,
screenWidth
/
2
-
strlen
(
"PRESS R TO REPLAY"
)
/
2
*
fontSizeSmall
,
screenHeight
*
0
.
62
,
fontSizeSmall
,
DARKGRAY
);
}
}
EndDrawing
();
EndDrawing
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment