Added tiles and sprites, creating arenaGUI
198
IAEngine.c
@ -1,99 +1,99 @@
|
||||
/*
|
||||
* IAEngine.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*
|
||||
* Fonction qui va définir le comportement joueur(s) "ordinateur"
|
||||
*/
|
||||
|
||||
#include "playerInterface.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
int IAEngine(PLAYER * player1, PLAYER * player2)
|
||||
{
|
||||
char Race[20];
|
||||
|
||||
//Player 1 est le joueur, player 2 le bot
|
||||
if((player1 != NULL) & (player2 !=NULL))
|
||||
{
|
||||
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
||||
int Player1PositionX = player1->PositionX;
|
||||
int Player1PositionY = player1->PositionY;
|
||||
|
||||
int Player2PositionX = player2->PositionX;
|
||||
int Player2PositionY = player2->PositionY;
|
||||
int action;
|
||||
|
||||
action = FindShortestPath(Player1PositionX,Player1PositionY,Player2PositionX,Player2PositionY);
|
||||
|
||||
printf("Tour de l'IA\n");
|
||||
if(action == 5)
|
||||
{
|
||||
AttackPlayer(player1,player2);
|
||||
}
|
||||
else if ((action >= 1) && (action <= 4))
|
||||
{
|
||||
ActionPlayer(player2,action);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY)
|
||||
{
|
||||
int differenceX = abs(Player1PositionX - Player2PositionX);
|
||||
int differenceY = abs(Player1PositionY - Player2PositionY);
|
||||
|
||||
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
|
||||
if((abs(Player1PositionX - (Player2PositionX - 1)) == 1) ||
|
||||
(abs(Player1PositionX - (Player2PositionX + 1)) == 1) ||
|
||||
(abs(Player1PositionX - (Player2PositionY - 1)) == 1) ||
|
||||
(abs(Player1PositionX - (Player2PositionY + 1)) == 1))
|
||||
{
|
||||
printf("Les 2 joueur sont à coté\n");
|
||||
printf("Le joueur 2 va combattre\n");
|
||||
action = 5;
|
||||
}
|
||||
|
||||
if(differenceX > abs(Player1PositionX - (Player2PositionX - 1)))
|
||||
{
|
||||
printf("Chemin plus court sur X\n");
|
||||
printf("Le joueur 2 va vers la gauche\n");
|
||||
action = 4;
|
||||
}
|
||||
else if(differenceX > abs(Player1PositionX - (Player2PositionX + 1)))
|
||||
{
|
||||
printf("Chemin plus court sur X\n");
|
||||
printf("Le joueur 2 va vers la droite\n");
|
||||
action = 2;
|
||||
}
|
||||
else if(differenceY > abs(Player1PositionY - (Player2PositionY + 1)))
|
||||
{
|
||||
printf("Chemin plus court sur Y\n");
|
||||
printf("Le joueur 2 va vers le bas\n");
|
||||
action = 3;
|
||||
}
|
||||
else if(differenceY > abs(Player1PositionY - (Player2PositionY - 1)))
|
||||
{
|
||||
printf("Chemin plus court sur Y\n");
|
||||
printf("Le joueur 2 va vers le haut\n");
|
||||
action = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Chemin plus long\n");
|
||||
action = 0;
|
||||
}
|
||||
return action;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* IAEngine.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*
|
||||
* Fonction qui va définir le comportement joueur(s) "ordinateur"
|
||||
*/
|
||||
|
||||
#include "playerInterface.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
int IAEngine(PLAYER * player1, PLAYER * player2)
|
||||
{
|
||||
char Race[20];
|
||||
|
||||
//Player 1 est le joueur, player 2 le bot
|
||||
if((player1 != NULL) & (player2 !=NULL))
|
||||
{
|
||||
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
|
||||
int Player1PositionX = player1->PositionX;
|
||||
int Player1PositionY = player1->PositionY;
|
||||
|
||||
int Player2PositionX = player2->PositionX;
|
||||
int Player2PositionY = player2->PositionY;
|
||||
int action;
|
||||
|
||||
action = FindShortestPath(Player1PositionX,Player1PositionY,Player2PositionX,Player2PositionY);
|
||||
|
||||
printf("Tour de l'IA\n");
|
||||
if(action == 5)
|
||||
{
|
||||
AttackPlayer(player1,player2);
|
||||
}
|
||||
else if ((action >= 1) && (action <= 4))
|
||||
{
|
||||
ActionPlayer(player2,action);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY)
|
||||
{
|
||||
int differenceX = abs(Player1PositionX - Player2PositionX);
|
||||
int differenceY = abs(Player1PositionY - Player2PositionY);
|
||||
|
||||
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
|
||||
if((abs(Player1PositionX - (Player2PositionX - 1)) == 1) ||
|
||||
(abs(Player1PositionX - (Player2PositionX + 1)) == 1) ||
|
||||
(abs(Player1PositionX - (Player2PositionY - 1)) == 1) ||
|
||||
(abs(Player1PositionX - (Player2PositionY + 1)) == 1))
|
||||
{
|
||||
printf("Les 2 joueur sont à coté\n");
|
||||
printf("Le joueur 2 va combattre\n");
|
||||
action = 5;
|
||||
}
|
||||
|
||||
if(differenceX > abs(Player1PositionX - (Player2PositionX - 1)))
|
||||
{
|
||||
printf("Chemin plus court sur X\n");
|
||||
printf("Le joueur 2 va vers la gauche\n");
|
||||
action = 4;
|
||||
}
|
||||
else if(differenceX > abs(Player1PositionX - (Player2PositionX + 1)))
|
||||
{
|
||||
printf("Chemin plus court sur X\n");
|
||||
printf("Le joueur 2 va vers la droite\n");
|
||||
action = 2;
|
||||
}
|
||||
else if(differenceY > abs(Player1PositionY - (Player2PositionY + 1)))
|
||||
{
|
||||
printf("Chemin plus court sur Y\n");
|
||||
printf("Le joueur 2 va vers le bas\n");
|
||||
action = 3;
|
||||
}
|
||||
else if(differenceY > abs(Player1PositionY - (Player2PositionY - 1)))
|
||||
{
|
||||
printf("Chemin plus court sur Y\n");
|
||||
printf("Le joueur 2 va vers le haut\n");
|
||||
action = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Chemin plus long\n");
|
||||
action = 0;
|
||||
}
|
||||
return action;
|
||||
|
||||
}
|
||||
|
||||
|
28
IAEngine.h
@ -1,14 +1,14 @@
|
||||
/*
|
||||
* IAEngine.h
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#ifndef IAENGINE_H_
|
||||
#define IAENGINE_H_
|
||||
|
||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
|
||||
int IAEngine(PLAYER * player1, PLAYER * player2);
|
||||
|
||||
#endif /* IAENGINE_H_ */
|
||||
/*
|
||||
* IAEngine.h
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#ifndef IAENGINE_H_
|
||||
#define IAENGINE_H_
|
||||
|
||||
int FindShortestPath(int Player1PositionX, int Player1PositionY, int Player2PositionX, int Player2PositionY);
|
||||
int IAEngine(PLAYER * player1, PLAYER * player2);
|
||||
|
||||
#endif /* IAENGINE_H_ */
|
||||
|
317
arenaEngine.c
@ -1,150 +1,167 @@
|
||||
#include "arenaEngine.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "fileHandler.h"
|
||||
#include "logHelper.h"
|
||||
|
||||
|
||||
/*
|
||||
* Arena generate functions
|
||||
*/
|
||||
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
if (prevHTile == NULL) {
|
||||
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->playerOnTile = NULL;
|
||||
tile_h->nextRow = NULL;
|
||||
tile_h->nextColumn = NULL;
|
||||
} else if (prevHTile != NULL) {
|
||||
tile_h = calloc(1,sizeof(ARENA_H_TILE));
|
||||
prevHTile->nextRow = tile_h;
|
||||
tile_h->type_id = 0;
|
||||
tile_h->playerOnTile = NULL;
|
||||
tile_h->nextRow = NULL;
|
||||
tile_h->nextColumn = NULL;
|
||||
}
|
||||
|
||||
return tile_h;
|
||||
}
|
||||
|
||||
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
||||
ARENA_W_TILE* tile_w = NULL;
|
||||
|
||||
if (prevHTile != NULL && prevWTile == NULL) {
|
||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||
prevHTile->nextColumn = tile_w;
|
||||
tile_w->type_id = 0;
|
||||
tile_w->playerOnTile = NULL;
|
||||
tile_w->nextColumn = NULL;
|
||||
|
||||
return tile_w;
|
||||
} else if (prevHTile == NULL && prevWTile != NULL) {
|
||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||
prevWTile->nextColumn = tile_w;
|
||||
tile_w->type_id = 0;
|
||||
tile_w->playerOnTile = NULL;
|
||||
tile_w->nextColumn = NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ARENA_H_TILE* genNewArena(int size_h, int size_w) {
|
||||
ARENA_H_TILE* arenaOrigin = NULL;
|
||||
ARENA_H_TILE* TmpCursor_h = NULL;
|
||||
ARENA_W_TILE* TmpCursor_w = NULL;
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<size_h;i++){
|
||||
if (i==0) {
|
||||
arenaOrigin = createHTile(NULL);
|
||||
TmpCursor_h = arenaOrigin;
|
||||
} else {
|
||||
TmpCursor_h = createHTile(TmpCursor_h);
|
||||
}
|
||||
|
||||
for(j=0;j<size_w;j++){
|
||||
if (j==0) {
|
||||
TmpCursor_w = createWTile(TmpCursor_h, NULL);
|
||||
} else {
|
||||
createWTile(NULL, TmpCursor_w);
|
||||
}
|
||||
|
||||
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
|
||||
}
|
||||
}
|
||||
|
||||
return arenaOrigin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Arena delete functions
|
||||
*/
|
||||
void deleteWTile(ARENA_W_TILE* WTile) {
|
||||
if (WTile->nextColumn != NULL) {
|
||||
deleteWTile(WTile->nextColumn);
|
||||
}
|
||||
|
||||
free(WTile);
|
||||
}
|
||||
|
||||
void deleteHTile(ARENA_H_TILE* HTile) {
|
||||
if (HTile->nextRow != NULL) {
|
||||
deleteHTile(HTile->nextRow);
|
||||
}
|
||||
|
||||
deleteWTile(HTile->nextColumn);
|
||||
free(HTile);
|
||||
}
|
||||
|
||||
void deleteArena(ARENA_H_TILE* arena) {
|
||||
deleteHTile(arena);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Arena status functions
|
||||
*/
|
||||
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;
|
||||
|
||||
tile_h = arena;
|
||||
if (coord_x != 0) {
|
||||
for (i=0;i<coord_x;i++) {
|
||||
tile_h = arena->nextRow;
|
||||
}
|
||||
}
|
||||
|
||||
type_id = tile_h->type_id;
|
||||
} else {
|
||||
ARENA_W_TILE* tile_w = NULL;
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
tile_h = arena;
|
||||
if (coord_x != 0) {
|
||||
for (i=0;i<coord_x;i++) {
|
||||
tile_h = tile_h->nextRow;
|
||||
}
|
||||
}
|
||||
|
||||
tile_w = tile_h->nextColumn;
|
||||
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;
|
||||
}
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "fileHandler.h"
|
||||
#include "logHelper.h"
|
||||
#include "main.h"
|
||||
#include "arenaEngine.h"
|
||||
|
||||
|
||||
/*
|
||||
* Arena generate functions
|
||||
*/
|
||||
TILE* createTileList(void) {
|
||||
TILE* origin = NULL;
|
||||
|
||||
return origin;
|
||||
}
|
||||
|
||||
ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) {
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
if (prevHTile == NULL) {
|
||||
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->playerOnTile = NULL;
|
||||
tile_h->nextRow = NULL;
|
||||
tile_h->nextColumn = NULL;
|
||||
} else if (prevHTile != NULL) {
|
||||
tile_h = calloc(1,sizeof(ARENA_H_TILE));
|
||||
prevHTile->nextRow = tile_h;
|
||||
tile_h->type_id = 0;
|
||||
//tile_h->playerOnTile = NULL;
|
||||
tile_h->nextRow = NULL;
|
||||
tile_h->nextColumn = NULL;
|
||||
}
|
||||
|
||||
return tile_h;
|
||||
}
|
||||
|
||||
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
|
||||
ARENA_W_TILE* tile_w = NULL;
|
||||
|
||||
if (prevHTile != NULL && prevWTile == NULL) {
|
||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||
prevHTile->nextColumn = tile_w;
|
||||
tile_w->type_id = 0;
|
||||
//tile_w->playerOnTile = NULL;
|
||||
tile_w->nextColumn = NULL;
|
||||
|
||||
return tile_w;
|
||||
} else if (prevHTile == NULL && prevWTile != NULL) {
|
||||
tile_w = calloc(1,sizeof(ARENA_W_TILE));
|
||||
prevWTile->nextColumn = tile_w;
|
||||
tile_w->type_id = 0;
|
||||
//tile_w->playerOnTile = NULL;
|
||||
tile_w->nextColumn = NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ARENA_H_TILE* genNewArena(int size_h, int size_w) {
|
||||
ARENA_H_TILE* arenaOrigin = NULL;
|
||||
ARENA_H_TILE* TmpCursor_h = NULL;
|
||||
ARENA_W_TILE* TmpCursor_w = NULL;
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<size_h;i++){
|
||||
if (i==0) {
|
||||
arenaOrigin = createHTile(NULL);
|
||||
TmpCursor_h = arenaOrigin;
|
||||
} else {
|
||||
TmpCursor_h = createHTile(TmpCursor_h);
|
||||
}
|
||||
|
||||
for(j=0;j<size_w;j++){
|
||||
if (j==0) {
|
||||
TmpCursor_w = createWTile(TmpCursor_h, NULL);
|
||||
} else {
|
||||
createWTile(NULL, TmpCursor_w);
|
||||
}
|
||||
|
||||
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
|
||||
}
|
||||
}
|
||||
|
||||
return arenaOrigin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Arena delete functions
|
||||
*/
|
||||
void deleteWTile(ARENA_W_TILE* WTile) {
|
||||
if (WTile->nextColumn != NULL) {
|
||||
deleteWTile(WTile->nextColumn);
|
||||
}
|
||||
|
||||
free(WTile);
|
||||
}
|
||||
|
||||
void deleteHTile(ARENA_H_TILE* HTile) {
|
||||
if (HTile->nextRow != NULL) {
|
||||
deleteHTile(HTile->nextRow);
|
||||
}
|
||||
|
||||
deleteWTile(HTile->nextColumn);
|
||||
free(HTile);
|
||||
}
|
||||
|
||||
void deleteArena(ARENA_H_TILE* arena) {
|
||||
deleteHTile(arena);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Arena status functions
|
||||
*/
|
||||
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) {
|
||||
int type_id = -1;
|
||||
int i;
|
||||
|
||||
if (coord_x > A_WIDTH || coord_y > A_HEIGHT) return -1;
|
||||
|
||||
if (coord_y == 0) {
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
tile_h = arena;
|
||||
if (coord_x != 0) {
|
||||
for (i=0;i<coord_x;i++) {
|
||||
tile_h = arena->nextRow;
|
||||
}
|
||||
}
|
||||
|
||||
type_id = tile_h->type_id;
|
||||
} else {
|
||||
ARENA_W_TILE* tile_w = NULL;
|
||||
ARENA_H_TILE* tile_h = NULL;
|
||||
|
||||
tile_h = arena;
|
||||
if (coord_x != 0) {
|
||||
for (i=0;i<coord_x;i++) {
|
||||
tile_h = tile_h->nextRow;
|
||||
}
|
||||
}
|
||||
|
||||
tile_w = tile_h->nextColumn;
|
||||
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;
|
||||
}
|
||||
|
@ -1,46 +1,49 @@
|
||||
#include "playerInterface.h"
|
||||
|
||||
#ifndef ARENAENGINE_H_
|
||||
#define ARENAENGINE_H_
|
||||
|
||||
|
||||
|
||||
/*
|
||||
typedef struct items{
|
||||
int type_id;
|
||||
//texture?
|
||||
int isFlat;
|
||||
int minedId;
|
||||
struct items *nextItem;
|
||||
}ITEMS;
|
||||
*/
|
||||
|
||||
typedef struct tileType{
|
||||
int type_id;
|
||||
//texture?
|
||||
int isGround;
|
||||
int canBeMined;
|
||||
}TILE;
|
||||
|
||||
typedef struct arena_h_tile{ //Rows chained list
|
||||
int type_id;
|
||||
PLAYER* playerOnTile;
|
||||
struct arena_h_tile *nextRow;
|
||||
struct arena_w_tile *nextColumn;
|
||||
}ARENA_H_TILE;
|
||||
|
||||
typedef struct arena_w_tile{ //Columns chained list
|
||||
int type_id;
|
||||
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);
|
||||
|
||||
//Status functions
|
||||
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y);
|
||||
|
||||
#endif
|
||||
#include "playerInterface.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifndef ARENAENGINE_H_
|
||||
#define ARENAENGINE_H_
|
||||
|
||||
|
||||
|
||||
/*
|
||||
typedef struct items{
|
||||
int type_id;
|
||||
//texture?
|
||||
int isFlat;
|
||||
int minedId;
|
||||
struct items *nextItem;
|
||||
}ITEMS;
|
||||
*/
|
||||
|
||||
typedef struct tileType{
|
||||
int type_id;
|
||||
SDL_Surface texture;
|
||||
int isGround;
|
||||
int canBeMined;
|
||||
struct tileType *nextTile;
|
||||
}TILE;
|
||||
|
||||
typedef struct arena_h_tile{ //Rows chained list
|
||||
int type_id;
|
||||
//PLAYER* playerOnTile;
|
||||
struct arena_h_tile *nextRow;
|
||||
struct arena_w_tile *nextColumn;
|
||||
}ARENA_H_TILE;
|
||||
|
||||
typedef struct arena_w_tile{ //Columns chained list
|
||||
int type_id;
|
||||
//PLAYER* playerOnTile;
|
||||
struct arena_w_tile *nextColumn;
|
||||
}ARENA_W_TILE;
|
||||
|
||||
|
||||
//Generation functions
|
||||
TILE* createTileList(void);
|
||||
ARENA_H_TILE* genNewArena(int size_h, int size_w);
|
||||
void deleteArena(ARENA_H_TILE* arena);
|
||||
|
||||
//Status functions
|
||||
int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y);
|
||||
|
||||
#endif
|
||||
|
26
arenaGUI.c
@ -1,3 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "SDL2/SDL.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
arenaGUI.h
@ -1,6 +1,9 @@
|
||||
#ifndef ARENAGUI_H_
|
||||
#define ARENAGUI_H_
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#include "main.h"
|
||||
#include "arenaEngine.h"
|
||||
|
||||
#ifndef ARENAGUI_H_
|
||||
#define ARENAGUI_H_
|
||||
|
||||
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
After Width: | Height: | Size: 1.1 KiB |
BIN
data/sprite_ia_1.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
data/sprite_player_1.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
data/tile_gold.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
data/tile_grass.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
data/tile_rock.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
data/tile_tree.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
data/tile_water.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
@ -1,15 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int resOpen(char* filename, FILE* f) {
|
||||
char fLoc[128];
|
||||
|
||||
strcpy(fLoc, "resources/");
|
||||
strcat(fLoc, filename);
|
||||
f = fopen(fLoc, "rb");
|
||||
|
||||
if (f != NULL) return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int resOpen(char* filename, FILE* f) {
|
||||
char fLoc[128];
|
||||
|
||||
strcpy(fLoc, "resources/");
|
||||
strcat(fLoc, filename);
|
||||
f = fopen(fLoc, "rb");
|
||||
|
||||
if (f != NULL) return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef FILEHANDLER_H_
|
||||
#define FILEHANDLER_H_
|
||||
|
||||
int resOpen(char* filename);
|
||||
|
||||
#endif
|
||||
#ifndef FILEHANDLER_H_
|
||||
#define FILEHANDLER_H_
|
||||
|
||||
int resOpen(char* filename);
|
||||
|
||||
#endif
|
||||
|
152
logHelper.c
@ -1,76 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "logHelper.h"
|
||||
|
||||
FILE *log_file=NULL;
|
||||
|
||||
int initialise_logger(){
|
||||
time_t raw_time;
|
||||
struct tm *pdh;
|
||||
time(&raw_time);
|
||||
pdh = localtime(&raw_time);
|
||||
char name[32];
|
||||
sprintf(name, "%04d-%02d-%02d.log", pdh->tm_year+1900, pdh->tm_mon+1, pdh->tm_mday);
|
||||
log_file=fopen(name, "a");
|
||||
|
||||
if(log_file==NULL) //fichier innexistant
|
||||
{
|
||||
log_file=fopen(name,"w+");
|
||||
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stop_logger() {fclose(log_file);}
|
||||
|
||||
void addLogInfo(char *mess){
|
||||
time_t now;
|
||||
struct tm* tm_info;
|
||||
char buffer[12];
|
||||
|
||||
initialise_logger();
|
||||
|
||||
time(&now);
|
||||
tm_info = localtime(&now);
|
||||
strftime(buffer, 12, "%H:%M:%S", tm_info);
|
||||
fprintf(log_file,"[INFO][%s] %s\n", buffer, mess);
|
||||
|
||||
stop_logger();
|
||||
}
|
||||
|
||||
void addLogWarn(char *mess){
|
||||
time_t now;
|
||||
struct tm* tm_info;
|
||||
char buffer[12];
|
||||
|
||||
initialise_logger();
|
||||
|
||||
time(&now);
|
||||
tm_info = localtime(&now);
|
||||
strftime(buffer, 12, "%H:%M:%S", tm_info);
|
||||
fprintf(log_file,"[WARN][%s] %s\n", buffer, mess);
|
||||
|
||||
stop_logger();
|
||||
}
|
||||
|
||||
void addLogCritical(char *mess){
|
||||
time_t now;
|
||||
struct tm* tm_info;
|
||||
char buffer[12];
|
||||
|
||||
initialise_logger();
|
||||
|
||||
time(&now);
|
||||
tm_info = localtime(&now);
|
||||
strftime(buffer, 12, "%H:%M:%S", tm_info);
|
||||
fprintf(log_file,"[CRITICAL][%s] %s\n", buffer, mess);
|
||||
|
||||
stop_logger();
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "logHelper.h"
|
||||
|
||||
FILE *log_file=NULL;
|
||||
|
||||
int initialise_logger(){
|
||||
time_t raw_time;
|
||||
struct tm *pdh;
|
||||
time(&raw_time);
|
||||
pdh = localtime(&raw_time);
|
||||
char name[32];
|
||||
sprintf(name, "%04d-%02d-%02d.log", pdh->tm_year+1900, pdh->tm_mon+1, pdh->tm_mday);
|
||||
log_file=fopen(name, "a");
|
||||
|
||||
if(log_file==NULL) //fichier innexistant
|
||||
{
|
||||
log_file=fopen(name,"w+");
|
||||
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stop_logger() {fclose(log_file);}
|
||||
|
||||
void addLogInfo(char *mess){
|
||||
time_t now;
|
||||
struct tm* tm_info;
|
||||
char buffer[12];
|
||||
|
||||
initialise_logger();
|
||||
|
||||
time(&now);
|
||||
tm_info = localtime(&now);
|
||||
strftime(buffer, 12, "%H:%M:%S", tm_info);
|
||||
fprintf(log_file,"[INFO][%s] %s\n", buffer, mess);
|
||||
|
||||
stop_logger();
|
||||
}
|
||||
|
||||
void addLogWarn(char *mess){
|
||||
time_t now;
|
||||
struct tm* tm_info;
|
||||
char buffer[12];
|
||||
|
||||
initialise_logger();
|
||||
|
||||
time(&now);
|
||||
tm_info = localtime(&now);
|
||||
strftime(buffer, 12, "%H:%M:%S", tm_info);
|
||||
fprintf(log_file,"[WARN][%s] %s\n", buffer, mess);
|
||||
|
||||
stop_logger();
|
||||
}
|
||||
|
||||
void addLogCritical(char *mess){
|
||||
time_t now;
|
||||
struct tm* tm_info;
|
||||
char buffer[12];
|
||||
|
||||
initialise_logger();
|
||||
|
||||
time(&now);
|
||||
tm_info = localtime(&now);
|
||||
strftime(buffer, 12, "%H:%M:%S", tm_info);
|
||||
fprintf(log_file,"[CRITICAL][%s] %s\n", buffer, mess);
|
||||
|
||||
stop_logger();
|
||||
}
|
||||
|
22
logHelper.h
@ -1,11 +1,11 @@
|
||||
#ifndef LOGGER_H_
|
||||
#define LOGGER_H_
|
||||
|
||||
int initialise_logger(); //Prépare le logger à écrire dans les fichiers de logs
|
||||
void stop_logger();
|
||||
|
||||
void addLogInfo(char *mess); //Ajoute une entrée dans le fichier de log de type INFO
|
||||
void addLogWarn(char *mess);
|
||||
void addLogCritical(char *mess); //Ajoute une entrée dans le fichier de log de type CRITICAL
|
||||
|
||||
#endif
|
||||
#ifndef LOGGER_H_
|
||||
#define LOGGER_H_
|
||||
|
||||
int initialise_logger(); //Prépare le logger à écrire dans les fichiers de logs
|
||||
void stop_logger();
|
||||
|
||||
void addLogInfo(char *mess); //Ajoute une entrée dans le fichier de log de type INFO
|
||||
void addLogWarn(char *mess);
|
||||
void addLogCritical(char *mess); //Ajoute une entrée dans le fichier de log de type CRITICAL
|
||||
|
||||
#endif
|
||||
|
136
main.c
@ -1,60 +1,76 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
//#include "IAEngine.h"
|
||||
#include "playerInterface.h"
|
||||
#include "SDL2/SDL.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "logHelper.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_thread.h>
|
||||
#include <SDL2/SDL_mutex.h>
|
||||
#include "arenaEngine.h"
|
||||
|
||||
#define A_HEIGHT 100
|
||||
#define A_WIDTH 100
|
||||
|
||||
void initDisplayLib() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
addLogCritical("Init SDL libs failed !");
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void initResources() {
|
||||
//resOpen();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ARENA_H_TILE* arena = NULL;
|
||||
|
||||
// Création de la fenêtre
|
||||
SDL_Window* pWindow = NULL;
|
||||
pWindow = SDL_CreateWindow("Arena Survival Tournament",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN);
|
||||
|
||||
addLogInfo("Starting game...");
|
||||
initDisplayLib();
|
||||
initResources();
|
||||
|
||||
addLogInfo("Creating new arena...");
|
||||
arena = genNewArena(A_HEIGHT, A_WIDTH);
|
||||
if (arena == NULL) {
|
||||
addLogCritical("Error with arena generator !");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
addLogInfo("Successfully created arena.");
|
||||
|
||||
deleteArena(arena);
|
||||
addLogInfo("Cleared arena.");
|
||||
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#include "main.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "logHelper.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
//#include <SDL2/SDL_thread.h>
|
||||
//#include <SDL2/SDL_mutex.h>
|
||||
#include "arenaEngine.h"
|
||||
#include "arenaGUI.h"
|
||||
//#include "IAEngine.h"
|
||||
#include "playerInterface.h"
|
||||
|
||||
|
||||
void initDisplayLib() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
addLogCritical("Init SDL libs failed !");
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
addLogInfo("Starting game...");
|
||||
addLogInfo("Try init SDL libs...");
|
||||
initDisplayLib();
|
||||
|
||||
addLogInfo("Load ressources in memory...");
|
||||
SDL_Surface *tile_grass = NULL, *tile_rock = NULL, *tile_tree = NULL, *tile_water = NULL, *sprite_player_act = NULL, *sprite_ia_act = NULL;
|
||||
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");
|
||||
tile_rock = IMG_Load("data/tile_rock.png");
|
||||
tile_tree = IMG_Load("data/tile_tree.png");
|
||||
tile_water = IMG_Load("data/tile_water.png");
|
||||
|
||||
sprite_player[DOWN] = IMG_Load("data/sprite_player_1.png");
|
||||
//sprite_player[UP] = IMG_Load("data/sprite_player_2.png");
|
||||
//sprite_player[LEFT] = IMG_Load("data/sprite_player_3.png");
|
||||
//sprite_player[RIGHT] = IMG_Load("data/sprite_player_4.png");
|
||||
|
||||
sprite_ia[DOWN] = IMG_Load("data/sprite_ia_1.png");
|
||||
//sprite_ia[UP] = IMG_Load("data/sprite_ia_2.png");
|
||||
//sprite_ia[LEFT] = IMG_Load("data/sprite_ia_3.png");
|
||||
//sprite_ia[RIGHT] = IMG_Load("data/sprite_ia_4.png");
|
||||
|
||||
addLogInfo("Create SDL windows instance...");
|
||||
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("Creating new arena...");
|
||||
ARENA_H_TILE* arena = NULL;
|
||||
arena = genNewArena(A_HEIGHT, A_WIDTH);
|
||||
if (arena == NULL) {
|
||||
addLogCritical("Error with arena generator !");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
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
@ -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
|
38
menuGUI.c
@ -1,19 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int createGameMenuWindows() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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);
|
||||
SDL_Delay(5000);
|
||||
SDL_DestroyWindow(main_test);
|
||||
|
||||
SDL_Quit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int createGameMenuWindows() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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);
|
||||
SDL_Delay(5000);
|
||||
SDL_DestroyWindow(main_test);
|
||||
|
||||
SDL_Quit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
12
menuGUI.h
@ -1,6 +1,6 @@
|
||||
#ifndef MENUGUI_H_
|
||||
#define MENUGUI_H_
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef MENUGUI_H_
|
||||
#define MENUGUI_H_
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,468 +1,468 @@
|
||||
/*
|
||||
* playerInterface.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#include "playerInterface.h"
|
||||
|
||||
#include "SDL2/SDL.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define ArenaMAX 100
|
||||
|
||||
int PlayerInterface(void)
|
||||
{
|
||||
|
||||
PLAYER* List=NULL;
|
||||
PLAYER* Element=NULL;
|
||||
int id=0;
|
||||
int numberAlive;
|
||||
|
||||
PLAYER* player1=NULL;
|
||||
PLAYER* player2=NULL;
|
||||
|
||||
while(id<2)
|
||||
{
|
||||
id = id + 1;
|
||||
Element = createPlayer(id);
|
||||
List = insertRightPlaceRecursive(List,Element);
|
||||
}
|
||||
|
||||
displayList(List);
|
||||
|
||||
player1 = SearchPlayer(List, 1);
|
||||
player2 = SearchPlayer(List, 2);
|
||||
|
||||
printf("Nom player 1 : %s\n",player1->Name);
|
||||
printf("Nom player 2 : %s\n",player2->Name);
|
||||
|
||||
numberAlive = NumberPlayerAlive(List);
|
||||
printf("Nombre de joueur en vie : %i",numberAlive);
|
||||
|
||||
|
||||
int action;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
action=getEvent();
|
||||
|
||||
if(action == 1)
|
||||
{
|
||||
ActionPlayer(player1,1); //Déplacement vers le haut
|
||||
}
|
||||
else if(action == 2)
|
||||
{
|
||||
ActionPlayer(player1,2); //Déplacement vers la droite
|
||||
}
|
||||
else if(action == 3)
|
||||
{
|
||||
ActionPlayer(player1,3); //Déplacement vers le bas
|
||||
}
|
||||
else if(action == 4)
|
||||
{
|
||||
ActionPlayer(player1,4); //Déplacement vers la gauche
|
||||
}
|
||||
else if(action == 5)
|
||||
{
|
||||
//Regarder le perso en face, le plus près
|
||||
AttackPlayer(player1,player2); //Voir quel player on choisit d'attaquer
|
||||
}
|
||||
|
||||
|
||||
//Tour de l'IA
|
||||
IAEngine(player1,player2);
|
||||
|
||||
}
|
||||
|
||||
while(action != -1);
|
||||
|
||||
return -1;
|
||||
|
||||
//return 0;
|
||||
}
|
||||
|
||||
|
||||
int getEvent()
|
||||
{
|
||||
int action;
|
||||
SDL_Event event;
|
||||
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
|
||||
|
||||
switch(event.type) /* Test du type d'événement */
|
||||
{
|
||||
/* Si c'est un événement de type "Quitter" */
|
||||
case SDL_QUIT : printf("QUITTER\n");
|
||||
action = -1;
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
switch(event.key.keysym.sym) //La valeur de touche
|
||||
{
|
||||
case SDLK_UP: printf("FLECHE DU HAUT\n");
|
||||
action = 1;
|
||||
break;
|
||||
case SDLK_DOWN: printf("FLECHE DU BAS\n");
|
||||
action = 3;
|
||||
break;
|
||||
case SDLK_RIGHT: printf("FLECHE DE DROITE\n");
|
||||
action = 2;
|
||||
break;
|
||||
case SDLK_LEFT: printf("FLECHE DE GAUCHE\n");
|
||||
action = 4;
|
||||
break;
|
||||
case SDLK_SPACE:printf("BARRE D'ESPACE\n");
|
||||
action = 5;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
ActionPlayer(player2,1); //Déplacement vers le haut
|
||||
ActionPlayer(player2,2); //Déplacement vers la droite
|
||||
ActionPlayer(player2,3); //Déplacement vers le bas
|
||||
ActionPlayer(player2,4); //Déplacement vers la gauche
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//freeElement(List, 2); // Fonctionne
|
||||
//freeList(List); // Fonctionne
|
||||
|
||||
//displayList(List);
|
||||
|
||||
/** Pour la simulation d'un combat, on rentre la lettre A au clavier
|
||||
* Le joueur 1 va attaqué le joueur 2 et inversement
|
||||
* On affiche le score des joueurs
|
||||
*
|
||||
* */
|
||||
//List = AttackPlayer(List, 1, 2);
|
||||
|
||||
// SDL_Quit();
|
||||
|
||||
|
||||
/**Fonction qui crée un joueur
|
||||
*
|
||||
* */
|
||||
PLAYER* createPlayer(int Id)
|
||||
{
|
||||
PLAYER* player=NULL;
|
||||
//Utilisé la fonction de récupération de la taille de l'arène
|
||||
|
||||
player=(PLAYER*)malloc(sizeof(PLAYER));
|
||||
if(player==NULL)
|
||||
{
|
||||
printf("ERREUR Allocation joueur ");
|
||||
}
|
||||
|
||||
printf("Entrer le nom du joueur\n");
|
||||
scanf("%s",player->Name);
|
||||
printf("Nb PV?\n");
|
||||
scanf("%d",&player->HealthPoints);
|
||||
player->Id = Id;
|
||||
player->AttacksPoints = 10;
|
||||
|
||||
if(Id == 1)
|
||||
{
|
||||
player->PositionX=0;
|
||||
player->PositionY=0;
|
||||
}
|
||||
else if(Id ==2)
|
||||
{
|
||||
player->PositionX=ArenaMAX;
|
||||
player->PositionY=0;
|
||||
}
|
||||
else if(Id ==3)
|
||||
{
|
||||
player->PositionX=0;
|
||||
player->PositionY=ArenaMAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->PositionX=ArenaMAX;
|
||||
player->PositionY=ArenaMAX;
|
||||
}
|
||||
|
||||
player->suiv=NULL;
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
/**Fonction qui ajoute un joueur à la liste
|
||||
*
|
||||
* */
|
||||
|
||||
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element)
|
||||
{
|
||||
if(Head == NULL)
|
||||
{
|
||||
return Element;
|
||||
}
|
||||
|
||||
if(Element->Id < Head->Id)
|
||||
{
|
||||
Element->suiv = Head;
|
||||
return Element;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Element->Id == Head->Id)
|
||||
{
|
||||
printf("Le joueur à l'id %d exite déja dans la liste\n",Element->Id);
|
||||
free(Element);
|
||||
return Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
Head->suiv = insertRightPlaceRecursive(Head->suiv,Element);
|
||||
return Head;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void displayList(PLAYER * Head)
|
||||
{
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
}
|
||||
while(Head != NULL)
|
||||
{
|
||||
printf("****Player %d****\n",Head->Id);
|
||||
printf("Nom : %s\n",Head->Name);
|
||||
Head = Head->suiv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PLAYER * freeElement(PLAYER *Head, int Id)
|
||||
{
|
||||
PLAYER * Element;
|
||||
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
}
|
||||
|
||||
if(Id == Head->Id)
|
||||
{
|
||||
Element = Head;
|
||||
Head = Head->suiv;
|
||||
printf("Le joueur %d a été supprimé de la liste\n",Element->Id);
|
||||
free(Element);
|
||||
return Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
Head->suiv = freeElement(Head->suiv,Id);
|
||||
return Head;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PLAYER * freeList(PLAYER *Head)
|
||||
{
|
||||
if(Head != NULL)
|
||||
{
|
||||
freeList(Head->suiv);
|
||||
|
||||
}
|
||||
free(Head);
|
||||
Head=NULL;
|
||||
|
||||
return Head;
|
||||
}
|
||||
|
||||
int NumberPlayerAlive(PLAYER *Head)
|
||||
{
|
||||
int numberAlive=0;
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
if(Head->HealthPoints > 0)
|
||||
{
|
||||
numberAlive = numberAlive + 1;
|
||||
}
|
||||
Head=Head->suiv;
|
||||
}
|
||||
while(Head != NULL);
|
||||
return numberAlive;
|
||||
}
|
||||
}
|
||||
|
||||
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer)
|
||||
{
|
||||
printf("Fonction Recherche\n");
|
||||
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
}
|
||||
|
||||
if(Head->Id == idPlayer)
|
||||
{
|
||||
printf("Trouvé\n");
|
||||
|
||||
printf(" Joueur %s\n",Head->Name);
|
||||
return Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
Head->suiv = SearchPlayer(Head->suiv,idPlayer);
|
||||
|
||||
return Head->suiv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AttackPlayer( PLAYER *player1, PLAYER *player2)
|
||||
{
|
||||
printf("Fonction Attaque\n");
|
||||
|
||||
|
||||
if((player1 != NULL) && (player2 != NULL))
|
||||
{
|
||||
|
||||
while((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
||||
{
|
||||
printf("\n\n** Tour **\n");
|
||||
|
||||
printf("Attaque Joueur %d sur joueur %d \n",player1->Id,player2->Id);
|
||||
|
||||
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 ",player2->Id,player2->Name,player2->HealthPoints);
|
||||
|
||||
if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
||||
{
|
||||
printf("\nAttaque Joueur %d sur joueur %d\n ",player2->Id,player1->Id);
|
||||
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",player2->Id,player2->Name,player2->HealthPoints);
|
||||
}
|
||||
}
|
||||
|
||||
if(player1->HealthPoints > player2->HealthPoints)
|
||||
{
|
||||
printf("Combat finie \n Le joueur 1 a gagné le combat\n");
|
||||
}
|
||||
else if(player1->HealthPoints < player2->HealthPoints)
|
||||
{
|
||||
printf("Combat finie \n Le joueur 2 a gagné le combat\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Combat finie \n Les 2 joueurs sont morts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ActionPlayer(PLAYER * player, int action)
|
||||
{
|
||||
/* action = 1 --> Déplacement d'1 carreau vers le haut
|
||||
* action = 2 --> Déplacement d'1 carreau vers la droite
|
||||
* action = 3 --> Déplacement d'1 carreau vers le bas
|
||||
* action = 4 --> Déplacement d'1 carreau vers la gauche
|
||||
*
|
||||
* */
|
||||
|
||||
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
|
||||
int positionX = player->PositionX;
|
||||
int positionY = player->PositionY;
|
||||
|
||||
|
||||
|
||||
printf("\n**** Player %s ****",player->Name);
|
||||
|
||||
if(action == 1)
|
||||
{
|
||||
printf("On veut aller vers le haut\n");
|
||||
|
||||
if(positionY-1 >= 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers le haut\n");
|
||||
}
|
||||
}
|
||||
else if(action == 2)
|
||||
{
|
||||
printf("On veut aller vers la droite\n");
|
||||
|
||||
if(positionX + 1 <= ArenaMAX)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers la droite\n");
|
||||
}
|
||||
}
|
||||
else if(action == 3)
|
||||
{
|
||||
printf("On veut aller vers le bas\n");
|
||||
|
||||
if(positionY + 1 <= ArenaMAX)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers le bas\n");
|
||||
}
|
||||
}
|
||||
else if(action == 4)
|
||||
{
|
||||
printf("On veut aller vers la gauche\n");
|
||||
|
||||
if(positionX - 1 >= 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers la gauche\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Autre action\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Echec, le joueur est NULL\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* playerInterface.c
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#include "playerInterface.h"
|
||||
|
||||
#include "SDL2/SDL.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define ArenaMAX 100
|
||||
|
||||
int PlayerInterface(void)
|
||||
{
|
||||
|
||||
PLAYER* List=NULL;
|
||||
PLAYER* Element=NULL;
|
||||
int id=0;
|
||||
int numberAlive;
|
||||
|
||||
PLAYER* player1=NULL;
|
||||
PLAYER* player2=NULL;
|
||||
|
||||
while(id<2)
|
||||
{
|
||||
id = id + 1;
|
||||
Element = createPlayer(id);
|
||||
List = insertRightPlaceRecursive(List,Element);
|
||||
}
|
||||
|
||||
displayList(List);
|
||||
|
||||
player1 = SearchPlayer(List, 1);
|
||||
player2 = SearchPlayer(List, 2);
|
||||
|
||||
printf("Nom player 1 : %s\n",player1->Name);
|
||||
printf("Nom player 2 : %s\n",player2->Name);
|
||||
|
||||
numberAlive = NumberPlayerAlive(List);
|
||||
printf("Nombre de joueur en vie : %i",numberAlive);
|
||||
|
||||
|
||||
int action;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
action=getEvent();
|
||||
|
||||
if(action == 1)
|
||||
{
|
||||
ActionPlayer(player1,1); //Déplacement vers le haut
|
||||
}
|
||||
else if(action == 2)
|
||||
{
|
||||
ActionPlayer(player1,2); //Déplacement vers la droite
|
||||
}
|
||||
else if(action == 3)
|
||||
{
|
||||
ActionPlayer(player1,3); //Déplacement vers le bas
|
||||
}
|
||||
else if(action == 4)
|
||||
{
|
||||
ActionPlayer(player1,4); //Déplacement vers la gauche
|
||||
}
|
||||
else if(action == 5)
|
||||
{
|
||||
//Regarder le perso en face, le plus près
|
||||
AttackPlayer(player1,player2); //Voir quel player on choisit d'attaquer
|
||||
}
|
||||
|
||||
|
||||
//Tour de l'IA
|
||||
IAEngine(player1,player2);
|
||||
|
||||
}
|
||||
|
||||
while(action != -1);
|
||||
|
||||
return -1;
|
||||
|
||||
//return 0;
|
||||
}
|
||||
|
||||
|
||||
int getEvent()
|
||||
{
|
||||
int action;
|
||||
SDL_Event event;
|
||||
SDL_WaitEvent(&event); /* Récupération de l'événement dans event */
|
||||
|
||||
switch(event.type) /* Test du type d'événement */
|
||||
{
|
||||
/* Si c'est un événement de type "Quitter" */
|
||||
case SDL_QUIT : printf("QUITTER\n");
|
||||
action = -1;
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
switch(event.key.keysym.sym) //La valeur de touche
|
||||
{
|
||||
case SDLK_UP: printf("FLECHE DU HAUT\n");
|
||||
action = 1;
|
||||
break;
|
||||
case SDLK_DOWN: printf("FLECHE DU BAS\n");
|
||||
action = 3;
|
||||
break;
|
||||
case SDLK_RIGHT: printf("FLECHE DE DROITE\n");
|
||||
action = 2;
|
||||
break;
|
||||
case SDLK_LEFT: printf("FLECHE DE GAUCHE\n");
|
||||
action = 4;
|
||||
break;
|
||||
case SDLK_SPACE:printf("BARRE D'ESPACE\n");
|
||||
action = 5;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
ActionPlayer(player2,1); //Déplacement vers le haut
|
||||
ActionPlayer(player2,2); //Déplacement vers la droite
|
||||
ActionPlayer(player2,3); //Déplacement vers le bas
|
||||
ActionPlayer(player2,4); //Déplacement vers la gauche
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//freeElement(List, 2); // Fonctionne
|
||||
//freeList(List); // Fonctionne
|
||||
|
||||
//displayList(List);
|
||||
|
||||
/** Pour la simulation d'un combat, on rentre la lettre A au clavier
|
||||
* Le joueur 1 va attaqué le joueur 2 et inversement
|
||||
* On affiche le score des joueurs
|
||||
*
|
||||
* */
|
||||
//List = AttackPlayer(List, 1, 2);
|
||||
|
||||
// SDL_Quit();
|
||||
|
||||
|
||||
/**Fonction qui crée un joueur
|
||||
*
|
||||
* */
|
||||
PLAYER* createPlayer(int Id)
|
||||
{
|
||||
PLAYER* player=NULL;
|
||||
//Utilisé la fonction de récupération de la taille de l'arène
|
||||
|
||||
player=(PLAYER*)malloc(sizeof(PLAYER));
|
||||
if(player==NULL)
|
||||
{
|
||||
printf("ERREUR Allocation joueur ");
|
||||
}
|
||||
|
||||
printf("Entrer le nom du joueur\n");
|
||||
scanf("%s",player->Name);
|
||||
printf("Nb PV?\n");
|
||||
scanf("%d",&player->HealthPoints);
|
||||
player->Id = Id;
|
||||
player->AttacksPoints = 10;
|
||||
|
||||
if(Id == 1)
|
||||
{
|
||||
player->PositionX=0;
|
||||
player->PositionY=0;
|
||||
}
|
||||
else if(Id ==2)
|
||||
{
|
||||
player->PositionX=ArenaMAX;
|
||||
player->PositionY=0;
|
||||
}
|
||||
else if(Id ==3)
|
||||
{
|
||||
player->PositionX=0;
|
||||
player->PositionY=ArenaMAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->PositionX=ArenaMAX;
|
||||
player->PositionY=ArenaMAX;
|
||||
}
|
||||
|
||||
player->suiv=NULL;
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
/**Fonction qui ajoute un joueur à la liste
|
||||
*
|
||||
* */
|
||||
|
||||
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element)
|
||||
{
|
||||
if(Head == NULL)
|
||||
{
|
||||
return Element;
|
||||
}
|
||||
|
||||
if(Element->Id < Head->Id)
|
||||
{
|
||||
Element->suiv = Head;
|
||||
return Element;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Element->Id == Head->Id)
|
||||
{
|
||||
printf("Le joueur à l'id %d exite déja dans la liste\n",Element->Id);
|
||||
free(Element);
|
||||
return Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
Head->suiv = insertRightPlaceRecursive(Head->suiv,Element);
|
||||
return Head;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void displayList(PLAYER * Head)
|
||||
{
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
}
|
||||
while(Head != NULL)
|
||||
{
|
||||
printf("****Player %d****\n",Head->Id);
|
||||
printf("Nom : %s\n",Head->Name);
|
||||
Head = Head->suiv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PLAYER * freeElement(PLAYER *Head, int Id)
|
||||
{
|
||||
PLAYER * Element;
|
||||
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
}
|
||||
|
||||
if(Id == Head->Id)
|
||||
{
|
||||
Element = Head;
|
||||
Head = Head->suiv;
|
||||
printf("Le joueur %d a été supprimé de la liste\n",Element->Id);
|
||||
free(Element);
|
||||
return Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
Head->suiv = freeElement(Head->suiv,Id);
|
||||
return Head;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PLAYER * freeList(PLAYER *Head)
|
||||
{
|
||||
if(Head != NULL)
|
||||
{
|
||||
freeList(Head->suiv);
|
||||
|
||||
}
|
||||
free(Head);
|
||||
Head=NULL;
|
||||
|
||||
return Head;
|
||||
}
|
||||
|
||||
int NumberPlayerAlive(PLAYER *Head)
|
||||
{
|
||||
int numberAlive=0;
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
if(Head->HealthPoints > 0)
|
||||
{
|
||||
numberAlive = numberAlive + 1;
|
||||
}
|
||||
Head=Head->suiv;
|
||||
}
|
||||
while(Head != NULL);
|
||||
return numberAlive;
|
||||
}
|
||||
}
|
||||
|
||||
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer)
|
||||
{
|
||||
printf("Fonction Recherche\n");
|
||||
|
||||
if(Head == NULL)
|
||||
{
|
||||
printf("La liste est vide\n");
|
||||
}
|
||||
|
||||
if(Head->Id == idPlayer)
|
||||
{
|
||||
printf("Trouvé\n");
|
||||
|
||||
printf(" Joueur %s\n",Head->Name);
|
||||
return Head;
|
||||
}
|
||||
else
|
||||
{
|
||||
Head->suiv = SearchPlayer(Head->suiv,idPlayer);
|
||||
|
||||
return Head->suiv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AttackPlayer( PLAYER *player1, PLAYER *player2)
|
||||
{
|
||||
printf("Fonction Attaque\n");
|
||||
|
||||
|
||||
if((player1 != NULL) && (player2 != NULL))
|
||||
{
|
||||
|
||||
while((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
||||
{
|
||||
printf("\n\n** Tour **\n");
|
||||
|
||||
printf("Attaque Joueur %d sur joueur %d \n",player1->Id,player2->Id);
|
||||
|
||||
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 ",player2->Id,player2->Name,player2->HealthPoints);
|
||||
|
||||
if((player1->HealthPoints > 0) && (player2->HealthPoints > 0))
|
||||
{
|
||||
printf("\nAttaque Joueur %d sur joueur %d\n ",player2->Id,player1->Id);
|
||||
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",player2->Id,player2->Name,player2->HealthPoints);
|
||||
}
|
||||
}
|
||||
|
||||
if(player1->HealthPoints > player2->HealthPoints)
|
||||
{
|
||||
printf("Combat finie \n Le joueur 1 a gagné le combat\n");
|
||||
}
|
||||
else if(player1->HealthPoints < player2->HealthPoints)
|
||||
{
|
||||
printf("Combat finie \n Le joueur 2 a gagné le combat\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Combat finie \n Les 2 joueurs sont morts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ActionPlayer(PLAYER * player, int action)
|
||||
{
|
||||
/* action = 1 --> Déplacement d'1 carreau vers le haut
|
||||
* action = 2 --> Déplacement d'1 carreau vers la droite
|
||||
* action = 3 --> Déplacement d'1 carreau vers le bas
|
||||
* action = 4 --> Déplacement d'1 carreau vers la gauche
|
||||
*
|
||||
* */
|
||||
|
||||
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
|
||||
int positionX = player->PositionX;
|
||||
int positionY = player->PositionY;
|
||||
|
||||
|
||||
|
||||
printf("\n**** Player %s ****",player->Name);
|
||||
|
||||
if(action == 1)
|
||||
{
|
||||
printf("On veut aller vers le haut\n");
|
||||
|
||||
if(positionY-1 >= 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers le haut\n");
|
||||
}
|
||||
}
|
||||
else if(action == 2)
|
||||
{
|
||||
printf("On veut aller vers la droite\n");
|
||||
|
||||
if(positionX + 1 <= ArenaMAX)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers la droite\n");
|
||||
}
|
||||
}
|
||||
else if(action == 3)
|
||||
{
|
||||
printf("On veut aller vers le bas\n");
|
||||
|
||||
if(positionY + 1 <= ArenaMAX)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers le bas\n");
|
||||
}
|
||||
}
|
||||
else if(action == 4)
|
||||
{
|
||||
printf("On veut aller vers la gauche\n");
|
||||
|
||||
if(positionX - 1 >= 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Impossible d'aller vers la gauche\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Autre action\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Echec, le joueur est NULL\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,49 +1,49 @@
|
||||
/*
|
||||
* playerInterface.h
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#ifndef PLAYERINTERFACE_H_
|
||||
#define PLAYERINTERFACE_H_
|
||||
|
||||
/** Structure d'un joueur (IA ou utilisateur)
|
||||
*
|
||||
* */
|
||||
typedef struct Player
|
||||
{
|
||||
int Id;
|
||||
char Name[35];
|
||||
char Race[20];
|
||||
|
||||
int HealthPoints;
|
||||
int AttacksPoints;
|
||||
int DefensePoints;
|
||||
|
||||
int PositionX;
|
||||
int PositionY;
|
||||
//char Weapons[Max_Weapons];
|
||||
|
||||
//int Coins;
|
||||
|
||||
struct Player * suiv;
|
||||
|
||||
}PLAYER;
|
||||
|
||||
//Prototypes
|
||||
|
||||
PLAYER* createPlayer(int Id);
|
||||
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element);
|
||||
void displayList(PLAYER * Head);
|
||||
PLAYER * freeElement(PLAYER *Head, int Id);
|
||||
PLAYER * freeList(PLAYER *Head);
|
||||
|
||||
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer);
|
||||
void AttackPlayer( PLAYER *player1, PLAYER *player2);
|
||||
void ActionPlayer(PLAYER * player, int action);
|
||||
|
||||
int NumberPlayerAlive(PLAYER *Head);
|
||||
int getEvent(void);
|
||||
|
||||
#endif /* PLAYERINTERFACE_H_ */
|
||||
/*
|
||||
* playerInterface.h
|
||||
*
|
||||
* Created on: 17 juin 2018
|
||||
* Author: isen
|
||||
*/
|
||||
|
||||
#ifndef PLAYERINTERFACE_H_
|
||||
#define PLAYERINTERFACE_H_
|
||||
|
||||
/** Structure d'un joueur (IA ou utilisateur)
|
||||
*
|
||||
* */
|
||||
typedef struct Player
|
||||
{
|
||||
int Id;
|
||||
char Name[35];
|
||||
char Race[20];
|
||||
|
||||
int HealthPoints;
|
||||
int AttacksPoints;
|
||||
int DefensePoints;
|
||||
|
||||
int PositionX;
|
||||
int PositionY;
|
||||
//char Weapons[Max_Weapons];
|
||||
|
||||
//int Coins;
|
||||
|
||||
struct Player * suiv;
|
||||
|
||||
}PLAYER;
|
||||
|
||||
//Prototypes
|
||||
|
||||
PLAYER* createPlayer(int Id);
|
||||
PLAYER* insertRightPlaceRecursive(PLAYER* Head, PLAYER* Element);
|
||||
void displayList(PLAYER * Head);
|
||||
PLAYER * freeElement(PLAYER *Head, int Id);
|
||||
PLAYER * freeList(PLAYER *Head);
|
||||
|
||||
PLAYER * SearchPlayer(PLAYER *Head, int idPlayer);
|
||||
void AttackPlayer( PLAYER *player1, PLAYER *player2);
|
||||
void ActionPlayer(PLAYER * player, int action);
|
||||
|
||||
int NumberPlayerAlive(PLAYER *Head);
|
||||
int getEvent(void);
|
||||
|
||||
#endif /* PLAYERINTERFACE_H_ */
|
||||
|