This commit is contained in:
2024-12-12 20:33:05 +01:00
parent 0f018cd3af
commit 2c61fbe868
4 changed files with 30 additions and 8 deletions

View File

@@ -82,8 +82,7 @@ canIGoDirection (short int valueOfNCase, short int valueOfNPlusOneCase)
return 0; return 0;
} }
void void move (unsigned short int **tab, vect *playerPos, vect direction)
move (unsigned short int **tab, vect *playerPos, vect direction)
{ {
short int valueOfNCase short int valueOfNCase
= tab[playerPos->x + direction.x][playerPos->y + direction.y]; = tab[playerPos->x + direction.x][playerPos->y + direction.y];
@@ -157,13 +156,12 @@ move (unsigned short int **tab, vect *playerPos, vect direction)
} }
} }
void void inGameLoop (unsigned short int **tab2d, vect *playerPos, vect *targets, int nbr_targets)
inGameLoop (unsigned short int **tab2d, vect *playerPos)
{ {
vect direction = { 0, 0 }; vect direction = { 0, 0 };
char input; char input;
bool finish = false;
while (1) while (!finish)
{ {
printf ("Utilisez Z/Q/S/D pour bouger, X pour quitter : "); printf ("Utilisez Z/Q/S/D pour bouger, X pour quitter : ");
@@ -203,6 +201,25 @@ inGameLoop (unsigned short int **tab2d, vect *playerPos)
move (tab2d, playerPos, direction); move (tab2d, playerPos, direction);
printf ("\n"); printf ("\n");
if (isWin(tab2d, targets, nbr_targets))
{
finish = true;
}
screenDisplay (tab2d, 32); screenDisplay (tab2d, 32);
} }
} }
bool isWin(unsigned short int **tab2d, vect *targets, int nbr_targets)
{
int i;
for (i = 0; i < nbr_targets; ++i)
{
int x = targets[i].x;
int y = targets[i].y;
if (tab2d[x][y] != BOX_ON_TARGET)
{
return false;
}
}
return true;
}

View File

@@ -2,6 +2,7 @@
#define FONCTION_H #define FONCTION_H
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#define EMPTY 0 #define EMPTY 0
#define WALL 1 #define WALL 1
@@ -19,7 +20,8 @@ typedef struct Vecteur
unsigned short int **creatArea2D(const unsigned int N); unsigned short int **creatArea2D(const unsigned int N);
void screenDisplay( unsigned short int **tab,int size); void screenDisplay( unsigned short int **tab,int size);
void inGameLoop(unsigned short int **tab2d,vect *playerPos ); void inGameLoop (unsigned short int **tab2d, vect *playerPos, vect *targets, int nbr_targets);
bool isWin(unsigned short int **tab2d, vect *targets, int nbr_targets);
#endif // FONCTION_H #endif // FONCTION_H

2
main.c
View File

@@ -11,7 +11,7 @@ int main()
unsigned short int **tab2d = creatArea2D(32); unsigned short int **tab2d = creatArea2D(32);
targets = fileToTab2D("test.txt", tab2d, 32, playerPos, &nbr_targets); targets = fileToTab2D("test.txt", tab2d, 32, playerPos, &nbr_targets);
screenDisplay(tab2d, 32); screenDisplay(tab2d, 32);
inGameLoop(tab2d,playerPos); inGameLoop(tab2d,playerPos, targets, nbr_targets);
free(playerPos); free(playerPos);
return 0; return 0;
} }

3
test2.txt Normal file
View File

@@ -0,0 +1,3 @@
#####
#@$.#
#####