unsigne short int -> char
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void screenDisplay (unsigned short int **tab, int size)
|
void screenDisplay (char **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', '.', '*', '@', '+' };
|
||||||
@@ -18,13 +18,13 @@ void screenDisplay (unsigned short int **tab, int size)
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < size; ++j)
|
for (int j = 0; j < size; ++j)
|
||||||
{
|
{
|
||||||
printf ("%c ", element[tab[i][j]]);
|
printf ("%c ", element[(int)tab[i][j]]);
|
||||||
}
|
}
|
||||||
puts ("");
|
puts ("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenDisplayGameSDL (unsigned short int **tab, dis *display_user)
|
void screenDisplayGameSDL (char **tab, dis *display_user)
|
||||||
{
|
{
|
||||||
unsigned int display_game
|
unsigned int display_game
|
||||||
= display_user->size_window - display_user->size_menu;
|
= display_user->size_window - display_user->size_menu;
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
void screenDisplay (unsigned short int **tab, int size);
|
void screenDisplay (char **tab, int size);
|
||||||
int getMaxSize (dis display_user);
|
int getMaxSize (dis display_user);
|
||||||
void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
void displayImage (SDL_Renderer *renderer, SDL_Texture *texture, vect pos,
|
||||||
int size);
|
int size);
|
||||||
void initSDL (dis *display_user);
|
void initSDL (dis *display_user);
|
||||||
void screenDisplayGameSDL (unsigned short int **tab, dis *display_user);
|
void screenDisplayGameSDL (char **tab, dis *display_user);
|
||||||
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size);
|
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
29
function.c
29
function.c
@@ -11,10 +11,15 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
unsigned short int **creatArea2D (const unsigned int N)
|
/**
|
||||||
|
* \brief Cette fonction permet de creer une liste 2D carre
|
||||||
|
* \param N La valeur N est le nombre d'élément dans le tableau.
|
||||||
|
* \return Le tableau 2D carre
|
||||||
|
*/
|
||||||
|
char **creatArea2D (const unsigned int N)
|
||||||
{
|
{
|
||||||
unsigned short int **tab2d;
|
char **tab2d;
|
||||||
tab2d = calloc (N, sizeof (unsigned short int *));
|
tab2d = calloc (N, sizeof (char *));
|
||||||
if (tab2d == NULL)
|
if (tab2d == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -24,7 +29,7 @@ unsigned short int **creatArea2D (const unsigned int N)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < N && !fail; ++i)
|
for (i = 0; i < N && !fail; ++i)
|
||||||
{
|
{
|
||||||
tab2d[i] = calloc (N, sizeof (unsigned short int));
|
tab2d[i] = calloc (N, sizeof (char));
|
||||||
if (tab2d[i] == NULL)
|
if (tab2d[i] == NULL)
|
||||||
{
|
{
|
||||||
fail = true;
|
fail = true;
|
||||||
@@ -44,7 +49,7 @@ unsigned short int **creatArea2D (const unsigned int N)
|
|||||||
return tab2d;
|
return tab2d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free2D (unsigned short int **tab, int N)
|
void free2D (char **tab, int N)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < N; ++i)
|
for (i = 0; i < N; ++i)
|
||||||
@@ -99,7 +104,7 @@ short int canIGoDirection (short int valueOfNCase,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move (unsigned short int **tab, vect *playerPos, vect direction,
|
void move (char **tab, vect *playerPos, vect direction,
|
||||||
score *score_user)
|
score *score_user)
|
||||||
{
|
{
|
||||||
short int valueOfNCase
|
short int valueOfNCase
|
||||||
@@ -193,7 +198,7 @@ void move (unsigned short int **tab, vect *playerPos, vect direction,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
void inGameLoop (char **tab2d, int N, vect *playerPos,
|
||||||
vect *targets, int nbr_targets, dis *display_user,
|
vect *targets, int nbr_targets, dis *display_user,
|
||||||
score *score_user)
|
score *score_user)
|
||||||
{
|
{
|
||||||
@@ -286,7 +291,7 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWin (unsigned short int **tab2d, vect *targets, int nbr_targets)
|
bool isWin (char **tab2d, vect *targets, int nbr_targets)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < nbr_targets; ++i)
|
for (i = 0; i < nbr_targets; ++i)
|
||||||
@@ -301,7 +306,7 @@ bool isWin (unsigned short int **tab2d, vect *targets, int nbr_targets)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool islose (unsigned short int **tab2d, const int N)
|
bool islose (char **tab2d, const int N)
|
||||||
{
|
{
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
for (x = 0; x < N; ++x)
|
for (x = 0; x < N; ++x)
|
||||||
@@ -336,7 +341,7 @@ vect plusVect (vect one, vect two)
|
|||||||
|
|
||||||
int lengthVect (vect vector) { return abs (vector.x) + abs (vector.y); }
|
int lengthVect (vect vector) { return abs (vector.x) + abs (vector.y); }
|
||||||
|
|
||||||
bool blockBox (unsigned short int **tab2d, vect box_coor)
|
bool blockBox (char **tab2d, vect box_coor)
|
||||||
{
|
{
|
||||||
int nbr_touch = 0;
|
int nbr_touch = 0;
|
||||||
vect card[4] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };
|
vect card[4] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };
|
||||||
@@ -346,7 +351,7 @@ bool blockBox (unsigned short int **tab2d, vect box_coor)
|
|||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
vect test = plusVect (box_coor, card[i]);
|
vect test = plusVect (box_coor, card[i]);
|
||||||
unsigned short int val = tab2d[test.x][test.y];
|
char val = tab2d[test.x][test.y];
|
||||||
if (val == BOX || val == WALL || val == BOX_ON_TARGET)
|
if (val == BOX || val == WALL || val == BOX_ON_TARGET)
|
||||||
{
|
{
|
||||||
nbr_touch++;
|
nbr_touch++;
|
||||||
@@ -417,7 +422,7 @@ bool blockBox (unsigned short int **tab2d, vect box_coor)
|
|||||||
vect current = plusVect (box_coor, dir_test[i]);
|
vect current = plusVect (box_coor, dir_test[i]);
|
||||||
while (!wall)
|
while (!wall)
|
||||||
{
|
{
|
||||||
unsigned short int val = tab2d[current.x][current.y];
|
char val = tab2d[current.x][current.y];
|
||||||
if (val == WALL)
|
if (val == WALL)
|
||||||
wall = true;
|
wall = true;
|
||||||
if (val == TARGET)
|
if (val == TARGET)
|
||||||
|
|||||||
14
function.h
14
function.h
@@ -39,14 +39,14 @@ typedef struct essential_sdl
|
|||||||
unsigned int size_menu;
|
unsigned int size_menu;
|
||||||
} dis;
|
} dis;
|
||||||
|
|
||||||
unsigned short int **creatArea2D (const unsigned int N);
|
char **creatArea2D (const unsigned int N);
|
||||||
void free2D (unsigned short int **tab, int N);
|
void free2D (char **tab, int N);
|
||||||
void screenDisplay (unsigned short int **tab, int size);
|
void screenDisplay (char **tab, int size);
|
||||||
bool isWin (unsigned short int **tab2d, vect *targets, int nbr_targets);
|
bool isWin (char **tab2d, vect *targets, int nbr_targets);
|
||||||
bool islose (unsigned short int **tab2d, const int N);
|
bool islose (char **tab2d, const int N);
|
||||||
bool blockBox (unsigned short int **tab2d, vect box_coor);
|
bool blockBox (char **tab2d, vect box_coor);
|
||||||
vect plusVect (vect one, vect two);
|
vect plusVect (vect one, vect two);
|
||||||
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
void inGameLoop (char **tab2d, int N, vect *playerPos,
|
||||||
vect *targets, int nbr_targets, dis *display_user, score *score_user);
|
vect *targets, int nbr_targets, dis *display_user, score *score_user);
|
||||||
char *timeToText(time_t time);
|
char *timeToText(time_t time);
|
||||||
|
|
||||||
|
|||||||
2
main.c
2
main.c
@@ -21,7 +21,7 @@ int main ()
|
|||||||
vect *targets;
|
vect *targets;
|
||||||
int nbr_targets;
|
int nbr_targets;
|
||||||
score playerScore;
|
score playerScore;
|
||||||
unsigned short int **tab2d = creatArea2D (SIZE_PLAY);
|
char **tab2d = creatArea2D (SIZE_PLAY);
|
||||||
|
|
||||||
score score_user = {0, 0, 0,0};
|
score score_user = {0, 0, 0,0};
|
||||||
|
|
||||||
|
|||||||
2
read.c
2
read.c
@@ -2,7 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
vect *fileToTab2D (const char *name_file, unsigned short int **tab,
|
vect *fileToTab2D (const char *name_file, char **tab,
|
||||||
const unsigned N, vect *player, int *nbr_targets)
|
const unsigned N, vect *player, int *nbr_targets)
|
||||||
{
|
{
|
||||||
vect *targets = malloc (sizeof (vect));
|
vect *targets = malloc (sizeof (vect));
|
||||||
|
|||||||
2
read.h
2
read.h
@@ -1,6 +1,6 @@
|
|||||||
#ifndef READ_H
|
#ifndef READ_H
|
||||||
#define READ_H
|
#define READ_H
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
vect *fileToTab2D (const char *name_file, unsigned short int **tab,
|
vect *fileToTab2D (const char *name_file, char **tab,
|
||||||
const unsigned N, vect *player, int *nbr_targets);
|
const unsigned N, vect *player, int *nbr_targets);
|
||||||
#endif // !READ_H
|
#endif // !READ_H
|
||||||
|
|||||||
Reference in New Issue
Block a user