Merge branch 'arena'

This commit is contained in:
JackCarterSmith 2018-06-20 15:22:16 +02:00
commit fc7085d306
5 changed files with 131 additions and 82 deletions

View File

@ -17,9 +17,10 @@
int IAEngine(PLAYER * player1, PLAYER * player2)
{
char Race[20];
//Player 1 est le joueur, player 2 le bot
if((player1 != NULL) & (player2 !=NULL))
char Race[20];
{
//On récupère les positions des 2 joueurs . L'IA sait où est le joueur
int Player1PositionX = player1->PositionX;

View File

@ -2,36 +2,31 @@
#include <stdlib.h>
#include <stdio.h>
#include "fileHandler.h"
#include "logHelper.h"
int initResources() {
//resOpen();
return 0;
}
/*
* 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->isGround = 1;
tile_h->canBeMined = 0;
tile_h->playerOnTile = NULL;
tile_h->nextRow = NULL;
tile_h->nextColumn = NULL;
return tile_h;
} else if (prevHTile != NULL) {
tile_h = calloc(1,sizeof(ARENA_H_TILE));
prevHTile->nextRow = tile_h;
tile_h->type_id = 0;
tile_h->isGround = 1;
tile_h->canBeMined = 0;
tile_h->playerOnTile = NULL;
tile_h->nextRow = NULL;
tile_h->nextColumn = NULL;
}
return NULL;
return tile_h;
}
ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
@ -41,8 +36,7 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
tile_w = calloc(1,sizeof(ARENA_W_TILE));
prevHTile->nextColumn = tile_w;
tile_w->type_id = 0;
tile_w->isGround = 1;
tile_w->canBeMined = 0;
tile_w->playerOnTile = NULL;
tile_w->nextColumn = NULL;
return tile_w;
@ -50,29 +44,28 @@ ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) {
tile_w = calloc(1,sizeof(ARENA_W_TILE));
prevWTile->nextColumn = tile_w;
tile_w->type_id = 0;
tile_w->isGround = 1;
tile_w->canBeMined = 0;
tile_w->playerOnTile = NULL;
tile_w->nextColumn = NULL;
}
return NULL;
}
ARENA_H_TILE* genNewArena(int w, int h) {
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<h;i++){
for(i=0;i<size_h;i++){
if (i==0) {
arenaOrigin = createHTile(NULL);
TmpCursor_h = arenaOrigin;
} else {
createHTile(TmpCursor_h);
TmpCursor_h = createHTile(TmpCursor_h);
}
for(j=0;j<w;j++){
for(j=0;j<size_w;j++){
if (j==0) {
TmpCursor_w = createWTile(TmpCursor_h, NULL);
} else {
@ -81,13 +74,77 @@ ARENA_H_TILE* genNewArena(int w, int h) {
if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn;
}
if (i!=0) TmpCursor_h = TmpCursor_h->nextRow;
}
return arenaOrigin;
}
int deleteArena(ARENA_H_TILE* genNewArena) {
/*
* 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;
}

View File

@ -1,3 +1,5 @@
#include "playerInterface.h"
#ifndef ARENAENGINE_H_
#define ARENAENGINE_H_
@ -13,21 +15,32 @@ typedef struct items{
}ITEMS;
*/
typedef struct arena_h_tile{ //Rows chained list
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;
//texture?
int isGround;
int canBeMined;
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

81
main.c
View File

@ -11,65 +11,50 @@
#include <stdio.h>
#include <stdlib.h>
#include "logHelper.h"
#include "SDL2/SDL.h"
#include "SDL2/SDL_thread.h"
#include "SDL2/SDL_mutex.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_thread.h>
#include <SDL2/SDL_mutex.h>
#include "arenaEngine.h"
int main(void)
{
SDL_Init(SDL_INIT_VIDEO);
#define A_HEIGHT 100
#define A_WIDTH 100
if (SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (%s)\n",SDL_GetError());
return -1;
void initDisplayLib() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
addLogCritical("Init SDL libs failed !");
exit(EXIT_FAILURE);
}
else
{
int continuer = 1;
int action;
}
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();
SDL_Event event; // Cette variable servira plus tard à gérer les événements
if( pWindow )
{
SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voie la fenêtre */
while (continuer)
{
action = PlayerInterface();
if (action == -1)
{
continuer = 0;
addLogInfo("Creating new arena...");
arena = genNewArena(A_HEIGHT, A_WIDTH);
if (arena == NULL) {
addLogCritical("Error with arena generator !");
exit(EXIT_FAILURE);
}
else
{
addLogInfo("Successfully created arena.");
}
}
//SDL_DestroyWindow(pWindow);
}
else
{
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
}
}
//IAEngine();
SDL_Quit();
//PlayerInterface();
return 0;
deleteArena(arena);
addLogInfo("Cleared arena.");
return EXIT_SUCCESS;
}

View File

@ -1,13 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "SDL2/SDL.h"
void initDisplayLib() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError());
exit(EXIT_FAILURE);
}
}
#include <SDL2/SDL.h>
int createGameMenuWindows() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {