def handle(self): while True: my_game.singleMove() self.data = self.request.recv(1024).strip() pressed_buttons = game_display.get_user_input() char_to_send = '#' for ch in pressed_buttons: char_to_send += chr(ch) # sending pressed buttons to client self.request.sendall(char_to_send) for ch in char_to_send: my_game.charPress(0, ch) # getting client info # self.data is already string of chr, no need to call chr() opponent_char = self.data for ch in opponent_char: my_game.charPress(1, ch) game_display.update_display(my_game) game_display.terminal_game.stdscr.refresh() communication.wait_period()
HOST, PORT = sys.argv[1], int(sys.argv[2]) else: HOST, PORT = "192.168.0.10", 9999 try: game_display.init_everything() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((HOST, PORT)) # main action: pressed_buttons = [] my_game = game.Game(settings.NUMBER_OF_BATTLE_COLUMNS, settings.DICTIONARY) game_display.update_display(my_game) while True: my_game.singleMove() pressed_buttons = game_display.get_user_input() char_to_send = '#' for ch in pressed_buttons: char_to_send += chr(ch) sock.sendall(char_to_send) for ch in char_to_send: my_game.charPress(0, ch) opponent_char = sock.recv(1024) for ch in opponent_char: my_game.charPress(1, ch) game_display.update_display(my_game)
self.enemy_hits = [] return tmp def enemy_player_hitted(self): tmp = self.local_hits self.local_hits = [] return tmp def recent_explosions(self): tmp = self.explosions self.explosions = [] return tmp if __name__ == "__main__": game_display.init_everything() x = Game(100, settings.DICTIONARY) try: while True: ch = [] ch = game_display.get_user_input() for c in ch: if c >= 0 and c <= 255: # making sure it can be converted to char x.charPress(0, chr(c)) game_display.update_display(x) x.singleMove() time.sleep(0.05) finally: game_display.restore_terminal_display()