Added tiles and sprites, creating arenaGUI

This commit is contained in:
JackCarterSmith 2018-06-21 16:00:37 +02:00
parent fc7085d306
commit b3a0b6619e
24 changed files with 1101 additions and 1028 deletions

View File

@ -1,99 +1,99 @@
/* /*
* IAEngine.c * IAEngine.c
* *
* Created on: 17 juin 2018 * Created on: 17 juin 2018
* Author: isen * Author: isen
* *
* Fonction qui va définir le comportement joueur(s) "ordinateur" * Fonction qui va définir le comportement joueur(s) "ordinateur"
*/ */
#include "playerInterface.h" #include "playerInterface.h"
#include "SDL2/SDL.h" #include "SDL2/SDL.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
int IAEngine(PLAYER * player1, PLAYER * player2) int IAEngine(PLAYER * player1, PLAYER * player2)
{ {
char Race[20]; char Race[20];
//Player 1 est le joueur, player 2 le bot //Player 1 est le joueur, player 2 le bot
if((player1 != NULL) & (player2 !=NULL)) if((player1 != NULL) & (player2 !=NULL))
{ {
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur //On récupère les positions des 2 joueurs . L'IA sait où est le joueur
int Player1PositionX = player1->PositionX; int Player1PositionX = player1->PositionX;
int Player1PositionY = player1->PositionY; int Player1PositionY = player1->PositionY;
int Player2PositionX = player2->PositionX; int Player2PositionX = player2->PositionX;
int Player2PositionY = player2->PositionY; int Player2PositionY = player2->PositionY;
int action; int action;
action = FindShortestPath(Player1PositionX,Player1PositionY,Player2PositionX,Player2PositionY); action = FindShortestPath(Player1PositionX,Player1PositionY,Player2PositionX,Player2PositionY);
printf("Tour de l'IA\n"); printf("Tour de l'IA\n");
if(action == 5) if(action == 5)
{ {
AttackPlayer(player1,player2); AttackPlayer(player1,player2);
} }
else if ((action >= 1) && (action <= 4)) else if ((action >= 1) && (action <= 4))
{ {
ActionPlayer(player2,action); ActionPlayer(player2,action);
} }
} }
return 0; return 0;
} }
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY) int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY)
{ {
int differenceX = abs(Player1PositionX - Player2PositionX); int differenceX = abs(Player1PositionX - Player2PositionX);
int differenceY = abs(Player1PositionY - Player2PositionY); int differenceY = abs(Player1PositionY - Player2PositionY);
int action; int action;
//Revoir cette partie il faut que les 2 joueurs soit sur la même ligne ou colone avec une différence de ligne ou colonne de 1 //Revoir cette partie il faut que les 2 joueurs soit sur la même ligne ou colone avec une différence de ligne ou colonne de 1
if((abs(Player1PositionX - (Player2PositionX - 1)) == 1) || if((abs(Player1PositionX - (Player2PositionX - 1)) == 1) ||
(abs(Player1PositionX - (Player2PositionX + 1)) == 1) || (abs(Player1PositionX - (Player2PositionX + 1)) == 1) ||
(abs(Player1PositionX - (Player2PositionY - 1)) == 1) || (abs(Player1PositionX - (Player2PositionY - 1)) == 1) ||
(abs(Player1PositionX - (Player2PositionY + 1)) == 1)) (abs(Player1PositionX - (Player2PositionY + 1)) == 1))
{ {
printf("Les 2 joueur sont à coté\n"); printf("Les 2 joueur sont à coté\n");
printf("Le joueur 2 va combattre\n"); printf("Le joueur 2 va combattre\n");
action = 5; action = 5;
} }
if(differenceX > abs(Player1PositionX - (Player2PositionX - 1))) if(differenceX > abs(Player1PositionX - (Player2PositionX - 1)))
{ {
printf("Chemin plus court sur X\n"); printf("Chemin plus court sur X\n");
printf("Le joueur 2 va vers la gauche\n"); printf("Le joueur 2 va vers la gauche\n");
action = 4; action = 4;
} }
else if(differenceX > abs(Player1PositionX - (Player2PositionX + 1))) else if(differenceX > abs(Player1PositionX - (Player2PositionX + 1)))
{ {
printf("Chemin plus court sur X\n"); printf("Chemin plus court sur X\n");
printf("Le joueur 2 va vers la droite\n"); printf("Le joueur 2 va vers la droite\n");
action = 2; action = 2;
} }
else if(differenceY > abs(Player1PositionY - (Player2PositionY + 1))) else if(differenceY > abs(Player1PositionY - (Player2PositionY + 1)))
{ {
printf("Chemin plus court sur Y\n"); printf("Chemin plus court sur Y\n");
printf("Le joueur 2 va vers le bas\n"); printf("Le joueur 2 va vers le bas\n");
action = 3; action = 3;
} }
else if(differenceY > abs(Player1PositionY - (Player2PositionY - 1))) else if(differenceY > abs(Player1PositionY - (Player2PositionY - 1)))
{ {
printf("Chemin plus court sur Y\n"); printf("Chemin plus court sur Y\n");
printf("Le joueur 2 va vers le haut\n"); printf("Le joueur 2 va vers le haut\n");
action = 1; action = 1;
} }
else else
{ {
printf("Chemin plus long\n"); printf("Chemin plus long\n");
action = 0; action = 0;
} }
return action; return action;
} }

View File

@ -1,14 +1,14 @@
/* /*
* IAEngine.h * IAEngine.h
* *
* Created on: 17 juin 2018 * Created on: 17 juin 2018
* Author: isen * Author: isen
*/ */
#ifndef IAENGINE_H_ #ifndef IAENGINE_H_
#define IAENGINE_H_ #define IAENGINE_H_
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY); int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
int IAEngine(PLAYER * player1, PLAYER * player2); int IAEngine(PLAYER * player1, PLAYER * player2);
#endif /* IAENGINE_H_ */ #endif /* IAENGINE_H_ */

