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
551ab3c1
Commit
551ab3c1
authored
Oct 29, 2020
by
Erwan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout de l'affichage de la grille et début de mise en place du clic sur cellule
parent
95f2f797
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
8 deletions
+61
-8
minesweeper.c
minesweeper.c
+61
-8
No files found.
minesweeper.c
View file @
551ab3c1
...
...
@@ -2,10 +2,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <conio.h>
#define SIZE_OF_HEX 40
struct
celluleDemineur
{
bool
hasMine
;
int
nearbyMine
;
Vector2
pos
;
bool
isPressed
;
bool
isFlaged
;
Color
couleurCase
;
};
typedef
struct
celluleDemineur
*
CelluleDemineur
;
...
...
@@ -61,10 +68,12 @@ int main(void)
// Initialization
//--------------------------------------------------------------------------------------
const
int
screenWidth
=
800
;
const
int
screenHeight
=
450
;
const
int
screenHeight
=
800
;
bool
gameIsLost
=
false
;
//CREER MATRICE DES MINES
int
nbLigneMatrice
=
10
,
nbColonneMatrice
=
10
,
nbMines
=
5
0
;
int
nbLigneMatrice
=
7
,
nbColonneMatrice
=
7
,
nbMines
=
1
0
;
CelluleDemineur
**
matriceMines
=
malloc
(
nbLigneMatrice
*
sizeof
(
CelluleDemineur
*
));
for
(
int
i
=
0
;
i
<
nbColonneMatrice
;
i
++
)
matriceMines
[
i
]
=
malloc
(
nbColonneMatrice
*
sizeof
(
CelluleDemineur
));
...
...
@@ -73,14 +82,22 @@ int main(void)
for
(
int
j
=
0
;
j
<
nbColonneMatrice
;
j
++
){
matriceMines
[
i
][
j
]
=
malloc
(
sizeof
(
struct
celluleDemineur
));
matriceMines
[
i
][
j
]
->
hasMine
=
false
;
matriceMines
[
i
][
j
]
->
isPressed
=
false
;
matriceMines
[
i
][
j
]
->
isFlaged
=
false
;
matriceMines
[
i
][
j
]
->
nearbyMine
=
0
;
matriceMines
[
i
][
j
]
->
couleurCase
=
LIGHTGRAY
;
if
(
i
%
2
==
0
){
matriceMines
[
i
][
j
]
->
pos
=
(
Vector2
){(
1
.
5
*
j
+
1
.
75
)
*
SIZE_OF_HEX
,
(
1
.
5
*
i
+
1
)
*
SIZE_OF_HEX
};
}
else
{
matriceMines
[
i
][
j
]
->
pos
=
(
Vector2
){(
1
.
5
*
j
+
1
)
*
SIZE_OF_HEX
,
(
1
.
5
*
i
+
1
)
*
SIZE_OF_HEX
};
}
}
}
//GENERATION DES MINES
generationMines
(
nbMines
,
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
afficherGrilleConsole
(
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
int
remainingMines
=
nbMines
;
InitWindow
(
screenWidth
,
screenHeight
,
"HexaSweeper"
);
...
...
@@ -92,16 +109,52 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
if
(
IsMouseButtonPressed
(
MOUSE_LEFT_BUTTON
)){
matriceMines
[
0
][
0
]
->
isPressed
=
true
;
if
(
matriceMines
[
0
][
0
]
->
nearbyMine
==
0
){
matriceMines
[
0
][
0
]
->
couleurCase
=
WHITE
;
}
else
if
(
matriceMines
[
0
][
0
]
->
nearbyMine
<
0
){
matriceMines
[
0
][
0
]
->
couleurCase
=
MAROON
;
gameIsLost
=
true
;
}
else
{
matriceMines
[
0
][
0
]
->
couleurCase
=
BEIGE
;
}
}
if
(
IsMouseButtonPressed
(
MOUSE_MIDDLE_BUTTON
)){
if
(
!
matriceMines
[
0
][
0
]
->
isPressed
){
matriceMines
[
0
][
0
]
->
isFlaged
=
!
matriceMines
[
0
][
0
]
->
isFlaged
;
if
(
matriceMines
[
0
][
0
]
->
isFlaged
){
matriceMines
[
0
][
0
]
->
couleurCase
=
GREEN
;
remainingMines
--
;
}
else
{
matriceMines
[
0
][
0
]
->
couleurCase
=
LIGHTGRAY
;
remainingMines
++
;
}
}
}
// Draw
//----------------------------------------------------------------------------------
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
DrawText
(
"Congrats! You created your first window!"
,
190
,
200
,
20
,
LIGHTGRAY
);
for
(
int
i
=
0
;
i
<
nbLigneMatrice
;
i
++
){
for
(
int
j
=
0
;
j
<
nbColonneMatrice
;
j
++
){
DrawPoly
(
matriceMines
[
i
][
j
]
->
pos
,
6
,
SIZE_OF_HEX
,
0
,
GRAY
);
DrawPoly
(
matriceMines
[
i
][
j
]
->
pos
,
6
,
SIZE_OF_HEX
-
5
,
0
,
matriceMines
[
i
][
j
]
->
couleurCase
);
if
(
matriceMines
[
i
][
j
]
->
isPressed
&&
matriceMines
[
i
][
j
]
->
nearbyMine
>
0
)
DrawText
(
TextFormat
(
"%i"
,
matriceMines
[
i
][
j
]
->
nearbyMine
),
matriceMines
[
i
][
j
]
->
pos
.
x
,
matriceMines
[
i
][
j
]
->
pos
.
y
,
SIZE_OF_HEX
/
2
,
BROWN
);
}
}
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