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;
}
void
move (unsigned short int **tab, vect *playerPos, vect direction)
void move (unsigned short int **tab, vect *playerPos, vect direction)
{
short int valueOfNCase
= tab[playerPos->x + direction.x][playerPos->y + direction.y];
@@ -157,13 +156,12 @@ move (unsigned short int **tab, vect *playerPos, vect direction)
}
}
void
inGameLoop (unsigned short int **tab2d, vect *playerPos)
void inGameLoop (unsigned short int **tab2d, vect *playerPos, vect *targets, int nbr_targets)
{
vect direction = { 0, 0 };
char input;
while (1)
bool finish = false;
while (!finish)
{
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);
printf ("\n");
if (isWin(tab2d, targets, nbr_targets))
{
finish = true;
}
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;
}