View File

@ -1,150 +1,167 @@
#include "arenaEngine.h" #include <stdlib.h>
#include <stdlib.h> #include <stdio.h>
#include <stdio.h> #include "fileHandler.h"
#include "fileHandler.h" #include "logHelper.h"
#include "logHelper.h" #include "main.h"
#include "arenaEngine.h"
/*
* Arena generate functions /*
*/ * Arena generate functions
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) { */
ARENA_H_TILE* tile_h = NULL; TILE* createTileList(void) {
TILE* origin = NULL;
if (prevHTile == NULL) {
tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0 return origin;
tile_h->type_id = 0; }
tile_h->playerOnTile = NULL;
tile_h->nextRow = NULL; ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
tile_h->nextColumn = NULL; ARENA_H_TILE* tile_h = NULL;
} else if (prevHTile != NULL) {
tile_h = calloc(1,sizeof(ARENA_H_TILE)); if (prevHTile == NULL) {
prevHTile->nextRow = tile_h; tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0
tile_h->type_id = 0; tile_h->type_id = 0;
tile_h->playerOnTile = NULL; //tile_h->playerOnTile = NULL;
tile_h->nextRow = NULL; tile_h->nextRow = NULL;
tile_h->nextColumn = NULL; tile_h->nextColumn = NULL;
} } else if (prevHTile != NULL) {
tile_h = calloc(1,sizeof(ARENA_H_TILE));
return tile_h; prevHTile->nextRow = tile_h;
} tile_h->type_id = 0;
//tile_h->playerOnTile = NULL;
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) { tile_h->nextRow = NULL;
ARENA_W_TILE* tile_w = NULL; tile_h->nextColumn = NULL;
}
if (prevHTile != NULL && prevWTile == NULL) {
tile_w = calloc(1,sizeof(ARENA_W_TILE)); return tile_h;
prevHTile->nextColumn = tile_w; }
tile_w->type_id = 0;
tile_w->playerOnTile = NULL; ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
tile_w->nextColumn = NULL; ARENA_W_TILE* tile_w = NULL;
return tile_w; if (prevHTile != NULL && prevWTile == NULL) {
} else if (prevHTile == NULL && prevWTile != NULL) { tile_w = calloc(1,sizeof(ARENA_W_TILE));
tile_w = calloc(1,sizeof(ARENA_W_TILE)); prevHTile->nextColumn = tile_w;
prevWTile->nextColumn = tile_w; tile_w->type_id = 0;
tile_w->type_id = 0; //tile_w->playerOnTile = NULL;
tile_w->playerOnTile = NULL; tile_w->nextColumn = NULL;
tile_w->nextColumn = NULL;
} return tile_w;
} else if (prevHTile == NULL && prevWTile != NULL) {
return NULL; tile_w = calloc(1,sizeof(ARENA_W_TILE));
} prevWTile->nextColumn = tile_w;
tile_w->type_id = 0;
ARENA_H_TILE* genNewArena(int size_h, int size_w) { //tile_w->playerOnTile = NULL;
ARENA_H_TILE* arenaOrigin = NULL; tile_w->nextColumn = NULL;
ARENA_H_TILE* TmpCursor_h = NULL; }
ARENA_W_TILE* TmpCursor_w = NULL;
int i,j; return NULL;
}
for(i=0;i<size_h;i++){
if (i==0) { ARENA_H_TILE* genNewArena(int size_h, int size_w) {
arenaOrigin = createHTile(NULL); ARENA_H_TILE* arenaOrigin = NULL;
TmpCursor_h = arenaOrigin; ARENA_H_TILE* TmpCursor_h = NULL;
} else { ARENA_W_TILE* TmpCursor_w = NULL;
TmpCursor_h = createHTile(TmpCursor_h); int i,j;
}
for(i=0;i<size_h;i++){
for(j=0;j<size_w;j++){ if (i==0) {
if (j==0) { arenaOrigin = createHTile(NULL);
TmpCursor_w = createWTile(TmpCursor_h, NULL); TmpCursor_h = arenaOrigin;
} else { } else {
createWTile(NULL, TmpCursor_w); TmpCursor_h = createHTile(TmpCursor_h);
} }
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn; for(j=0;j<size_w;j++){
} if (j==0) {
} TmpCursor_w = createWTile(TmpCursor_h, NULL);
} else {
return arenaOrigin; createWTile(NULL, TmpCursor_w);
} }
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
}
/* }
* Arena delete functions
*/ return arenaOrigin;
void deleteWTile(ARENA_W_TILE* WTile) { }
if (WTile->nextColumn != NULL) {
deleteWTile(WTile->nextColumn);
}
/*
free(WTile); * Arena delete functions
} */
void deleteWTile(ARENA_W_TILE* WTile) {
void deleteHTile(ARENA_H_TILE* HTile) { if (WTile->nextColumn != NULL) {
if (HTile->nextRow != NULL) { deleteWTile(WTile->nextColumn);
deleteHTile(HTile->nextRow); }
}
free(WTile);
deleteWTile(HTile->nextColumn); }
free(HTile);
} void deleteHTile(ARENA_H_TILE* HTile) {
if (HTile->nextRow != NULL) {
void deleteArena(ARENA_H_TILE* arena) { deleteHTile(HTile->nextRow);
deleteHTile(arena); }
}
deleteWTile(HTile->nextColumn);
free(HTile);
}
/*
* Arena status functions void deleteArena(ARENA_H_TILE* arena) {
*/ deleteHTile(arena);
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) { }
int type_id = -1;
int i;
if (coord_y == 0) { /*
ARENA_H_TILE* tile_h = NULL; * Arena status functions
*/
tile_h = arena; int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
if (coord_x != 0) { int type_id = -1;
for (i=0;i<coord_x;i++) { int i;
tile_h = arena->nextRow;
} if (coord_x > A_WIDTH || coord_y > A_HEIGHT) return -1;
}
if (coord_y == 0) {
type_id = tile_h->type_id; ARENA_H_TILE* tile_h = NULL;
} else {
ARENA_W_TILE* tile_w = NULL; tile_h = arena;
ARENA_H_TILE* tile_h = NULL; if (coord_x != 0) {
for (i=0;i<coord_x;i++) {
tile_h = arena; tile_h = arena->nextRow;
if (coord_x != 0) { }
for (i=0;i<coord_x;i++) { }
tile_h = tile_h->nextRow;
} type_id = tile_h->type_id;
} } else {
ARENA_W_TILE* tile_w = NULL;
tile_w = tile_h->nextColumn; ARENA_H_TILE* tile_h = NULL;
if (coord_y != 0) {
for (i=0;i<coord_y;i++) { tile_h = arena;
tile_w = tile_w->nextColumn; if (coord_x != 0) {
} for (i=0;i<coord_x;i++) {
} tile_h = tile_h->nextRow;
}
type_id = tile_w->type_id; }
}
tile_w = tile_h->nextColumn;
return type_id; if (coord_y != 0) {
} for (i=0;i<coord_y;i++) {
tile_w = tile_w->nextColumn;
}
}
type_id = tile_w->type_id;
}
return type_id;
}
int isPlayerAdjacent(PLAYER* p1, PLAYER* p2) {
int adjPlayer = -1;
if ((p1->PositionX-1 || p1->PositionX+1) == p2->PositionX && (p1->PositionY-1 || p1->PositionY+1) == p2->PositionY) adjPlayer = 1;
return adjPlayer;
}

