#include "GameCode.h"
#include "Game.h"
#include <windows.h>
#include <exception>

// Application entry point
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
{
	// Create game instance
	Engine::Game* game = new Engine::Game();

	// Initialize game
	if (!game->initialize())
	{
		MessageBoxA(0, "Failed to initialize Game", "Error", MB_ICONERROR|MB_OK);
		delete game;
		return 0;
	}

	// Initialize GameCode
	Engine::GameCode* gameCode = Engine::GameCode::create();
	if (!gameCode->initialize())
	{
		MessageBoxA(0, "Failed to initialize GameCode", "Error", MB_ICONERROR|MB_OK);
		delete gameCode;
		delete game;
		return 0;
	}
	
	// Run game
	try
	{
		game->run(gameCode);
	}
	catch (std::exception& ex)
	{
		MessageBoxA(0, "An unhandled exception has occurred", "Error", MB_ICONERROR|MB_OK);
	}

	// Shutdown
	delete gameCode;
	delete game;
	return 0;
}