Commit 551ab3c1 authored by Erwan's avatar Erwan

Ajout de l'affichage de la grille et début de mise en place du clic sur cellule

parent 95f2f797
...@@ -2,10 +2,17 @@ ...@@ -2,10 +2,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <conio.h>
#define SIZE_OF_HEX 40
struct celluleDemineur{ struct celluleDemineur{
bool hasMine; bool hasMine;
int nearbyMine; int nearbyMine;
Vector2 pos;
bool isPressed;
bool isFlaged;
Color couleurCase;
}; };
typedef struct celluleDemineur* CelluleDemineur; typedef struct celluleDemineur* CelluleDemineur;
...@@ -61,10 +68,12 @@ int main(void) ...@@ -61,10 +68,12 @@ int main(void)
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 800;
bool gameIsLost = false;
//CREER MATRICE DES MINES //CREER MATRICE DES MINES
int nbLigneMatrice = 10, nbColonneMatrice = 10, nbMines = 50; int nbLigneMatrice = 7, nbColonneMatrice = 7, nbMines = 10;
CelluleDemineur** matriceMines = malloc(nbLigneMatrice * sizeof(CelluleDemineur *)); CelluleDemineur** matriceMines = malloc(nbLigneMatrice * sizeof(CelluleDemineur *));
for(int i=0; i<nbColonneMatrice; i++) for(int i=0; i<nbColonneMatrice; i++)
matriceMines[i] = malloc(nbColonneMatrice * sizeof(CelluleDemineur)); matriceMines[i] = malloc(nbColonneMatrice * sizeof(CelluleDemineur));
...@@ -73,14 +82,22 @@ int main(void) ...@@ -73,14 +82,22 @@ int main(void)
for(int j=0; j<nbColonneMatrice; j++){ for(int j=0; j<nbColonneMatrice; j++){
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]->isFlaged = false;
matriceMines[i][j]->nearbyMine = 0; 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 //GENERATION DES MINES
generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines); generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines);
afficherGrilleConsole(nbLigneMatrice, nbColonneMatrice, matriceMines); afficherGrilleConsole(nbLigneMatrice, nbColonneMatrice, matriceMines);
int remainingMines = nbMines;
InitWindow(screenWidth, screenHeight, "HexaSweeper"); InitWindow(screenWidth, screenHeight, "HexaSweeper");
...@@ -92,16 +109,52 @@ int main(void) ...@@ -92,16 +109,52 @@ int main(void)
{ {
// Update // 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 // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); 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(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment