I have an issue with resetting my game in pygame when the user is asked to restart. The program is constructed like this:
import board as b class Gui(): def __init__(self): pygame.init() self.gamestate = b.GameState() def run(self): running = True while running: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_r: running = False pygame.quit() Gui().run if __name__ == '__main__': Gui().run() What happens when the user tries to restart is that the Gui closes and the while loop exits as they should. It then opens a new window BUT it has not cleared the gamestate, so my gamestate from previous run is still there. I thought that the line self.gamestate = b.GameState() would create a new gamestate for me but that seems not to be the case. Here is a short snippet from the board file:
class GameState: def __init__(self): self.board = s.start_position When calling it I thought it would set the board to start position and all its parameters to inititial, but something is not right and I have not been able to solve this for 3 days now. I hope you can help me how to clear the gamestate and start from fresh again.