#include <stdio.h>
#include <string.h>
#include <windows.h>
#define MAX_X	20
#define MAX_Y	20
//Easy defines to make setting up the map easier
#define F	"You are in a forest."
#define S	"You are standing in a murky swamp."
#define R   "A river runs past you."
#define T	"You are standing on a dusty trail."
#define C	"You are standing in an open clearing."
#define W	"There is a wall here. You can never stand on this square."
int main(void)
{
	char * TheMap[MAX_X][MAX_Y] = {
		F,R,F,F,F,F,F,F,W,W,W,W,W,F,F,F,T,F,F,F,
		F,R,R,F,C,F,F,F,W,F,F,F,W,F,F,F,T,F,W,W,
		F,F,R,F,F,F,F,F,C,F,F,F,W,F,F,T,T,F,W,F,
		F,F,R,F,F,F,F,F,W,F,F,F,W,F,T,T,F,F,W,F,
		F,F,R,R,F,F,C,F,W,W,W,W,W,F,T,F,F,F,W,F,
		F,F,F,R,F,F,F,F,F,F,F,F,F,F,T,F,C,F,W,F,
		F,F,F,R,F,F,F,F,F,F,F,F,F,T,T,F,F,C,W,F,
		F,F,F,R,F,F,F,F,F,S,S,F,T,T,F,F,F,F,W,W,
		F,F,F,R,F,F,F,F,S,S,S,S,T,S,F,F,F,F,F,W,
		F,F,F,R,R,F,T,T,T,T,T,T,S,F,F,F,F,F,F,W,
		F,F,F,F,R,F,T,S,S,S,S,S,S,S,F,F,C,F,F,W,
		F,F,F,F,R,F,T,F,F,S,S,F,F,F,F,F,F,F,F,W,
		F,F,F,F,R,R,T,T,F,F,F,F,F,F,F,F,F,F,F,W,
		F,F,F,C,F,R,F,T,T,F,F,F,F,F,S,S,S,S,F,W,
		F,F,F,F,F,R,R,F,T,T,F,F,S,S,S,S,F,F,F,W,
		F,F,C,C,F,F,R,R,F,T,F,F,F,F,S,S,S,F,F,W,
		F,F,C,C,F,F,F,R,R,T,F,F,C,F,F,S,S,S,F,W,
		F,F,F,F,F,F,F,F,R,T,F,F,F,F,F,F,S,S,S,W,
		F,F,F,F,F,F,C,F,R,T,F,C,F,F,F,S,S,S,F,W,
		F,F,F,F,C,F,F,F,R,T,F,F,F,F,F,F,F,F,F,W
	};
	FILE *fp;
	fp = fopen("AUTOMADE.MAP", "w");
	for (short y = 0; y < MAX_Y; y ++)
		for (short x = 0; x < MAX_X; x ++)
		{
			fprintf(fp, "\n//COLOUMN %i, ROW %i\n", y, x);
			fprintf(fp, "%s\n", TheMap[x][y]);
			//the tags to tell us if a certain direction has been marked as a no-go
			//0 = North
			//1 = South
			//2 = West
			//3 = East
			BOOL ExitTag[4];
			//Set all the allow walking by defaut
			ExitTag[0] = TRUE;
			ExitTag[1] = TRUE;
			ExitTag[2] = TRUE;
			ExitTag[3] = TRUE;
			//Stop us from walking out of the map
			if (x == 0)
				ExitTag[0] = FALSE;
			else if (x == MAX_X -1)
				ExitTag[1] = FALSE;
			if (y == 0)
				ExitTag[2] = FALSE;
			else if (y == MAX_Y -1)
				ExitTag[3] = FALSE;
			//Check for things that we're not allowed to walk through
			//(the 'W' is a wall so we cant walk to a sqaure that is a wall)
			if (y > 0)
			{
				if (strcmp(TheMap[x][y-1], W) == 0)
				{
					fprintf(fp, "There is a wall to the north.\n");
					ExitTag[0] = FALSE;
				}
			}
			else if (y < MAX_Y)
			{
				if (strcmp(TheMap[x][y+1], W) == 0)
				{
					fprintf(fp, "There is a wall to the south.\n");
					ExitTag[1] = FALSE;
				}
			}
			if (x > 0)
			{
				if (strcmp(TheMap[x-1][y], W) == 0)
				{
					fprintf(fp, "There is a wall to the west.\n");
					ExitTag[2] = FALSE;
				}
			}
			else if (x < MAX_X)
			{
				if (strcmp(TheMap[x+1][y], W) == 0)
				{
					fprintf(fp, "There is a wall to the east.\n");
					ExitTag[3] = FALSE;
				}
			}
			fprintf(fp, "-DoneText-\n");
			fprintf(fp, "EXITS: ");
			if (ExitTag[0]) fprintf(fp, "N");
			if (ExitTag[1]) fprintf(fp, "S");
			if (ExitTag[2]) fprintf(fp, "W");
			if (ExitTag[3]) fprintf(fp, "E");
			fprintf(fp, "\n");
		}
	fclose(fp);
	return 0;
}