Added cleanup function to Game to take care of dynamically allocated memory when window is closed

event handing moved to the end of the while loop in main to avoid using the window after it has been closed