View File

@ -1,46 +1,49 @@
#include "playerInterface.h" #include "playerInterface.h"
#include <SDL2/SDL.h>
#ifndef ARENAENGINE_H_
#define ARENAENGINE_H_ #ifndef ARENAENGINE_H_
#define ARENAENGINE_H_
/*
typedef struct items{ /*
int type_id; typedef struct items{
//texture? int type_id;
int isFlat; //texture?
int minedId; int isFlat;
struct items *nextItem; int minedId;
}ITEMS; struct items *nextItem;
*/ }ITEMS;
*/
typedef struct tileType{
int type_id; typedef struct tileType{
//texture? int type_id;
int isGround; SDL_Surface texture;
int canBeMined; int isGround;
}TILE; int canBeMined;
struct tileType *nextTile;
typedef struct arena_h_tile{ //Rows chained list }TILE;
int type_id;
PLAYER* playerOnTile; typedef struct arena_h_tile{ //Rows chained list
struct arena_h_tile *nextRow; int type_id;
struct arena_w_tile *nextColumn; //PLAYER* playerOnTile;
}ARENA_H_TILE; struct arena_h_tile *nextRow;
struct arena_w_tile *nextColumn;
typedef struct arena_w_tile{ //Columns chained list }ARENA_H_TILE;
int type_id;
PLAYER* playerOnTile; typedef struct arena_w_tile{ //Columns chained list
struct arena_w_tile *nextColumn; int type_id;
}ARENA_W_TILE; //PLAYER* playerOnTile;
struct arena_w_tile *nextColumn;
}ARENA_W_TILE;
//Generation functions
ARENA_H_TILE* genNewArena(int size_h, int size_w);
void deleteArena(ARENA_H_TILE* arena); //Generation functions
TILE* createTileList(void);
//Status functions ARENA_H_TILE* genNewArena(int size_h, int size_w);
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y); void deleteArena(ARENA_H_TILE* arena);
#endif //Status functions
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y);
#endif

View File

@ -1,3 +1,23 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "SDL2/SDL.h" #include "logHelper.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include "arenaGUI.h"
void displayArena(ARENA_H_TILE* arena, SDL_Window* window, SDL_Surface *res, int size_h, int size_w, int tile_size) {
SDL_Rect tmp_tile_coord;
int i,j;
for (i=0; i<size_h; i++) {
for (j=0; j<size_w; j++) {
tmp_tile_coord.x = i * tile_size;
tmp_tile_coord.y = j * tile_size;
SDL_BlitSurface(res, NULL, SDL_GetWindowSurface(window), &tmp_tile_coord);
SDL_UpdateWindowSurface(window);
}
}
}

View File

@ -1,6 +1,9 @@
#ifndef ARENAGUI_H_ #include "main.h"
#define ARENAGUI_H_ #include "arenaEngine.h"
#ifndef ARENAGUI_H_
#define ARENAGUI_H_
#endif
void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, SDL_Surface *res, int size_h, int size_w, int tile_size);
#endif

BIN
data/icon_ia.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
data/sprite_ia_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/sprite_player_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
data/tile_gold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
data/tile_grass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
data/tile_rock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
data/tile_tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
data/tile_water.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,15 +1,15 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
int resOpen(char* filename, FILE* f) { int resOpen(char* filename, FILE* f) {
char fLoc[128]; char fLoc[128];
strcpy(fLoc, "resources/"); strcpy(fLoc, "resources/");
strcat(fLoc, filename); strcat(fLoc, filename);
f = fopen(fLoc, "rb"); f = fopen(fLoc, "rb");
if (f != NULL) return 0; if (f != NULL) return 0;
return -1; return -1;
} }

View File

@ -1,6 +1,6 @@
#ifndef FILEHANDLER_H_ #ifndef FILEHANDLER_H_
#define FILEHANDLER_H_ #define FILEHANDLER_H_
int resOpen(char* filename); int resOpen(char* filename);
#endif #endif

View File

