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
b1ab7ffa
Commit
b1ab7ffa
authored
Oct 31, 2020
by
Erwan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout de la condition de defaite et ajout de la regeneration de la grille dans les mêmes conditions
parent
03239074
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
25 deletions
+60
-25
minesweeper.c
minesweeper.c
+60
-25
No files found.
minesweeper.c
View file @
b1ab7ffa
...
...
@@ -19,6 +19,24 @@ struct celluleDemineur{
typedef
struct
celluleDemineur
*
CelluleDemineur
;
bool
containsMine
(
int
line
,
int
col
,
CelluleDemineur
**
matriceMines
);
CelluleDemineur
*
recupererVoisins
(
int
line
,
int
column
,
CelluleDemineur
**
matriceMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
);
void
incrementationVoisinMine
(
int
line
,
int
column
,
CelluleDemineur
**
matriceMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
);
bool
revelerVoisins
(
int
line
,
int
column
,
CelluleDemineur
**
matriceMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
);
bool
revelerCase
(
CelluleDemineur
**
matriceMines
,
int
line
,
int
column
,
int
nbLigneMatrice
,
int
nbColonneMatrice
);
void
generationMines
(
int
nbMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
,
CelluleDemineur
**
matriceMines
);
void
initGrille
(
int
nbLigneMatrice
,
int
nbColonneMatrice
,
CelluleDemineur
**
matriceMines
);
float
getDistanceBetweenPoints
(
Vector2
a
,
Vector2
b
);
bool
containsMine
(
int
line
,
int
col
,
CelluleDemineur
**
matriceMines
){
return
(
matriceMines
[
line
][
col
]
->
hasMine
==
true
);
}
...
...
@@ -60,30 +78,36 @@ void incrementationVoisinMine(int line, int column, CelluleDemineur** matriceMin
free
(
voisins
);
}
void
revelerVoisins
(
int
line
,
int
column
,
CelluleDemineur
**
matriceMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
){
bool
revelerVoisins
(
int
line
,
int
column
,
CelluleDemineur
**
matriceMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
){
CelluleDemineur
*
voisins
=
recupererVoisins
(
line
,
column
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
bool
res
=
false
,
resTemp
;
for
(
int
i
=
0
;
i
<
6
;
i
++
){
if
(
voisins
[
i
]
!=
NULL
){
revelerCase
(
matriceMines
,
voisins
[
i
]
->
line
,
voisins
[
i
]
->
column
,
nbLigneMatrice
,
nbColonneMatrice
);
resTemp
=
revelerCase
(
matriceMines
,
voisins
[
i
]
->
line
,
voisins
[
i
]
->
column
,
nbLigneMatrice
,
nbColonneMatrice
);
if
(
resTemp
)
res
=
true
;
}
}
free
(
voisins
);
return
res
;
}
void
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
;
if
(
!
matriceMines
[
line
][
column
]
->
isFlaged
&&
!
matriceMines
[
line
][
column
]
->
isPressed
){
matriceMines
[
line
][
column
]
->
isPressed
=
true
;
if
(
matriceMines
[
line
][
column
]
->
nearbyMine
==
0
){
matriceMines
[
line
][
column
]
->
couleurCase
=
LIGHTGRAY
;
revelerVoisins
(
line
,
column
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
}
else
if
(
matriceMines
[
line
][
column
]
->
nearbyMine
<
0
){
re
s
=
re
velerVoisins
(
line
,
column
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
}
else
if
(
containsMine
(
line
,
column
,
matriceMines
)
){
matriceMines
[
line
][
column
]
->
couleurCase
=
MAROON
;
res
=
true
;
}
else
{
matriceMines
[
line
][
column
]
->
couleurCase
=
LIGHTGRAY
;
}
}
return
res
;
}
void
generationMines
(
int
nbMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
,
CelluleDemineur
**
matriceMines
){
...
...
@@ -131,28 +155,25 @@ int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const
int
screenWidth
=
1600
;
const
int
screenHeight
=
900
;
const
int
screenWidth
=
1280
;
const
int
screenHeight
=
1024
;
int
fontSizeBig
=
screenWidth
*
screenHeight
/
30000
;
int
fontSizeSmall
=
screenWidth
*
screenHeight
/
35000
;
InitWindow
(
screenWidth
,
screenHeight
,
"HexaSweeper - Erwan MERLY"
);
SetTargetFPS
(
60
);
srand
(
time
(
NULL
));
InitWindow
(
screenWidth
,
screenHeight
,
"HexaSweeper"
);
int
nbLigneMatrice
=
10
,
nbColonneMatrice
=
10
,
nbMines
=
20
;
int
curCaseX
=
0
,
curCaseY
=
0
,
remainingMines
=
nbMines
;
bool
lose
=
false
,
win
=
false
;
//CREER MATRICE DES MINES
int
nbLigneMatrice
=
10
,
nbColonneMatrice
=
10
,
nbMines
=
1
;
//CREATION DE LA MATRICE DES MINES
CelluleDemineur
**
matriceMines
=
malloc
(
nbLigneMatrice
*
sizeof
(
CelluleDemineur
*
));
for
(
int
i
=
0
;
i
<
nbLigneMatrice
;
i
++
)
matriceMines
[
i
]
=
calloc
(
nbLigneMatrice
*
nbColonneMatrice
,
sizeof
(
CelluleDemineur
));
initGrille
(
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
//GENERATION DES MINES
generationMines
(
nbMines
,
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
int
remainingMines
=
nbMines
,
curCaseX
=
0
,
curCaseY
=
0
;
bool
lose
=
false
,
win
=
false
;
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
...
...
@@ -160,11 +181,11 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
)){
revelerCase
(
matriceMines
,
curCaseX
,
curCaseY
,
nbLigneMatrice
,
nbColonneMatrice
);
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
)
&&
!
lose
&&
!
win
){
lose
=
revelerCase
(
matriceMines
,
curCaseX
,
curCaseY
,
nbLigneMatrice
,
nbColonneMatrice
);
}
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
)){
if
(
IsMouseButtonPressed
(
MOUSE_RIGHT_BUTTON
)
&&
!
lose
&&
!
win
){
if
(
!
matriceMines
[
curCaseX
][
curCaseY
]
->
isPressed
){
matriceMines
[
curCaseX
][
curCaseY
]
->
isFlaged
=
!
matriceMines
[
curCaseX
][
curCaseY
]
->
isFlaged
;
if
(
matriceMines
[
curCaseX
][
curCaseY
]
->
isFlaged
){
...
...
@@ -178,9 +199,9 @@ int main(void)
}
}
if
(
IsMouseButtonPressed
(
MOUSE_MIDDLE_BUTTON
)){
revelerCase
(
matriceMines
,
curCaseX
,
curCaseY
,
nbLigneMatrice
,
nbColonneMatrice
);
revelerVoisins
(
curCaseX
,
curCaseY
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
if
(
IsMouseButtonPressed
(
MOUSE_MIDDLE_BUTTON
)
&&
!
lose
&&
!
win
){
lose
=
revelerCase
(
matriceMines
,
curCaseX
,
curCaseY
,
nbLigneMatrice
,
nbColonneMatrice
);
lose
=
revelerVoisins
(
curCaseX
,
curCaseY
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
}
Vector2
mPos
=
GetMousePosition
();
...
...
@@ -198,6 +219,15 @@ int main(void)
}
if
(
win
||
lose
){
if
(
IsKeyPressed
(
'R'
)){
lose
=
false
;
initGrille
(
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
generationMines
(
nbMines
,
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
}
}
// Draw
//----------------------------------------------------------------------------------
BeginDrawing
();
...
...
@@ -214,7 +244,12 @@ int main(void)
}
}
if
(
lose
)
DrawText
(
"GAME OVER"
,
0
,
0
,
25
,
BLACK
);
if
(
lose
||
win
){
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
(
win
)
DrawText
(
"YOU WIN!"
,
screenWidth
/
2
-
3
*
fontSizeBig
,
screenHeight
*
0
.
57
,
fontSizeBig
,
LIME
);
DrawText
(
"PRESS R TO REPLAY"
,
screenWidth
/
2
-
6
*
fontSizeSmall
,
screenHeight
*
0
.
62
,
fontSizeSmall
,
DARKGRAY
);
}
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