This commit is contained in:
2024-12-12 11:52:03 +01:00
parent 509863f591
commit 055bec0350
4 changed files with 63 additions and 3 deletions

View File

@@ -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)

View File

@@ -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
View 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

3
main.c
View File

@@ -1,7 +1,8 @@
#include <stdio.h>
#include "function.h"
int main()
{
puts("main");
printf("main\n");
return 0;
}