@ -1,76 +1,76 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "logHelper.h" #include "logHelper.h"
FILE *log_file=NULL; FILE *log_file=NULL;
int initialise_logger(){ int initialise_logger(){
time_t raw_time; time_t raw_time;
struct tm *pdh; struct tm *pdh;
time(&raw_time); time(&raw_time);
pdh = localtime(&raw_time); pdh = localtime(&raw_time);
char name[32]; char name[32];
sprintf(name, "%04d-%02d-%02d.log", pdh->tm_year+1900, pdh->tm_mon+1, pdh->tm_mday); sprintf(name, "%04d-%02d-%02d.log", pdh->tm_year+1900, pdh->tm_mon+1, pdh->tm_mday);
log_file=fopen(name, "a"); log_file=fopen(name, "a");
if(log_file==NULL) //fichier innexistant if(log_file==NULL) //fichier innexistant
{ {
log_file=fopen(name,"w+"); log_file=fopen(name,"w+");
if(log_file==NULL) { //Le prog n'a pas les droits en écriture if(log_file==NULL) { //Le prog n'a pas les droits en écriture
printf("\n****************************************************************\nATTENTION ! Le fichier de log ne peut être écris, aucune info ne sera enregistré !\n****************************************************************\n"); printf("\n****************************************************************\nATTENTION ! Le fichier de log ne peut être écris, aucune info ne sera enregistré !\n****************************************************************\n");
return -1; return -1;
} }
} }
return 0; return 0;
} }
void stop_logger() {fclose(log_file);} void stop_logger() {fclose(log_file);}
void addLogInfo(char *mess){ void addLogInfo(char *mess){
time_t now; time_t now;
struct tm* tm_info; struct tm* tm_info;
char buffer[12]; char buffer[12];
initialise_logger(); initialise_logger();
time(&now); time(&now);
tm_info = localtime(&now); tm_info = localtime(&now);
strftime(buffer, 12, "%H:%M:%S", tm_info); strftime(buffer, 12, "%H:%M:%S", tm_info);
fprintf(log_file,"[INFO][%s] %s\n", buffer, mess); fprintf(log_file,"[INFO][%s] %s\n", buffer, mess);
stop_logger(); stop_logger();
} }
void addLogWarn(char *mess){ void addLogWarn(char *mess){
time_t now; time_t now;
struct tm* tm_info; struct tm* tm_info;
char buffer[12]; char buffer[12];
initialise_logger(); initialise_logger();
time(&now); time(&now);
tm_info = localtime(&now); tm_info = localtime(&now);
strftime(buffer, 12, "%H:%M:%S", tm_info); strftime(buffer, 12, "%H:%M:%S", tm_info);
fprintf(log_file,"[WARN][%s] %s\n", buffer, mess); fprintf(log_file,"[WARN][%s] %s\n", buffer, mess);
stop_logger(); stop_logger();
} }
void addLogCritical(char *mess){ void addLogCritical(char *mess){
time_t now; time_t now;
struct tm* tm_info; struct tm* tm_info;
char buffer[12]; char buffer[12];
initialise_logger(); initialise_logger();
time(&now); time(&now);
tm_info = localtime(&now); tm_info = localtime(&now);
strftime(buffer, 12, "%H:%M:%S", tm_info); strftime(buffer, 12, "%H:%M:%S", tm_info);
fprintf(log_file,"[CRITICAL][%s] %s\n", buffer, mess); fprintf(log_file,"[CRITICAL][%s] %s\n", buffer, mess);
stop_logger(); stop_logger();
} }

View File

@ -1,11 +1,11 @@
#ifndef LOGGER_H_ #ifndef LOGGER_H_
#define LOGGER_H_ #define LOGGER_H_
int initialise_logger(); //Prépare le logger à écrire dans les fichiers de logs int initialise_logger(); //Prépare le logger à écrire dans les fichiers de logs
void stop_logger(); void stop_logger();
void addLogInfo(char *mess); //Ajoute une entrée dans le fichier de log de type INFO void addLogInfo(char *mess); //Ajoute une entrée dans le fichier de log de type INFO
void addLogWarn(char *mess); void addLogWarn(char *mess);
void addLogCritical(char *mess); //Ajoute une entrée dans le fichier de log de type CRITICAL void addLogCritical(char *mess); //Ajoute une entrée dans le fichier de log de type CRITICAL
#endif #endif

136
main.c
View File

