def __init__(self): self._game = Game() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.ifHasFailed = False
def reset(self): self._game.reset() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.n = 0 self.ifHasFailed = False
def reset(self): """ Function: Resets the state of game but the map remains the same. """ self._game.reset() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.ifHasFailed = False
def main(): root = tk.Tk() root.title("Tic-Tac-Toe") root.geometry("800x600") Program.screen = Window(master=root) Program.screen.setGameOptionsModeScreen(Program.go2BoardScreen) Program.screen.mainloop()
class Main: def __init__(self): self._game = Game() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.n = 0 self.ifHasFailed = False def reset(self): self._game.reset() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.n = 0 self.ifHasFailed = False def start(self): global expectedResult global nr nr += 1 if nr == 21: stopGame() self._codes = expectedResult[f"{nr}"] print(f"Initial codes: {self._codes}\n") if self._codes == -1: # missing start or stop self._window.draw() return elif self._codes == -2: # missing condition self._window.draw() return for codeList in self._codes: self.function(codeList) self._game.update() if self._game.run == True: self._window.draw() else: self._window.draw() break main() def function(self, codeList): self._game.update() self._window.draw() if self._game.run == False: return code = codeList[0] if type(code) is list: code = code[0] self.n += 1 # print(f"\nFrame {self.n}") # print(f"List: {codeList}") # print(f"Code: {code}") if code == 87: # Move forward self._character.moveForward() self.ifHasFailed = False elif code == 79: # Turn right self._character.turnRight() self.ifHasFailed = False elif code == 61: # Turn left self._character.turnLeft() self.ifHasFailed = False elif code == 47: # Start whileloop # print(f"Cond: {codeList[1]}") while self.condition(codeList[1]): for codeSubList in codeList[2]: self._game.update() if self._game.run == True: self._window.draw() self.function(codeSubList) else: self._window.draw() main() self.ifHasFailed = False elif code == 59: # Start if-statement # print(f"Cond: {codeList[1]}") if self.condition(codeList[1]): self.ifHasFailed = False for codeSubList in codeList[2]: self._game.update() if self._game.run == True: self._window.draw() self.function(codeSubList) else: self._window.draw() main() else: self.ifHasFailed = True elif code == 103: # Start else-statement if self.ifHasFailed: for codeSubList in codeList[1]: self._game.update() if self._game.run == True: self._window.draw() self.function(codeSubList) else: self._window.draw() main() self.ifHasFailed = False self._game.update() if self._game.run == True: self._window.draw() else: self._window.draw() main() def condition(self, code): if code == 109: cond = self._character.pathAhead() elif code == 121: cond = self._character.notFinished() elif code == 117: cond = self._character.pathRight() elif code == 121: cond = self._character.pathLeft() # print(cond) return cond @property def game(self): return self._game @property def character(self): return self._character @property def window(self): return self._window
class Main: """ Class: Handels game-logic and runs the game, a new instance of Main is a new game, new map etc. """ def __init__(self): self._game = Game() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.ifHasFailed = False def reset(self): """ Function: Resets the state of game but the map remains the same. """ self._game.reset() self._window = Window(self._game) self._character = self._game.character self._window.draw() self.ifHasFailed = False def start(self): """ Function: Gets codes from webcam, starts game and runs until game is finished or character has bumped into a wall. """ self._codes = getCodes.get_codes() if self._codes == -1: # missing start or stop self._window.draw() return elif self._codes == -2: # missing condition self._window.draw() return for codeList in self._codes: self.function(codeList) self._game.update() if self._game.run == True: self._window.draw() else: self._window.draw() break main() def function(self, codeList): """ Function: args codeList, from current list of codes (codeList) get the current functionality. In this game it is: while - 47, if - 59, else - 103, pathAhead - 109, pathLeft - 115, pathRight - 117, notFinished - 121, forward - 87, turnLeft - 61, turnRight - 79 """ self._game.update() self._window.draw() if self._game.run == False: return code = codeList[0] if type(code) is list: code = code[0] if code == 87: # Move forward self._character.move_forward() self.ifHasFailed = False elif code == 79: # Turn right self._character.turn_right() self.ifHasFailed = False elif code == 61: # Turn left self._character.turn_left() self.ifHasFailed = False elif code == 47: # Start whileloop while self.condition(codeList[1]): for codeSubList in codeList[2]: self._game.update() if self._game.run == True: self._window.draw() self.function(codeSubList) else: self._window.draw() main() self.ifHasFailed = False elif code == 59: # Start if-statement if self.condition(codeList[1]): self.ifHasFailed = False for codeSubList in codeList[2]: self._game.update() if self._game.run == True: self._window.draw() self.function(codeSubList) else: self._window.draw() main() else: self.ifHasFailed = True elif code == 103: # Start else-statement if self.ifHasFailed: for codeSubList in codeList[1]: self._game.update() if self._game.run == True: self._window.draw() self.function(codeSubList) else: self._window.draw() main() self.ifHasFailed = False self._game.update() if self._game.run == True: self._window.draw() else: self._window.draw() main() def condition(self, code): """ Function: args code, from given code representing a statement, checks if that statement is true or not and returns either True or False. In this game it is: pathAhead - 109, pathLeft - 115, pathRight - 117, notFinished - 121 """ if code == 109: cond = self._character.path_ahead() elif code == 121: cond = self._character.not_finished() elif code == 117: cond = self._character.path_right() elif code == 121: cond = self._character.path_left() return cond @property def game(self): """ Function: game getter """ return self._game @property def character(self): """ Function: character getter """ return self._character @property def window(self): """ Function: window getter """ return self._window
# pprint(axis_values) # print('-------------- Window.Window.joystick_assignments') # pprint(Window.Window.joystick_assignments) # print('--------------- Window.Window.channels') # pprint(Window.Window.channels) # print('------------------------------------') bsp.updateOutput(axis_values) elif button_change is True: bsp.send_gate_output(button_to_change, button_on) if __name__ == "__main__": root = Tk() tksupport.install(root) app = Window.Window(root) # root.wm_title("ps4tomidi") ps4.init() deferred = handle_ps4_events() deferred.addCallback(handle_ps4_events) # reactor.callWhenRunning(handle_ps4_events) reactor.run() root.destroy() # reactor.callInThread(handle_ps4_events)