Transfer Python code from Blender Render to Blender Game Engine
In the logic bricks you can add python scripts under "Controllers".  You would need to set a sensor "Property" or two that holds something to indicate the start/end of the game.  Likewise you will need to set that "Property" at specific times to achieve what you want.  "Restsrt Game" is under Actuators.

You may have to modify your code but you can do a majority with Logic bricks and sensing "Properties".  You can do something similar with changing cameras at certain times.

For detecting frames, just have your script set a Logic Brick property each frame change, you will need to keep an eye on your FPS as large scripts can slow you down.