def adapt(self, parent):
     GameController.adapt(self,parent)
     if not self.online_controleur.my_turn:
         self.score_controller.var_time.set(Constants.MESSAGE_ADVERCE_TURN)
Beispiel #2
0
class MainController(Observer):
    def __init__(self, mainFrame, grid):
        self.mainFrame = mainFrame
        self.player = HumanPlayer(69, "test")
        self.view = MainFrameView(self.mainFrame, self)
        self.menu_controller = MenuController(self.mainFrame, self.player)
        game = GameOnePlayer(grid)
        game.set_player(self.player)
        self.game_controller = GameController(self.mainFrame, game)
        self.menu_controller.add_observer(self)
        end_vcontroleur = EndController()
        end_vcontroleur.add_observer(self)
        self.game_controller.set_end_controller(end_vcontroleur)
        self.__main_job = None
        self.mainFrame.protocol("WM_DELETE_WINDOW", self.update_quit)

    def run(self):
        self.update_time()
        self.refresh_view()
        self.__main_job = self.mainFrame.mainloop()

    def update_time(self):
        self.game_controller.up_timer()

        self.__jobtime = self.mainFrame.after(1000, self.update_time)

    def refresh_view(self):
        self.game_controller.grd_refresh()
        self.__jobrefresh = self.mainFrame.after(100, self.refresh_view)

    def update(self, data) -> None:
        self.__stop()
        endcontrolleur = self.game_controller.end_controlleur

        self.game_controller = GameController(self.mainFrame,
                                              GameOnePlayer(data))
        self.game_controller.game.set_player(self.player)
        self.game_controller.set_end_controller(endcontrolleur)
        self.refresh_view()
        self.update_time()

    def update_obline(self, data, iserveur) -> None:

        self.__stop()
        controller_main = oc.OnlineControlleur(iserveur, data, self.mainFrame)
        controller_main.add_apelant(self)
        controller_main.online_game(self.mainFrame)

    def craft_game(self, controleur):

        endcontrolleur = self.game_controller.end_controlleur
        self.game_controller = controleur

        self.game_controller.adapt(self.mainFrame)
        self.player.score = 0
        self.game_controller.game.set_player(self.player)
        self.game_controller.set_end_controller(endcontrolleur)
        self.refresh_view()

        self.update_time()

    def update_quit(self):
        self.__stop()

        self.mainFrame.destroy()

    def __stop(self):
        if self.__jobtime is not None:
            self.mainFrame.after_cancel(self.__jobtime)
            self.__jobtime = None
        if self.__jobrefresh is not None:
            self.mainFrame.after_cancel(self.__jobrefresh)
            self.__jobrefresh = None
        self.game_controller.quit()