formatage
This commit is contained in:
40
function.c
40
function.c
@@ -1,4 +1,5 @@
|
|||||||
#include "function.h"
|
#include "function.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -37,7 +38,8 @@ creatArea2D (const unsigned int N)
|
|||||||
return tab2d;
|
return tab2d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free2D(unsigned short int **tab, int N)
|
void
|
||||||
|
free2D (unsigned short int **tab, int N)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < N; ++i)
|
for (i = 0; i < N; ++i)
|
||||||
@@ -56,7 +58,6 @@ canIGoDirection (short int valueOfNCase, short int valueOfNPlusOneCase)
|
|||||||
if ((valueOfNCase == BOX && valueOfNPlusOneCase == EMPTY)
|
if ((valueOfNCase == BOX && valueOfNPlusOneCase == EMPTY)
|
||||||
|| (valueOfNCase == BOX && valueOfNPlusOneCase == TARGET))
|
|| (valueOfNCase == BOX && valueOfNPlusOneCase == TARGET))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (valueOfNPlusOneCase == TARGET)
|
if (valueOfNPlusOneCase == TARGET)
|
||||||
{
|
{
|
||||||
// Box on target
|
// Box on target
|
||||||
@@ -68,7 +69,6 @@ canIGoDirection (short int valueOfNCase, short int valueOfNPlusOneCase)
|
|||||||
if ((valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == EMPTY)
|
if ((valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == EMPTY)
|
||||||
|| (valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == TARGET))
|
|| (valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == TARGET))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (valueOfNPlusOneCase == TARGET)
|
if (valueOfNPlusOneCase == TARGET)
|
||||||
{
|
{
|
||||||
// Box on target and player on target too
|
// Box on target and player on target too
|
||||||
@@ -106,7 +106,8 @@ move (unsigned short int **tab, vect *playerPos, vect direction)
|
|||||||
if (add.x < 0 || add.y < 0)
|
if (add.x < 0 || add.y < 0)
|
||||||
{
|
{
|
||||||
valueOfNPlusOneCase = WALL;
|
valueOfNPlusOneCase = WALL;
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
valueOfNPlusOneCase = tab[add.x][add.y];
|
valueOfNPlusOneCase = tab[add.x][add.y];
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,10 @@ move (unsigned short int **tab, vect *playerPos, vect direction)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
inGameLoop (unsigned short int **tab2d, int N, vect *playerPos, vect *targets,
|
inGameLoop (unsigned short int **tab2d,
|
||||||
|
int N,
|
||||||
|
vect *playerPos,
|
||||||
|
vect *targets,
|
||||||
int nbr_targets)
|
int nbr_targets)
|
||||||
{
|
{
|
||||||
vect direction = { 0, 0 };
|
vect direction = { 0, 0 };
|
||||||
@@ -187,7 +191,6 @@ inGameLoop (unsigned short int **tab2d, int N, vect *playerPos, vect *targets,
|
|||||||
bool finish = false;
|
bool finish = false;
|
||||||
while (!finish)
|
while (!finish)
|
||||||
{
|
{
|
||||||
|
|
||||||
printf ("Utilisez Z/Q/S/D pour bouger, X pour quitter : ");
|
printf ("Utilisez Z/Q/S/D pour bouger, X pour quitter : ");
|
||||||
|
|
||||||
input = getchar ();
|
input = getchar ();
|
||||||
@@ -316,7 +319,6 @@ blockBox (unsigned short int **tab2d, vect box_coor)
|
|||||||
id_box = nbr_touch - 1;
|
id_box = nbr_touch - 1;
|
||||||
}
|
}
|
||||||
indice_card[nbr_touch - 1] = i;
|
indice_card[nbr_touch - 1] = i;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nbr_touch == 0)
|
if (nbr_touch == 0)
|
||||||
@@ -326,25 +328,28 @@ blockBox (unsigned short int **tab2d, vect box_coor)
|
|||||||
{
|
{
|
||||||
if (id_box != -1)
|
if (id_box != -1)
|
||||||
{
|
{
|
||||||
vect test = plusVect(card[indice_card[(id_box+1) %3]], card[indice_card[(id_box+2) %3]]);
|
vect test = plusVect (card[indice_card[(id_box + 1) % 3]],
|
||||||
if (test.x == 0 && test.y == 0) return false;
|
card[indice_card[(id_box + 2) % 3]]);
|
||||||
|
if (test.x == 0 && test.y == 0)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (nbr_touch == 2)
|
if (nbr_touch == 2)
|
||||||
{
|
{
|
||||||
|
|
||||||
int id1 = indice_card[0];
|
int id1 = indice_card[0];
|
||||||
int id2 = indice_card[1];
|
int id2 = indice_card[1];
|
||||||
vect add = plusVect (card[id1], card[id2]);
|
vect add = plusVect (card[id1], card[id2]);
|
||||||
if (lengthVect (add) == 2)
|
if (lengthVect (add) == 2)
|
||||||
{
|
{
|
||||||
if (id_box == -1) return true;
|
if (id_box == -1)
|
||||||
vect test = plusVect(card[indice_card[id_box]], card[indice_card[(id_box+1) %2]]);
|
return true;
|
||||||
|
vect test = plusVect (card[indice_card[id_box]],
|
||||||
|
card[indice_card[(id_box + 1) % 2]]);
|
||||||
test = plusVect (test, box_coor);
|
test = plusVect (test, box_coor);
|
||||||
if (tab2d[test.x][test.y] == WALL) return true;
|
if (tab2d[test.x][test.y] == WALL)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -362,8 +367,10 @@ blockBox (unsigned short int **tab2d, vect box_coor)
|
|||||||
while (!wall)
|
while (!wall)
|
||||||
{
|
{
|
||||||
unsigned short int val = tab2d[current.x][current.y];
|
unsigned short int val = tab2d[current.x][current.y];
|
||||||
if (val == WALL) wall = true;
|
if (val == WALL)
|
||||||
if (val == TARGET) return false;
|
wall = true;
|
||||||
|
if (val == TARGET)
|
||||||
|
return false;
|
||||||
|
|
||||||
vect cur_nor = plusVect (current, normal);
|
vect cur_nor = plusVect (current, normal);
|
||||||
val = tab2d[cur_nor.x][cur_nor.y];
|
val = tab2d[cur_nor.x][cur_nor.y];
|
||||||
@@ -371,7 +378,6 @@ blockBox (unsigned short int **tab2d, vect box_coor)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#ifndef FONCTION_H
|
#ifndef FONCTION_H
|
||||||
#define FONCTION_H
|
#define FONCTION_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define EMPTY 0
|
#define EMPTY 0
|
||||||
@@ -27,17 +27,14 @@ typedef struct Score
|
|||||||
unsigned int move_box;
|
unsigned int move_box;
|
||||||
} score;
|
} score;
|
||||||
|
|
||||||
|
|
||||||
unsigned short int **creatArea2D (const unsigned int N);
|
unsigned short int **creatArea2D (const unsigned int N);
|
||||||
void free2D (unsigned short int **tab, int N);
|
void free2D (unsigned short int **tab, int N);
|
||||||
void screenDisplay (unsigned short int **tab, int size);
|
void screenDisplay (unsigned short int **tab, int size);
|
||||||
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos, vect *targets, int nbr_targets);
|
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
||||||
|
vect *targets, int nbr_targets);
|
||||||
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);
|
vect plusVect (vect one, vect two);
|
||||||
|
|
||||||
#endif // FONCTION_H
|
#endif // FONCTION_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user