@ -1,60 +1,76 @@
/* #include "main.h"
* main.c #include <stdio.h>
* #include <stdlib.h>
* Created on: 17 juin 2018 #include "logHelper.h"
* Author: isen #include <SDL2/SDL.h>
*/ #include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
//#include "IAEngine.h" //#include <SDL2/SDL_thread.h>
#include "playerInterface.h" //#include <SDL2/SDL_mutex.h>
#include "SDL2/SDL.h" #include "arenaEngine.h"
#include <stdio.h> #include "arenaGUI.h"
#include <stdlib.h> //#include "IAEngine.h"
#include "logHelper.h" #include "playerInterface.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_thread.h>
#include <SDL2/SDL_mutex.h> void initDisplayLib() {
#include "arenaEngine.h" if (SDL_Init(SDL_INIT_VIDEO) != 0) {
addLogCritical("Init SDL libs failed !");
#define A_HEIGHT 100
#define A_WIDTH 100 exit(EXIT_FAILURE);
}
void initDisplayLib() { }
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
addLogCritical("Init SDL libs failed !"); int main(int argc, char *argv[]) {
addLogInfo("Starting game...");
exit(EXIT_FAILURE); addLogInfo("Try init SDL libs...");
} initDisplayLib();
}
addLogInfo("Load ressources in memory...");
void initResources() { SDL_Surface *tile_grass = NULL, *tile_rock = NULL, *tile_tree = NULL, *tile_water = NULL, *sprite_player_act = NULL, *sprite_ia_act = NULL;
//resOpen(); SDL_Surface *ressource[6] = {tile_grass, tile_rock, tile_tree, tile_water, sprite_player_act, sprite_ia_act};
} SDL_Surface *sprite_player[4] = {NULL}, *sprite_ia[4] = {NULL};
tile_grass = IMG_Load("data/tile_grass.png");
int main(int argc, char *argv[]) { tile_rock = IMG_Load("data/tile_rock.png");
ARENA_H_TILE* arena = NULL; tile_tree = IMG_Load("data/tile_tree.png");
tile_water = IMG_Load("data/tile_water.png");
// Création de la fenêtre
SDL_Window* pWindow = NULL; sprite_player[DOWN] = IMG_Load("data/sprite_player_1.png");
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN); //sprite_player[UP] = IMG_Load("data/sprite_player_2.png");
//sprite_player[LEFT] = IMG_Load("data/sprite_player_3.png");
addLogInfo("Starting game..."); //sprite_player[RIGHT] = IMG_Load("data/sprite_player_4.png");
initDisplayLib();
initResources(); sprite_ia[DOWN] = IMG_Load("data/sprite_ia_1.png");
//sprite_ia[UP] = IMG_Load("data/sprite_ia_2.png");
addLogInfo("Creating new arena..."); //sprite_ia[LEFT] = IMG_Load("data/sprite_ia_3.png");
arena = genNewArena(A_HEIGHT, A_WIDTH); //sprite_ia[RIGHT] = IMG_Load("data/sprite_ia_4.png");
if (arena == NULL) {
addLogCritical("Error with arena generator !"); addLogInfo("Create SDL windows instance...");
exit(EXIT_FAILURE); SDL_Window* gameWindows = SDL_CreateWindow("Arena Survival Tournament - alpha 0.2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOWS_WIDTH, WINDOWS_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
}
addLogInfo("Successfully created arena."); addLogInfo("Creating new arena...");
ARENA_H_TILE* arena = NULL;
deleteArena(arena); arena = genNewArena(A_HEIGHT, A_WIDTH);
addLogInfo("Cleared arena."); if (arena == NULL) {
addLogCritical("Error with arena generator !");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS; addLogInfo("Successfully created arena.");
}
addLogInfo("Display arena GUI...");
sprite_player_act = sprite_player[DOWN];
sprite_ia_act = sprite_ia[DOWN];
displayArena(arena, gameWindows, tile_grass, A_HEIGHT, A_WIDTH, TILE_SIZE);
deleteArena(arena);
addLogInfo("Cleared arena.");
SDL_Delay(5000);
addLogInfo("Unload SDL libs...");
SDL_Quit();
return EXIT_SUCCESS;
}

14
main.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef MAIN_H_
#define MAIN_H_
#define A_WIDTH 20
#define A_HEIGHT 20
#define TILE_SIZE 32
#define WINDOWS_WIDTH TILE_SIZE * A_WIDTH
#define WINDOWS_HEIGHT TILE_SIZE * A_HEIGHT
enum {DOWN, UP, LEFT, RIGHT};
enum {GRASS_T, ROCK_T, TREE_T, WATER_T, PLAYER_S, IA_S};
#endif

View File

