Commit fb46b69a authored by Erwan's avatar Erwan

Code: Non adaptable aux différentes résolutions

Readme: Ajout de la descripton du jeu
parent 8badac28
......@@ -10,7 +10,20 @@ Implémentation d'un démineur via la bibliothèque Raylib
**Lancer le projet :**
**Commandes et objectifs :**
A l'aide de la souris et de ses 3 boutons :
- Gauche: Révéler la case sélectionnée
- Droite: Marquer la case comme possédant une mine
(peremt de ne pas la déclencher et est nécessaire pour gagner)
- Milieu: Révèle toutes les cases autour
Le but du jeu est de marquer toutes les cases possédant des mines le plus rapidement possible.
Les chiffres sur les cases indiquent le nombre de mines autour.
Une case à 0 révèle toutes les cases autout.
**Description fichiers :**
*minesweeper.c*:
Contient le main du projet et la description des fonctions qui font fonctionner le jeu.
***Bilan sur le projet :***
- Grande difficulté de faire un affichage adaptable à toutes les résolutions car il prend beaucoup de paramètre dans mon cas
(les tailles de la grille en plus de la taille de la fenetre)
\ No newline at end of file
......@@ -144,9 +144,9 @@ void initGrille(int nbLigneMatrice, int nbColonneMatrice, CelluleDemineur** matr
matriceMines[i][j]->couleurCase = DARKGRAY;
if(i%2 == 0){
matriceMines[i][j]->pos = (Vector2){(1.5*j+1.75)*SIZE_OF_HEX + screenWidth/(nbColonneMatrice), (1.5*i+1)*SIZE_OF_HEX + screenHeight/nbLigneMatrice};
matriceMines[i][j]->pos = (Vector2){(1.5*j+1.75)*SIZE_OF_HEX + screenWidth/nbColonneMatrice, (1.5*i+1)*SIZE_OF_HEX + screenHeight/nbLigneMatrice};
}else{
matriceMines[i][j]->pos = (Vector2){(1.5*j+1)*SIZE_OF_HEX + screenWidth/(nbColonneMatrice), (1.5*i+1)*SIZE_OF_HEX + screenHeight/nbLigneMatrice};
matriceMines[i][j]->pos = (Vector2){(1.5*j+1)*SIZE_OF_HEX + screenWidth/nbColonneMatrice, (1.5*i+1)*SIZE_OF_HEX + screenHeight/nbLigneMatrice};
}
}
}
......@@ -162,7 +162,6 @@ int main(void)
//--------------------------------------------------------------------------------------
const int screenWidth = 1280;
const int screenHeight = 800;
int fontSizeSmall = screenWidth*screenHeight/35000;
InitWindow(screenWidth, screenHeight, "HexaSweeper - Erwan MERLY");
SetTargetFPS(60);
......@@ -186,29 +185,40 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
if(!win && !lose) timeEllapsed += GetFrameTime();
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !lose && !win){
lose = revelerCase(matriceMines, curCaseX, curCaseY, nbLigneMatrice, nbColonneMatrice);
}
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && !lose && !win){
if(!matriceMines[curCaseX][curCaseY]->isPressed){
matriceMines[curCaseX][curCaseY]->ifFlagged = !matriceMines[curCaseX][curCaseY]->ifFlagged;
if(matriceMines[curCaseX][curCaseY]->ifFlagged){
matriceMines[curCaseX][curCaseY]->couleurCase = GREEN;
flaggedMines++;
}
else{
matriceMines[curCaseX][curCaseY]->couleurCase = DARKGRAY;
flaggedMines--;
if(!win && !lose){
timeEllapsed += GetFrameTime();
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
lose = revelerCase(matriceMines, curCaseX, curCaseY, nbLigneMatrice, nbColonneMatrice);
}
if(IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)){
if(!matriceMines[curCaseX][curCaseY]->isPressed){
matriceMines[curCaseX][curCaseY]->ifFlagged = !matriceMines[curCaseX][curCaseY]->ifFlagged;
if(matriceMines[curCaseX][curCaseY]->ifFlagged){
matriceMines[curCaseX][curCaseY]->couleurCase = GREEN;
flaggedMines++;
}
else{
matriceMines[curCaseX][curCaseY]->couleurCase = DARKGRAY;
flaggedMines--;
}
}
}
}
if(IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON) && !lose && !win){
lose = revelerCase(matriceMines, curCaseX, curCaseY, nbLigneMatrice, nbColonneMatrice);
lose = revelerVoisins(curCaseX, curCaseY, matriceMines, nbLigneMatrice, nbColonneMatrice);
if(IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)){
lose = revelerCase(matriceMines, curCaseX, curCaseY, nbLigneMatrice, nbColonneMatrice);
lose = revelerVoisins(curCaseX, curCaseY, matriceMines, nbLigneMatrice, nbColonneMatrice);
}
}else{
if(IsKeyPressed('R')){
lose = false;
win = false;
flaggedMines = 0;
timeEllapsed = 0;
initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines);
generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines);
}
}
Vector2 mPos = GetMousePosition();
......@@ -236,17 +246,6 @@ int main(void)
if(trueFlagged == nbMines) win = true;
}
if(win || lose){
if(IsKeyPressed('R')){
lose = false;
win = false;
flaggedMines = 0;
timeEllapsed = 0;
initGrille(nbLigneMatrice, nbColonneMatrice, matriceMines);
generationMines(nbMines, nbLigneMatrice, nbColonneMatrice, matriceMines);
}
}
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
......@@ -265,39 +264,39 @@ int main(void)
}
//AFFICHAGE DE L'INTERFACE
DrawRectangle(0, screenHeight-75, screenWidth, 75, Fade(LIGHTGRAY, 0.5f));
DrawText(TextFormat("MINE FLAGGED: %d/%d", flaggedMines, nbMines), 50, screenHeight-50, 35, GRAY);
DrawText(TextFormat("Time: %d s", (int)timeEllapsed), screenWidth-250, screenHeight-50, 35, GRAY);
DrawRectangle(0, 725, 1280, 75, Fade(LIGHTGRAY, 0.5f));
DrawText(TextFormat("MINE FLAGGED: %d/%d", flaggedMines, nbMines), 50, 750, 35, GRAY);
DrawText(TextFormat("Time: %d s", (int)timeEllapsed), 1030, 750, 35, GRAY);
//AFFICHAGE CONTROLES ET REGLES
DrawText("CONTROLS", screenWidth-275, 50, 35, DARKGRAY);
DrawText("LEFT CLICK - REVEAL TILE", screenWidth-350, 100, 18, LIGHTGRAY);
DrawText("RIGHT CLICK - FLAG TILE", screenWidth-350, 130, 18, LIGHTGRAY);
DrawText("MIDDLE CLICK - REVEAL NEIGHBOURS", screenWidth-350, 160, 18, LIGHTGRAY);
DrawText("CONTROLS", 1005, 50, 35, DARKGRAY);
DrawText("LEFT CLICK - REVEAL TILE", 930, 100, 18, LIGHTGRAY);
DrawText("RIGHT CLICK - FLAG TILE", 930, 130, 18, LIGHTGRAY);
DrawText("MIDDLE CLICK - REVEAL NEIGHBOURS", 930, 160, 18, LIGHTGRAY);
DrawText("RULES", screenWidth-275, 210, 35, DARKGRAY);
DrawText("NUMBER INDICATE MINES AROUND", screenWidth-350, 260, 18, LIGHTGRAY);
DrawText("FLAG ALL THE MINES TO WIN", screenWidth-350, 290, 18, LIGHTGRAY);
DrawText("RULES", 1005, 210, 35, DARKGRAY);
DrawText("NUMBER INDICATE MINES AROUND", 930, 260, 18, LIGHTGRAY);
DrawText("FLAG ALL THE MINES TO WIN", 930, 290, 18, LIGHTGRAY);
DrawText("TILES", screenWidth-275, 340, 35, DARKGRAY);
DrawText("DARK GRAY - NON REVEALED", screenWidth-350, 390, 18, LIGHTGRAY);
DrawText("LIGHT GRAY - REVEALED", screenWidth-350, 420, 18, LIGHTGRAY);
DrawText("GREEN - FLAGGED", screenWidth-350, 450, 18, LIGHTGRAY);
DrawText("RED - MINE", screenWidth-350, 480, 18, LIGHTGRAY);
DrawText("TILES", 1005, 340, 35, DARKGRAY);
DrawText("DARK GRAY - NON REVEALED", 930, 390, 18, LIGHTGRAY);
DrawText("LIGHT GRAY - REVEALED", 930, 420, 18, LIGHTGRAY);
DrawText("GREEN - FLAGGED", 930, 450, 18, LIGHTGRAY);
DrawText("RED - MINE", 930, 480, 18, LIGHTGRAY);
//AFFICHAGE FIN DE PARTIE
if(lose || win){
DrawRectangle(0, screenHeight*0.55, screenWidth, screenHeight/8, Fade(GRAY, 0.8f));
DrawRectangle(0, 440, 1280, 100, Fade(GRAY, 0.8f));
if(lose){
DrawText("GAME OVER", screenWidth/2-strlen("GAME OVER")/2*35, screenHeight*0.58, 35, MAROON);
DrawText("GAME OVER", 500, 465, 35, MAROON);
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*35, screenHeight*0.57, 35, LIME);
DrawText("PRESS R TO REPLAY", screenWidth/2-strlen("PRESS R TO REPLAY")/2*30, screenHeight*0.62, 30, DARKGRAY);
if(win) DrawText("YOU WIN!", 500, 465, 35, LIME);
DrawText("PRESS R TO REPLAY", 500, 495, 30, DARKGRAY);
}
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