while the game runs check if the user interacted with the game, if yes change the games state accordingly. For each iteration change the state of your game (AI) and render the current state
Why not look at the code of open source games?
Try some cli experiments while you search for some game on git(hub/lab). It will let you comprehend a lot of the logic behind a game without worrying about graphics