fix deplacement out of range
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
void screenDisplay( unsigned short int **tab,int size)
|
void screenDisplay( unsigned short int **tab,int size)
|
||||||
{
|
{
|
||||||
puts("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ");
|
//puts("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 ");
|
||||||
char element[7] ={' ','#','S','.','*','@','+'} ;
|
char element[7] ={' ','#','S','.','*','@','+'} ;
|
||||||
for(int i=0;i<size;++i)
|
for(int i=0;i<size;++i)
|
||||||
{
|
{
|
||||||
|
|||||||
14
function.c
14
function.c
@@ -87,8 +87,18 @@ 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];
|
||||||
short int valueOfNPlusOneCase
|
|
||||||
= tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2];
|
vect add = plusVect(*playerPos, direction);
|
||||||
|
add = plusVect(add,direction);
|
||||||
|
short int valueOfNPlusOneCase;
|
||||||
|
|
||||||
|
if(add.x < 0 || add.y < 0)
|
||||||
|
{
|
||||||
|
valueOfNPlusOneCase = WALL;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
valueOfNPlusOneCase = tab[add.x][add.y];
|
||||||
|
}
|
||||||
|
|
||||||
short int returnValue = canIGoDirection (valueOfNCase, valueOfNPlusOneCase);
|
short int returnValue = canIGoDirection (valueOfNCase, valueOfNPlusOneCase);
|
||||||
short int playerState = tab[playerPos->x][playerPos->y];
|
short int playerState = tab[playerPos->x][playerPos->y];
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos, vect *targe
|
|||||||
bool isWin(unsigned short int **tab2d, vect *targets, int nbr_targets);
|
bool isWin(unsigned short int **tab2d, vect *targets, int nbr_targets);
|
||||||
bool islose(unsigned short int ** tab2d,const int N);
|
bool islose(unsigned short int ** tab2d,const int N);
|
||||||
bool blockBox(unsigned short int **tab2d, vect box_coor);
|
bool blockBox(unsigned short int **tab2d, vect box_coor);
|
||||||
|
vect plusVect (vect one, vect two);
|
||||||
|
|
||||||
#endif // FONCTION_H
|
#endif // FONCTION_H
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user