commencement menu + addaptatif
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
void screenDisplay (char **tab, int size);
|
void screenDisplay (char **tab, int x, int y);
|
||||||
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);
|
||||||
|
|||||||
@@ -8,13 +8,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define EMPTY 0
|
#define EMPTY 1
|
||||||
#define WALL 1
|
#define WALL 0
|
||||||
#define BOX 2
|
#define BOX 2
|
||||||
#define TARGET 3
|
#define TARGET 3
|
||||||
#define BOX_ON_TARGET 4
|
#define BOX_ON_TARGET 4
|
||||||
#define PLAYER 5
|
#define PLAYER 5
|
||||||
#define PLAYER_ON_TARGET 6
|
#define PLAYER_ON_TARGET 6
|
||||||
|
#define BUTTON 7
|
||||||
|
|
||||||
typedef struct Vecteur
|
typedef struct Vecteur
|
||||||
{
|
{
|
||||||
@@ -39,9 +40,8 @@ typedef struct essential_sdl
|
|||||||
unsigned int size_menu;
|
unsigned int size_menu;
|
||||||
} dis;
|
} dis;
|
||||||
|
|
||||||
char **creatArea2D (const unsigned int N);
|
char **creatArea2D (const int x, const int y);
|
||||||
void free2D (char **tab, int N);
|
void free2D (char **tab, int x);
|
||||||
void screenDisplay (char **tab, int size);
|
|
||||||
bool isWin (char **tab2d, vect *targets, int nbr_targets);
|
bool isWin (char **tab2d, vect *targets, int nbr_targets);
|
||||||
bool islose (char **tab2d, const int N);
|
bool islose (char **tab2d, const int N);
|
||||||
bool blockBox (char **tab2d, vect box_coor);
|
bool blockBox (char **tab2d, vect box_coor);
|
||||||
|
|||||||
@@ -3,4 +3,6 @@
|
|||||||
#include "function.h"
|
#include "function.h"
|
||||||
vect *fileToTab2D (const char *name_file, char **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);
|
||||||
|
int countCustomMaps(char *name_directory);
|
||||||
|
char ** generatorMenu(char *name_directory, int *x , int *y);
|
||||||
#endif // !READ_H
|
#endif // !READ_H
|
||||||
|
|||||||
8
maps/custom_0.txt
Normal file
8
maps/custom_0.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
################
|
||||||
|
# #
|
||||||
|
# IIIIIIIIIII #
|
||||||
|
# CCCCCCCCCCC #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# P #
|
||||||
|
################
|
||||||
8
maps/custom_1.txt
Normal file
8
maps/custom_1.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
################
|
||||||
|
# #
|
||||||
|
# IIIIIIIIIII #
|
||||||
|
# CCCCCCCCCCC #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# P #
|
||||||
|
################
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#####
|
#####
|
||||||
#PCI#
|
#PCI#
|
||||||
#####
|
# C #
|
||||||
#####
|
#I #
|
||||||
#####
|
#####
|
||||||
@@ -17,17 +17,18 @@
|
|||||||
/**
|
/**
|
||||||
* \brief La fonction permet d'afficher simplement le plateau de jeu dans le
|
* \brief La fonction permet d'afficher simplement le plateau de jeu dans le
|
||||||
* terminal.
|
* terminal.
|
||||||
* \param tab Le tableau 2d carre du plateau.
|
* \param tab Le tableau 2d du plateau.
|
||||||
* \param size La taille du plateau.
|
* \param x Le mombre de ligne.
|
||||||
|
* \param y Le nombre de colonnes.
|
||||||
* \return Void
|
* \return Void
|
||||||
*/
|
*/
|
||||||
void screenDisplay (char **tab, int size)
|
void screenDisplay (char **tab, int x ,int y )
|
||||||
{
|
{
|
||||||
// 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 < x; ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < size; ++j)
|
for (int j = 0; j < y; ++j)
|
||||||
{
|
{
|
||||||
printf ("%c ", element[(int)tab[i][j]]);
|
printf ("%c ", element[(int)tab[i][j]]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,20 +23,20 @@
|
|||||||
* \param N La valeur N est le nombre d'élément dans le tableau.
|
* \param N La valeur N est le nombre d'élément dans le tableau.
|
||||||
* \return Le pointeur du tableau 2D carre de char (1 octet).
|
* \return Le pointeur du tableau 2D carre de char (1 octet).
|
||||||
*/
|
*/
|
||||||
char **creatArea2D (const unsigned int N)
|
char **creatArea2D (const int x, const int y)
|
||||||
{
|
{
|
||||||
char **tab2d;
|
char **tab2d;
|
||||||
tab2d = calloc (N, sizeof (char *));
|
tab2d = calloc (x, sizeof (char *));
|
||||||
if (tab2d == NULL)
|
if (tab2d == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fail = false;
|
bool fail = false;
|
||||||
unsigned int i;
|
int i;
|
||||||
for (i = 0; i < N && !fail; ++i)
|
for (i = 0; i < x && !fail; ++i)
|
||||||
{
|
{
|
||||||
tab2d[i] = calloc (N, sizeof (char));
|
tab2d[i] = calloc (y, sizeof (char));
|
||||||
if (tab2d[i] == NULL)
|
if (tab2d[i] == NULL)
|
||||||
{
|
{
|
||||||
fail = true;
|
fail = true;
|
||||||
@@ -45,7 +45,7 @@ char **creatArea2D (const unsigned int N)
|
|||||||
|
|
||||||
if (fail)
|
if (fail)
|
||||||
{
|
{
|
||||||
unsigned int j;
|
int j;
|
||||||
for (j = 0; j < i; ++j)
|
for (j = 0; j < i; ++j)
|
||||||
{
|
{
|
||||||
free (tab2d[j]);
|
free (tab2d[j]);
|
||||||
@@ -62,10 +62,10 @@ char **creatArea2D (const unsigned int N)
|
|||||||
* \param N Le nombre d'éléments.
|
* \param N Le nombre d'éléments.
|
||||||
* \return Void.
|
* \return Void.
|
||||||
*/
|
*/
|
||||||
void free2D (char **tab, int N)
|
void free2D (char **tab, int x)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < N; ++i)
|
for (i = 0; i < x; ++i)
|
||||||
{
|
{
|
||||||
free (tab[i]);
|
free (tab[i]);
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user)
|
|||||||
case 2:
|
case 2:
|
||||||
// move player and the box
|
// move player and the box
|
||||||
|
|
||||||
tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER;
|
tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER;
|
||||||
tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]
|
tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]
|
||||||
= BOX;
|
= BOX;
|
||||||
score_user->move_box++;
|
score_user->move_box++;
|
||||||
|
|||||||
@@ -26,18 +26,21 @@ int main ()
|
|||||||
vect *targets;
|
vect *targets;
|
||||||
int nbr_targets;
|
int nbr_targets;
|
||||||
score playerScore;
|
score playerScore;
|
||||||
char **tab2d = creatArea2D (SIZE_PLAY);
|
char **tab2d = creatArea2D (SIZE_PLAY, SIZE_PLAY);
|
||||||
|
|
||||||
score score_user = {0, 0, 0,0};
|
score score_user = {0, 0, 0,0};
|
||||||
|
|
||||||
|
int x,y;
|
||||||
|
char**menu = generatorMenu("maps", &x, &y);
|
||||||
|
screenDisplay(menu, x, y);
|
||||||
|
|
||||||
targets
|
targets
|
||||||
= fileToTab2D ("test.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
= fileToTab2D ("maps/original_1.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
||||||
screenDisplayGameSDL (tab2d, &display_user);
|
screenDisplayGameSDL (tab2d, &display_user);
|
||||||
screenDisplay (tab2d, SIZE_PLAY);
|
|
||||||
inGameLoop (tab2d, SIZE_PLAY, playerPos, targets, nbr_targets,
|
inGameLoop (tab2d, SIZE_PLAY, playerPos, targets, nbr_targets,
|
||||||
&display_user, &score_user);
|
&display_user, &score_user);
|
||||||
|
|
||||||
|
//screenDisplay(tab2d, SIZE_PLAY, SIZE_PLAY);
|
||||||
SDL_DestroyWindow (display_user.window);
|
SDL_DestroyWindow (display_user.window);
|
||||||
SDL_DestroyRenderer (display_user.renderer);
|
SDL_DestroyRenderer (display_user.renderer);
|
||||||
free2D (tab2d, SIZE_PLAY);
|
free2D (tab2d, SIZE_PLAY);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "../include/function.h"
|
#include "../include/function.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief La fonction permet de stocker la zone de jeu en fonction de la lecture d'un fichier.
|
* \brief La fonction permet de stocker la zone de jeu en fonction de la lecture d'un fichier.
|
||||||
@@ -68,3 +69,48 @@ vect *fileToTab2D (const char *name_file, char **tab,
|
|||||||
fclose (file);
|
fclose (file);
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int countCustomMaps(char *name_directory)
|
||||||
|
{
|
||||||
|
int nbr = 0;
|
||||||
|
char name_map[50] = "";
|
||||||
|
sprintf(name_map, "%s/custom_%d.txt",name_directory ,nbr);
|
||||||
|
FILE *file = fopen(name_map, "r");
|
||||||
|
while (file != NULL)
|
||||||
|
{
|
||||||
|
nbr++;
|
||||||
|
sprintf(name_map, "%s/custom_%d.txt",name_directory ,nbr);
|
||||||
|
printf("%p, %d, %s\n", file, nbr, name_map);
|
||||||
|
file = fopen(name_map, "r");
|
||||||
|
}
|
||||||
|
|
||||||
|
return nbr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char ** generatorMenu(char *name_directory, int *x, int *y)
|
||||||
|
{
|
||||||
|
int nbr_custom = countCustomMaps("maps");
|
||||||
|
(*x) = 7;
|
||||||
|
(*y)= 5*(3+nbr_custom) +2;
|
||||||
|
char **menu = creatArea2D(*x,*y);
|
||||||
|
int i = 1;
|
||||||
|
for (i = 1;i < *y-1; ++i)
|
||||||
|
{
|
||||||
|
menu[4][i] = EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int j,k ;
|
||||||
|
|
||||||
|
for (j = 5; j < *y; j+=5)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (k = 1 ; k < 4; ++k)
|
||||||
|
{
|
||||||
|
menu[k][j] = EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user