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
95f2f797
Commit
95f2f797
authored
Oct 28, 2020
by
Erwan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout de l'initialisation de la grille (affichage console)
parent
f20f7939
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
0 deletions
+116
-0
minesweeper.c
minesweeper.c
+116
-0
No files found.
minesweeper.c
0 → 100644
View file @
95f2f797
#include "raylib.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
struct
celluleDemineur
{
bool
hasMine
;
int
nearbyMine
;
};
typedef
struct
celluleDemineur
*
CelluleDemineur
;
bool
containsMine
(
int
line
,
int
col
,
CelluleDemineur
**
matriceMines
){
return
(
matriceMines
[
line
][
col
]
->
hasMine
==
true
);
}
void
afficherGrilleConsole
(
int
nbLigneMatrice
,
int
nbColonneMatrice
,
CelluleDemineur
**
matriceMines
){
for
(
int
i
=
0
;
i
<
nbLigneMatrice
;
i
++
){
for
(
int
j
=
0
;
j
<
nbColonneMatrice
;
j
++
){
printf
(
"M%d:N%d - "
,
matriceMines
[
i
][
j
]
->
hasMine
,
matriceMines
[
i
][
j
]
->
nearbyMine
);
}
printf
(
"
\n
"
);
}
}
void
incrementationVoisinMine
(
int
line
,
int
column
,
CelluleDemineur
**
matriceMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
){
bool
linePrev
=
(
line
-
1
>=
0
),
colPrev
=
(
column
-
1
>=
0
);
bool
lineNext
=
(
line
+
1
<
nbLigneMatrice
),
colNext
=
(
column
+
1
<
nbColonneMatrice
);
if
(
colPrev
){
matriceMines
[
line
][
column
-
1
]
->
nearbyMine
++
;}
if
(
colNext
){
matriceMines
[
line
][
column
+
1
]
->
nearbyMine
++
;}
if
(
linePrev
){
matriceMines
[
line
-
1
][
column
]
->
nearbyMine
++
;}
if
(
lineNext
){
matriceMines
[
line
+
1
][
column
]
->
nearbyMine
++
;}
if
(
line
%
2
==
0
){
if
(
linePrev
&&
colNext
){
matriceMines
[
line
-
1
][
column
+
1
]
->
nearbyMine
++
;}
if
(
lineNext
&&
colNext
){
matriceMines
[
line
+
1
][
column
+
1
]
->
nearbyMine
++
;}
}
else
{
if
(
linePrev
&&
colPrev
){
matriceMines
[
line
-
1
][
column
-
1
]
->
nearbyMine
++
;}
if
(
lineNext
&&
colPrev
){
matriceMines
[
line
+
1
][
column
-
1
]
->
nearbyMine
++
;}
}
}
void
generationMines
(
int
nbMines
,
int
nbLigneMatrice
,
int
nbColonneMatrice
,
CelluleDemineur
**
matriceMines
){
srand
(
time
(
NULL
));
for
(
int
i
=
0
;
i
<
nbMines
;
i
++
){
int
lineRand
=
rand
()
%
nbLigneMatrice
;
int
colRand
=
rand
()
%
nbColonneMatrice
;
if
(
!
containsMine
(
lineRand
,
colRand
,
matriceMines
)){
matriceMines
[
lineRand
][
colRand
]
->
hasMine
=
true
;
matriceMines
[
lineRand
][
colRand
]
->
nearbyMine
=
-
9
;
incrementationVoisinMine
(
lineRand
,
colRand
,
matriceMines
,
nbLigneMatrice
,
nbColonneMatrice
);
}
}
}
int
main
(
void
)
{
// Initialization
//--------------------------------------------------------------------------------------
const
int
screenWidth
=
800
;
const
int
screenHeight
=
450
;
//CREER MATRICE DES MINES
int
nbLigneMatrice
=
10
,
nbColonneMatrice
=
10
,
nbMines
=
50
;
CelluleDemineur
**
matriceMines
=
malloc
(
nbLigneMatrice
*
sizeof
(
CelluleDemineur
*
));
for
(
int
i
=
0
;
i
<
nbColonneMatrice
;
i
++
)
matriceMines
[
i
]
=
malloc
(
nbColonneMatrice
*
sizeof
(
CelluleDemineur
));
for
(
int
i
=
0
;
i
<
nbLigneMatrice
;
i
++
){
for
(
int
j
=
0
;
j
<
nbColonneMatrice
;
j
++
){
matriceMines
[
i
][
j
]
=
malloc
(
sizeof
(
struct
celluleDemineur
));
matriceMines
[
i
][
j
]
->
hasMine
=
false
;
matriceMines
[
i
][
j
]
->
nearbyMine
=
0
;
}
}
//GENERATION DES MINES
generationMines
(
nbMines
,
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
afficherGrilleConsole
(
nbLigneMatrice
,
nbColonneMatrice
,
matriceMines
);
InitWindow
(
screenWidth
,
screenHeight
,
"HexaSweeper"
);
SetTargetFPS
(
60
);
// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while
(
!
WindowShouldClose
())
// Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing
();
ClearBackground
(
RAYWHITE
);
DrawText
(
"Congrats! You created your first window!"
,
190
,
200
,
20
,
LIGHTGRAY
);
EndDrawing
();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow
();
// Close window and OpenGL context
//--------------------------------------------------------------------------------------
return
0
;
}
\ No newline at end of file
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