I made a tictactoe game and added a time limit in the play turn.
My problem is how to make the remaining time visible to the player. I don’t know how to run different code line like a text displaying the remaining time with input function at the same time.
This is my current code:
(the function is part of class)
from inputimeout import inputimeout, TimeoutOccurred
def play_turn(self):
while True:
try:
choice = int(inputimeout(prompt=f"{self.players[self.current_player].name}, choose a move: ", timeout=5))
if 1 <= int(choice) <= 9 and self.board.update_board(choice, self.players[self.current_player].symbol):
break
else:
print("Invalid move,try again")
except TimeoutOccurred:
print("Timed out!!")
time.sleep(2)
return
except ValueError:
print("Please enter a number between 1 and 9")
New contributor
مالك خالد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.