win
This commit is contained in:
29
function.c
29
function.c
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FONCTION_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define EMPTY 0
|
||||
#define WALL 1
|
||||
@@ -19,7 +20,8 @@ typedef struct Vecteur
|
||||
|
||||
unsigned short int **creatArea2D(const unsigned int N);
|
||||
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
|
||||
|
||||
|
||||
|
||||
2
main.c
2
main.c
@@ -11,7 +11,7 @@ int main()
|
||||
unsigned short int **tab2d = creatArea2D(32);
|
||||
targets = fileToTab2D("test.txt", tab2d, 32, playerPos, &nbr_targets);
|
||||
screenDisplay(tab2d, 32);
|
||||
inGameLoop(tab2d,playerPos);
|
||||
inGameLoop(tab2d,playerPos, targets, nbr_targets);
|
||||
free(playerPos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user