#include "maze.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
#include <vector>

using namespace std;

maze::maze()
{

	sizeInX = 0;
	sizeInY = 0;

} // end of maze()

bool maze::loadLevel(string fileName)
{

	point2 endPoint;
	char temp;
	int y = 0;
	int x = 0;
	
	ifstream in(fileName.c_str());

	if(!in)
	// the file doesn't exist, return false
		return false;


	while(in && y < 32) 
	{
		x = 0;
		
		while(in.get(temp) && (x < 32)  && in && (temp != '\n')  )
		{
			if(temp == '*')
			{
				start.x = x;
				start.y = y;
			}
			if(temp == 'x')
			{
				endPoint.x = x;
				endPoint.y = y;
				end.push_back(endPoint);
			}
			level[y][x] = temp;
			x++;
			sizeInX = x;	
		}
		y++;
	}

//	if(sizeInY < 32)
		sizeInY = y;

	cout << "load succesful" << endl;

	in.close();

	return true;

}

void maze::getSize(int &xVar, int &yVar)
{

	xVar = sizeInX;
	yVar = sizeInY;

}

char maze::getElement(int xVar, int yVar)
{
	char retType;

	retType = level[yVar][xVar];
	return retType;

}

point2 maze::getStart()
{
	// this grabs the start point
	return start;
}

point2 maze::getEnd(int index)
{
	// the returns the end point
	return end[index];
}

int maze::getNumEnd()
{
	return end.size();
}