@ -1,19 +1,19 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
int createGameMenuWindows() { int createGameMenuWindows() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
SDL_Window *main_test; SDL_Window *main_test;
main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
SDL_Delay(5000); SDL_Delay(5000);
SDL_DestroyWindow(main_test); SDL_DestroyWindow(main_test);
SDL_Quit(); SDL_Quit();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,6 +1,6 @@
#ifndef MENUGUI_H_ #ifndef MENUGUI_H_
#define MENUGUI_H_ #define MENUGUI_H_
#endif #endif

View File

@ -1,468 +1,468 @@
/* /*
* playerInterface.c * playerInterface.c
* *
* Created on: 17 juin 2018 * Created on: 17 juin 2018
* Author: isen * Author: isen
*/ */
#include "playerInterface.h" #include "playerInterface.h"
#include "SDL2/SDL.h" #include "SDL2/SDL.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define ArenaMAX 100 #define ArenaMAX 100
int PlayerInterface(void) int PlayerInterface(void)
{ {
PLAYER* List=NULL; PLAYER* List=NULL;
PLAYER* Element=NULL; PLAYER* Element=NULL;
int id=0; int id=0;
int numberAlive; int numberAlive;
PLAYER* player1=NULL; PLAYER* player1=NULL;
PLAYER* player2=NULL; PLAYER* player2=NULL;
while(id<2) while(id<2)
{ {
id = id + 1; id = id + 1;
Element = createPlayer(id); Element = createPlayer(id);
List = insertRightPlaceRecursive(List,Element); List = insertRightPlaceRecursive(List,Element);
} }
displayList(List); displayList(List);
player1 = SearchPlayer(List, 1); player1 = SearchPlayer(List, 1);
player2 = SearchPlayer(List, 2); player2 = SearchPlayer(List, 2);
printf("Nom player 1 : %s\n",player1->Name); printf("Nom player 1 : %s\n",player1->Name);
printf("Nom player 2 : %s\n",player2->Name); printf("Nom player 2 : %s\n",player2->Name);
numberAlive = NumberPlayerAlive(List); numberAlive = NumberPlayerAlive(List);
printf("Nombre de joueur en vie : %i",numberAlive); printf("Nombre de joueur en vie : %i",numberAlive);
int action; int action;
do do
{ {
action=getEvent(); action=getEvent();
if(action == 1) if(action == 1)
{ {
ActionPlayer(player1,1); //Déplacement vers le haut ActionPlayer(player1,1); //Déplacement vers le haut
} }
else if(action == 2) else if(action == 2)
{ {
ActionPlayer(player1,2); //Déplacement vers la droite ActionPlayer(player1,2); //Déplacement vers la droite
} }
else if(action == 3) else if(action == 3)
{ {
ActionPlayer(player1,3); //Déplacement vers le bas ActionPlayer(player1,3); //Déplacement vers le bas
} }
else if(action == 4) else if(action == 4)
{ {
ActionPlayer(player1,4); //Déplacement vers la gauche ActionPlayer(player1,4); //Déplacement vers la gauche
} }
else if(action == 5) else if(action == 5)
{ {
//Regarder le perso en face, le plus près //Regarder le perso en face, le plus près
AttackPlayer(player1,player2); //Voir quel player on choisit d'attaquer AttackPlayer(player1,player2); //Voir quel player on choisit d'attaquer
} }
//Tour de l'IA //Tour de l'IA
IAEngine(player1,player2); IAEngine(player1,player2);
} }
while(action != -1); while(action != -1);
return -1; return -1;
//return 0; //return 0;
} }
int getEvent() int getEvent()
{ {
int action; int action;
SDL_Event event; SDL_Event event;
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */ SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
switch(event.type) /* Test du type d'événement */ switch(event.type) /* Test du type d'événement */
{ {
/* Si c'est un événement de type "Quitter" */ /* Si c'est un événement de type "Quitter" */
case SDL_QUIT : printf("QUITTER\n"); case SDL_QUIT : printf("QUITTER\n");
action = -1; action = -1;
break; break;
case SDL_KEYUP: case SDL_KEYUP:
switch(event.key.keysym.sym) //La valeur de touche switch(event.key.keysym.sym) //La valeur de touche
{ {
case SDLK_UP: printf("FLECHE DU HAUT\n"); case SDLK_UP: printf("FLECHE DU HAUT\n");
action = 1; action = 1;
break; break;
case SDLK_DOWN: printf("FLECHE DU BAS\n"); case SDLK_DOWN: printf("FLECHE DU BAS\n");
action = 3; action = 3;
break; break;
case SDLK_RIGHT: printf("FLECHE DE DROITE\n"); case SDLK_RIGHT: printf("FLECHE DE DROITE\n");
action = 2; action = 2;
break; break;
case SDLK_LEFT: printf("FLECHE DE GAUCHE\n"); case SDLK_LEFT: printf("FLECHE DE GAUCHE\n");
action = 4; action = 4;
break; break;
case SDLK_SPACE:printf("BARRE D'ESPACE\n"); case SDLK_SPACE:printf("BARRE D'ESPACE\n");
action = 5; action = 5;
} }
break; break;
} }
return action; return action;
} }
/* /*
ActionPlayer(player2,1); //Déplacement vers le haut ActionPlayer(player2,1); //Déplacement vers le haut
ActionPlayer(player2,2); //Déplacement vers la droite ActionPlayer(player2,2); //Déplacement vers la droite
ActionPlayer(player2,3); //Déplacement vers le bas ActionPlayer(player2,3); //Déplacement vers le bas
ActionPlayer(player2,4); //Déplacement vers la gauche ActionPlayer(player2,4); //Déplacement vers la gauche
*/ */
//freeElement(List, 2); // Fonctionne //freeElement(List, 2); // Fonctionne
//freeList(List); // Fonctionne //freeList(List); // Fonctionne
//displayList(List); //displayList(List);
/** Pour la simulation d'un combat, on rentre la lettre A au clavier /** Pour la simulation d'un combat, on rentre la lettre A au clavier
* Le joueur 1 va attaqué le joueur 2 et inversement * Le joueur 1 va attaqué le joueur 2 et inversement
* On affiche le score des joueurs * On affiche le score des joueurs
* *
* */ * */
//List = AttackPlayer(List, 1, 2); //List = AttackPlayer(List, 1, 2);
// SDL_Quit(); // SDL_Quit();
/**Fonction qui crée un joueur /**Fonction qui crée un joueur
* *
* */ * */
PLAYER* createPlayer(int Id) PLAYER* createPlayer(int Id)
{ {
PLAYER* player=NULL; PLAYER* player=NULL;
//Utilisé la fonction de récupération de la taille de l'arène //Utilisé la fonction de récupération de la taille de l'arène
player=(PLAYER*)malloc(sizeof(PLAYER)); player=(PLAYER*)malloc(sizeof(PLAYER));
if(player==NULL) if(player==NULL)
{ {
printf("ERREUR Allocation joueur "); printf("ERREUR Allocation joueur ");
} }
printf("Entrer le nom du joueur\n"); printf("Entrer le nom du joueur\n");
scanf("%s",player->Name); scanf("%s",player->Name);
printf("Nb PV?\n"); printf("Nb PV?\n");
scanf("%d",&player->HealthPoints); scanf("%d",&player->HealthPoints);
player->Id = Id; player->Id = Id;
player->AttacksPoints = 10; player->AttacksPoints = 10;
if(Id == 1) if(Id == 1)
{ {
player->PositionX=0; player->PositionX=0;
player->PositionY=0; player->PositionY=0;
} }
else if(Id ==2) else if(Id ==2)
{ {
player->PositionX=ArenaMAX; player->PositionX=ArenaMAX;
player->PositionY=0; player->PositionY=0;
} }
else if(Id ==3) else if(Id ==3)
{ {
player->PositionX=0; player->PositionX=0;
player->PositionY=ArenaMAX; player->PositionY=ArenaMAX;
} }
else else
{ {
player->PositionX=ArenaMAX; player->PositionX=ArenaMAX;
player->PositionY=ArenaMAX; player->PositionY=ArenaMAX;
} }
player->suiv=NULL; player->suiv=NULL;
return player; return player;
} }
/**Fonction qui ajoute un joueur à la liste /**Fonction qui ajoute un joueur à la liste
* *
* */ * */
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element) PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element)
{ {
if(Head == NULL) if(Head == NULL)
{ {
return Element; return Element;
} }
if(Element->Id < Head->Id) if(Element->Id < Head->Id)
{ {
Element->suiv = Head; Element->suiv = Head;
return Element; return Element;
} }
else else
{ {
if(Element->Id == Head->Id) if(Element->Id == Head->Id)
{ {
printf("Le joueur à l'id %d exite déja dans la liste\n",Element->Id); printf("Le joueur à l'id %d exite déja dans la liste\n",Element->Id);
free(Element); free(Element);
return Head; return Head;
} }
else else
{ {
Head->suiv = insertRightPlaceRecursive(Head->suiv,Element); Head->suiv = insertRightPlaceRecursive(Head->suiv,Element);
return Head; return Head;
} }
} }
} }
void displayList(PLAYER * Head) void displayList(PLAYER * Head)
{ {
if(Head == NULL) if(Head == NULL)
{ {
printf("La liste est vide\n"); printf("La liste est vide\n");
} }
while(Head != NULL) while(Head != NULL)
{ {
printf("****Player %d****\n",Head->Id); printf("****Player %d****\n",Head->Id);
printf("Nom : %s\n",Head->Name); printf("Nom : %s\n",Head->Name);
Head = Head->suiv; Head = Head->suiv;
} }
} }
PLAYER * freeElement(PLAYER *Head, int Id) PLAYER * freeElement(PLAYER *Head, int Id)
{ {
PLAYER * Element; PLAYER * Element;
if(Head == NULL) if(Head == NULL)
{ {
printf("La liste est vide\n"); printf("La liste est vide\n");
} }
if(Id == Head->Id) if(Id == Head->Id)
{ {
Element = Head; Element = Head;
Head = Head->suiv; Head = Head->suiv;
printf("Le joueur %d a été supprimé de la liste\n",Element->Id); printf("Le joueur %d a été supprimé de la liste\n",Element->Id);
free(Element); free(Element);
return Head; return Head;
} }
else else
{ {
Head->suiv = freeElement(Head->suiv,Id); Head->suiv = freeElement(Head->suiv,Id);
return Head; return Head;
} }
} }
PLAYER * freeList(PLAYER *Head) PLAYER * freeList(PLAYER *Head)
{ {
if(Head != NULL) if(Head != NULL)
{ {
freeList(Head->suiv); freeList(Head->suiv);
} }
free(Head); free(Head);
Head=NULL; Head=NULL;
return Head; return Head;
} }
int NumberPlayerAlive(PLAYER *Head) int NumberPlayerAlive(PLAYER *Head)
{ {
int numberAlive=0; int numberAlive=0;
if(Head == NULL) if(Head == NULL)
{ {
printf("La liste est vide\n"); printf("La liste est vide\n");
return -1; return -1;
} }
else else
{ {
do do
{ {
if(Head->HealthPoints > 0) if(Head->HealthPoints > 0)
{ {
numberAlive = numberAlive + 1; numberAlive = numberAlive + 1;
} }
Head=Head->suiv; Head=Head->suiv;
} }
while(Head != NULL); while(Head != NULL);
return numberAlive; return numberAlive;
} }
} }
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer) PLAYER * SearchPlayer(PLAYER *Head, int idPlayer)
{ {
printf("Fonction Recherche\n"); printf("Fonction Recherche\n");
if(Head == NULL) if(Head == NULL)
{ {
printf("La liste est vide\n"); printf("La liste est vide\n");
} }
if(Head->Id == idPlayer) if(Head->Id == idPlayer)
{ {
printf("Trouvé\n"); printf("Trouvé\n");
printf(" Joueur %s\n",Head->Name); printf(" Joueur %s\n",Head->Name);
return Head; return Head;
} }
else else
{ {
Head->suiv = SearchPlayer(Head->suiv,idPlayer); Head->suiv = SearchPlayer(Head->suiv,idPlayer);
return Head->suiv; return Head->suiv;
} }
} }
void AttackPlayer( PLAYER *player1, PLAYER *player2) void AttackPlayer( PLAYER *player1, PLAYER *player2)
{ {
printf("Fonction Attaque\n"); printf("Fonction Attaque\n");
if((player1 != NULL) && (player2 != NULL)) if((player1 != NULL) && (player2 != NULL))
{ {
while((player1->HealthPoints > 0) && (player2->HealthPoints > 0)) while((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
{ {
printf("\n\n** Tour **\n"); printf("\n\n** Tour **\n");
printf("Attaque Joueur %d sur joueur %d \n",player1->Id,player2->Id); printf("Attaque Joueur %d sur joueur %d \n",player1->Id,player2->Id);
player2->HealthPoints = player2->HealthPoints - player1->AttacksPoints; player2->HealthPoints = player2->HealthPoints - player1->AttacksPoints;
printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints); printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints);
printf("Joueur %d : %s PV = %d\n ",player2->Id,player2->Name,player2->HealthPoints); printf("Joueur %d : %s PV = %d\n ",player2->Id,player2->Name,player2->HealthPoints);
if((player1->HealthPoints > 0) && (player2->HealthPoints > 0)) if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
{ {
printf("\nAttaque Joueur %d sur joueur %d\n ",player2->Id,player1->Id); printf("\nAttaque Joueur %d sur joueur %d\n ",player2->Id,player1->Id);
player1->HealthPoints = player1->HealthPoints - player2->AttacksPoints; player1->HealthPoints = player1->HealthPoints - player2->AttacksPoints;
printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints); printf("Joueur %d : %s PV = %d\n ",player1->Id,player1->Name,player1->HealthPoints);
printf("Joueur %d : %s PV = %d \n",player2->Id,player2->Name,player2->HealthPoints); printf("Joueur %d : %s PV = %d \n",player2->Id,player2->Name,player2->HealthPoints);
} }
} }
if(player1->HealthPoints > player2->HealthPoints) if(player1->HealthPoints > player2->HealthPoints)
{ {
printf("Combat finie \n Le joueur 1 a gagné le combat\n"); printf("Combat finie \n Le joueur 1 a gagné le combat\n");
} }
else if(player1->HealthPoints < player2->HealthPoints) else if(player1->HealthPoints < player2->HealthPoints)
{ {
printf("Combat finie \n Le joueur 2 a gagné le combat\n"); printf("Combat finie \n Le joueur 2 a gagné le combat\n");
} }
else else
{ {
printf("Combat finie \n Les 2 joueurs sont morts"); printf("Combat finie \n Les 2 joueurs sont morts");
} }
} }
} }
void ActionPlayer(PLAYER * player, int action) void ActionPlayer(PLAYER * player, int action)
{ {
/* action = 1 --> Déplacement d'1 carreau vers le haut /* action = 1 --> Déplacement d'1 carreau vers le haut
* action = 2 --> Déplacement d'1 carreau vers la droite * action = 2 --> Déplacement d'1 carreau vers la droite
* action = 3 --> Déplacement d'1 carreau vers le bas * action = 3 --> Déplacement d'1 carreau vers le bas
* action = 4 --> Déplacement d'1 carreau vers la gauche * action = 4 --> Déplacement d'1 carreau vers la gauche
* *
* */ * */
if(player != NULL) if(player != NULL)
{ {
// récupère la position du personnage. La position de l'instance sur l'arène est récupérer par une fonction // récupère la position du personnage. La position de l'instance sur l'arène est récupérer par une fonction
int positionX = player->PositionX; int positionX = player->PositionX;
int positionY = player->PositionY; int positionY = player->PositionY;
printf("\n**** Player %s ****",player->Name); printf("\n**** Player %s ****",player->Name);
if(action == 1) if(action == 1)
{ {
printf("On veut aller vers le haut\n"); printf("On veut aller vers le haut\n");
if(positionY-1 >= 0) if(positionY-1 >= 0)
{ {
player->PositionY = positionY-1; player->PositionY = positionY-1;
printf("Déplacement de 1 vers le haut\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY); printf("Déplacement de 1 vers le haut\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
} }
else else
{ {
printf("Impossible d'aller vers le haut\n"); printf("Impossible d'aller vers le haut\n");
} }
} }
else if(action == 2) else if(action == 2)
{ {
printf("On veut aller vers la droite\n"); printf("On veut aller vers la droite\n");
if(positionX + 1 <= ArenaMAX) if(positionX + 1 <= ArenaMAX)
{ {
player->PositionX = positionX + 1; player->PositionX = positionX + 1;
printf("Déplacement de 1 vers la droite\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY); printf("Déplacement de 1 vers la droite\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
} }
else else
{ {
printf("Impossible d'aller vers la droite\n"); printf("Impossible d'aller vers la droite\n");
} }
} }
else if(action == 3) else if(action == 3)
{ {
printf("On veut aller vers le bas\n"); printf("On veut aller vers le bas\n");
if(positionY + 1 <= ArenaMAX) if(positionY + 1 <= ArenaMAX)
{ {
player->PositionY = positionY + 1; player->PositionY = positionY + 1;
printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY); printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
} }
else else
{ {
printf("Impossible d'aller vers le bas\n"); printf("Impossible d'aller vers le bas\n");
} }
} }
else if(action == 4) else if(action == 4)
{ {
printf("On veut aller vers la gauche\n"); printf("On veut aller vers la gauche\n");
if(positionX - 1 >= 0) if(positionX - 1 >= 0)
{ {
player->PositionX = positionX - 1; player->PositionX = positionX - 1;
printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY); printf("Déplacement de 1 vers le bas\n La nouvelle position est de X: %i et Y: %i \n",player->PositionX,player->PositionY);
} }
else else
{ {
printf("Impossible d'aller vers la gauche\n"); printf("Impossible d'aller vers la gauche\n");
} }
} }
else else
{ {
printf("Autre action\n"); printf("Autre action\n");
} }
} }
else else
{ {
printf("Echec, le joueur est NULL\n"); printf("Echec, le joueur est NULL\n");
} }
} }

