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