implements a basic game loop