tab2d
This commit is contained in:
6
Makefile
6
Makefile
@@ -1,7 +1,7 @@
|
||||
# Variable
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra $(shell pkg-config --cflags --libs sdl2)
|
||||
OBJ = main.o
|
||||
OBJ = main.o function.o
|
||||
TARGET = sokoban
|
||||
|
||||
all: $(TARGET)
|
||||
@@ -9,9 +9,11 @@ all: $(TARGET)
|
||||
$(TARGET): $(OBJ)
|
||||
$(CC) $(CFLAGS) $(OBJ) -o $(TARGET)
|
||||
|
||||
main.c : main.c
|
||||
main.o : main.c
|
||||
$(CC) $(CFLAGS) -c main.c
|
||||
|
||||
function.o : function.c
|
||||
$(CC) $(CFLAGS) -c function
|
||||
|
||||
clean :
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
|
||||
40
function.c
40
function.c
@@ -1 +1,41 @@
|
||||
#include "function.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
|
||||
unsigned short int **creatArea2D(const unsigned int N)
|
||||
{
|
||||
unsigned short int **tab2d;
|
||||
tab2d = malloc(sizeof(unsigned short int* ) * N);
|
||||
if (tab2d == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool fail = false;
|
||||
int i;
|
||||
for (i = 0; i < N && !fail; ++i)
|
||||
{
|
||||
tab2d[i] = malloc(sizeof(unsigned short int) * N);
|
||||
if (tab2d[i] == NULL)
|
||||
{
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fail)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < i; ++j)
|
||||
{
|
||||
free(tab2d[j]);
|
||||
}
|
||||
free(tab2d);
|
||||
return NULL;
|
||||
}
|
||||
return tab2d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
17
function.h
Normal file
17
function.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifdef FONCTION_H
|
||||
#define FONCTION_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#define EMPTY 0
|
||||
#define WALL 1
|
||||
#define BOX 2
|
||||
#define TARGET 3
|
||||
#define BOX_ON_TARGET 4
|
||||
#define PLAYER 5
|
||||
#define PLAYER_ON_TARGET 6
|
||||
|
||||
unsigned short int **creatArea2D(const unsigned int N);
|
||||
#endif // FONCTION_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user