/* Main.cpp */

#include "ConLib.h"
#include "Screen.h"

void main ()
{
	
	ConLib Console;
	int LastAction;
	
	
	// Generate a new maze and draw it
	Maze myMaze;
	Screen myScreen;
	myScreen.drawMaze(&myMaze);

	// Generate a new player and draw it
	Player myPlayer;
	myScreen.drawPlayer(&myPlayer);
	
	while(1)
	{
		LastAction = Console.GetKey();
		Console.SetBackgroundColour(ConRed);
		COORD position = myPlayer.getPosition();
		int walls = myMaze.getWalls(position);
		
		if(LastAction)
		{			
			int tween = myPlayer.getTween();
			switch(LastAction)
			{
			case VK_UP:
				if (tween & North || tween & South || tween == 0)
				{
					if (!(walls & North))
					{
						myPlayer.movePlayer(North);
					}
				}
				break;
			case VK_DOWN:
				if (tween & North || tween & South || tween == 0)
				{
					if (!(walls & South))
					{
						myPlayer.movePlayer(South);
					}
				}
				else
				{
					cout << tween;
				}
				break;
			case VK_LEFT:
				if (tween & East || tween & West || tween == 0)
				{
					if (!(walls & West))
					{
						myPlayer.movePlayer(West);
					}
				}
				break;
			case VK_RIGHT:
				if (tween & East || tween & West || tween == 0)
				{
					if (!(walls & East))
					{
						myPlayer.movePlayer(East);
					}
				}
				break;
			default:
				break;
			}
			myScreen.drawPlayer(&myPlayer);
		}
	}

	COORD CursorPosition;
	Console.SetBackgroundColour (0);
	Console.SetTextColour (ConRed | ConGreen | ConBlue);
	CursorPosition.X = 0;
	CursorPosition.Y = 23;
	Console.SetPosition (CursorPosition);
}