95 lines
1.5 KiB
C
95 lines
1.5 KiB
C
#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;
|
|
}
|
|
|
|
int CanIGoUp(unsigned short int **tab,int size,int posX,int posY)
|
|
{
|
|
if(tab[posX][posY+1]!=1)
|
|
{
|
|
if(tab[posX][posY+1]==2)
|
|
{
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
|
|
int CanIGoDown(unsigned short int **tab,int size,int posX,int posY)
|
|
{
|
|
if(tab[posX][posY-1]!=1)
|
|
{
|
|
if(tab[posX][posY-1]==2)
|
|
{
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
|
|
int CanIGoLeft(unsigned short int **tab,int size,int posX,int posY)
|
|
{
|
|
if(tab[posX-1][posY]!=1)
|
|
{
|
|
if(tab[posX-1][posY]==2)
|
|
{
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
|
|
int CanIGoRight(unsigned short int **tab,int size,int posX,int posY)
|
|
{
|
|
if(tab[posX+1][posY]!=1)
|
|
{
|
|
if(tab[posX+1][posY]==2)
|
|
{
|
|
return 2;
|
|
}
|
|
return 1;
|
|
}
|
|
return 0;
|
|
|
|
} |