View File

@ -1,49 +1,49 @@
/* /*
* playerInterface.h * playerInterface.h
* *
* Created on: 17 juin 2018 * Created on: 17 juin 2018
* Author: isen * Author: isen
*/ */
#ifndef PLAYERINTERFACE_H_ #ifndef PLAYERINTERFACE_H_
#define PLAYERINTERFACE_H_ #define PLAYERINTERFACE_H_
/** Structure d'un joueur (IA ou utilisateur) /** Structure d'un joueur (IA ou utilisateur)
* *
* */ * */
typedef struct Player typedef struct Player
{ {
int Id; int Id;
char Name[35]; char Name[35];
char Race[20]; char Race[20];
int HealthPoints; int HealthPoints;
int AttacksPoints; int AttacksPoints;
int DefensePoints; int DefensePoints;
int PositionX; int PositionX;
int PositionY; int PositionY;
//char Weapons[Max_Weapons]; //char Weapons[Max_Weapons];
//int Coins; //int Coins;
struct Player * suiv; struct Player * suiv;
}PLAYER; }PLAYER;
//Prototypes //Prototypes
PLAYER* createPlayer(int Id); PLAYER* createPlayer(int Id);
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element); PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element);
void displayList(PLAYER * Head); void displayList(PLAYER * Head);
PLAYER * freeElement(PLAYER *Head, int Id); PLAYER * freeElement(PLAYER *Head, int Id);
PLAYER * freeList(PLAYER *Head); PLAYER * freeList(PLAYER *Head);
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer); PLAYER * SearchPlayer(PLAYER *Head, int idPlayer);
void AttackPlayer( PLAYER *player1, PLAYER *player2); void AttackPlayer( PLAYER *player1, PLAYER *player2);
void ActionPlayer(PLAYER * player, int action); void ActionPlayer(PLAYER * player, int action);
int NumberPlayerAlive(PLAYER *Head); int NumberPlayerAlive(PLAYER *Head);
int getEvent(void); int getEvent(void);
#endif /* PLAYERINTERFACE_H_ */ #endif /* PLAYERINTERFACE_H_ */