def check_collisions(self): for x in self.words: if x.end_point > self.box.xsize: clear_screen() self.music_object.play_sound("game_lost.ogg") print(self.language.game[3].word) self.exit_state = 1 print(self.language.game[4].word) time.sleep(2) getch()
def execute_exercise(words, typos, begin_time): first_char = True escape_pressed_twice_interval = 1 escape_pressed = 0 j = 0 while j < len(words): word = words[j] char = "" i = 0 while (i < len(word)): char = getch() if first_char: begin_time = time() first_char = False if char == '\x1b' and time( ) - escape_pressed > escape_pressed_twice_interval: print("\nRetry (press ESC twice to quit)\n{}".format( ''.join(words))) typos = 0 first_char = True escape_pressed = time() j = -1 break if char == '\x1b' and time( ) - escape_pressed < escape_pressed_twice_interval: print("\nExiting (user pressed ESC twice)") exit() if char == word[i]: print(char, end='', flush=True) i += 1 else: typos += 1 j += 1 return typos, begin_time
def listener(self): may_i_continue = True string_query = '' print self.pyTermUI.preText(), while may_i_continue: char_data = getch() pressedKey = ord(char_data) #print str(pressedKey) if pressedKey == 12: os.system('clear') print self.pyTermUI.preText() + "%s" % string_query + " ", elif pressedKey == 127: string_query = string_query[:-1] print self.pyTermUI.preText() + "%s" % string_query + " ", print self.pyTermUI.preText() + "%s" % string_query, elif not pressedKey == 3: string_query += char_data print self.pyTermUI.preText() + "%s" % string_query, elif pressedKey == 3: return "{{BREAKAPPLICATION}}" commands = string_query.split() self.pyTermUI.check(commands) may_i_continue = False if pressedKey == 13 or pressedKey == 3 else True return string_query
def process_inputs(self, delta): # pass # if sys.stdin.read(): try: # input = sys.stdin.read(1) input = getch() if input == 'w': self.player.dy = -5.0 elif input == 'a': self.player.dx = -5.0 elif input == 's': self.player.dy = 5.0 elif input == 'd': self.player.dx = 5.0 except: pass
def run(self): self.can_be_continued = True if self.cycles == 0: self.clock_start = time.time() self.start_time = time.clock() self.print_map() self.end_time = time.clock() if self.continued: self.clock_start = time.time() - self.time_backup self.start_time = time.clock() self.end_time = time.clock() self.continued = False getch_start_time = time.time() temp = getch(0.20) self.end_time += time.time() - getch_start_time getch_start_time = 0 self.char_handling(temp) if self.end_time - self.start_time > self.timeout: # that for is not elegant for x in range( 0, int(round( (self.end_time - self.start_time) / self.timeout))): self.words_move() self.check_collisions() self.print_map() self.start_time = self.end_time self.end_time = time.clock() self.add_word() self.cycles += 1
self.game = Game(self.box,self.language) self.game.choose_generator(self.dictionary) self.music=Music() self.game.connect_music(self.music) def connect_music(self,music): self.music=music self.game.connect_music(self.music) #music = Music() #music.play_music(self.connected_object.music.music_location+"menu_music.ogg") game_itself=GameObjects() #game_itself.connect_music(music) game_itself.music.play_music("menu_music.ogg") menu = MainMenu() menu.add_position(game_itself.language.menu[0]) menu.add_position(game_itself.language.menu[1]) menu.add_position(game_itself.language.menu[13]) #to_be_added menu.add_position(game_itself.language.menu[2]) menu.add_position(game_itself.language.menu[3]) menu.add_position(game_itself.language.menu[4]) menu.add_position(game_itself.language.menu[5]) menu.connect_game_object(game_itself) menu.print_menu() temp="l" #27 Esc while True: temp = getch() menu.interact(temp)
from Getch import getch command = "u" while command != "p": command = getch() print(command)
def run(self): while True: ch = getch() sys.stdout.write(ch) self.conexao.write(ch)
def open_entry(self, entry_name): if entry_name.word == self.connected_object.language.menu[7].word: dictionary_location = os.getcwd()+"/dictionaries" dictionary_list = return_all_dictionaries(dictionary_location) dictionaries_menu = ChooseMenu("/dictionaries/") dictionaries_menu.connect_game_object(self.connected_object) dictionaries_menu.entries_names = [] for x in dictionary_list: dictionaries_menu.add_position(x) dictionaries_menu.add_position(self.connected_object.language.menu[11]) clear_screen() dictionaries_menu.print_menu() while str(dictionaries_menu.pressed_entry) != str(self.connected_object.language.menu[11]): temp = getch() dictionaries_menu.interact(temp) dictionaries_menu = None # dictionary_list=os.listdir(os.getcwd()+"/dictionaries") if entry_name.word == self.connected_object.language.menu[8].word: language_location = os.getcwd()+"/languages" language_list = os.listdir(language_location) languages_menu = ChooseMenu("/languages/") languages_menu.connect_game_object(self.connected_object) languages_menu.entries_names = [] for x in language_list: languages_menu.add_position(x) languages_menu.add_position(self.connected_object.language.menu[11]) clear_screen() languages_menu.print_menu() while str(languages_menu.pressed_entry) != str(self.connected_object.language.menu[11]): temp = getch() languages_menu.interact(temp) languages_menu = None if entry_name.word == self.connected_object.language.menu[13].word: game_menu = ChooseMenu("game_options") game_menu.connect_game_object(self.connected_object) game_menu.entries_names = [] entries_names.append() game_menu.add_position(self.connected_object.language.menu[11]) clear_screen() game_menu.print_menu() while str(game_menu.pressed_entry) != str(self.connected_object.game.menu[11]): temp = getch() game_menu.interact(temp) game_menu = None if entry_name.word == self.connected_object.language.menu[14].word: music_location = os.getcwd()+"/music" music_list = os.listdir(music_location) music_menu = ChooseMenu("/music/") music_menu.connect_game_object(self.connected_object) music_menu.entries_names = [] for x in music_list: music_menu.add_position(x) music_menu.add_position(self.connected_object.language.menu[11]) clear_screen() music_menu.print_menu() while str(music_menu.pressed_entry) != str(self.connected_object.language.menu[11]): temp = getch() music_menu.interact(temp) music_menu = None # dictionary_list=os.listdir(os.getcwd()+"/dictionaries") if entry_name.word == self.connected_object.language.menu[9].word: self.connected_object.music.switch_sound() if entry_name.word == self.connected_object.language.menu[10].word: self.connected_object.music.switch_music() if entry_name.word ==self.connected_object.language.menu[16].word: #temp = self.get_position_index(self.connected_object.language.menu[16].word) self.connected_object.language.menu[16].restore() self.connected_object.game.max_length_change() self.connected_object.language.menu[16].change(self.connected_object.language.menu[16].word + str(self.connected_object.game.max_length)) #self.change_position_index(self.connected_object.language.menu[16].word + str(self.connected_object.game.max_length),temp) if entry_name.word==self.connected_object.language.menu[17].word: self.connected_object.language.menu[17].restore() self.connected_object.box.change_x() self.connected_object.language.menu[17].change(self.connected_object.language.menu[17].word + str(self.connected_object.box.xsize)) self.connected_object.game.can_be_continued=False if entry_name.word==self.connected_object.language.menu[18].word: self.connected_object.language.menu[18].restore() self.connected_object.box.change_y() self.connected_object.language.menu[18].change(self.connected_object.language.menu[18].word + str(self.connected_object.box.ysize)) self.connected_object.game.can_be_continued=False if str(entry_name) == str(self.connected_object.language.menu[11]): pass self.print_menu()
def open_entry(self, entry_name): if str(entry_name) == str(self.connected_object.language.menu[5]): clear_screen() print(self.connected_object.language.menu[15]) time.sleep(2) sys.exit() elif str(entry_name) == str(self.connected_object.language.menu[0]): self.connected_object.music.stop_remember("Menu") self.connected_object.music.play_music("game_music.ogg") self.connected_object.game.reset() while self.connected_object.game.exit_state != 1: self.connected_object.game.run() self.connected_object.game.exit_state = 0 self.connected_object.music.stop_remember("Game") self.connected_object.music.play_remember("Menu") # Start the game elif entry_name.word == self.connected_object.language.menu[1].word: if self.connected_object.game.can_be_continued == True: self.connected_object.music.stop_remember("Menu") self.connected_object.music.play_remember("Game") self.connected_object.game.continued=True while self.connected_object.game.exit_state != 1: self.connected_object.game.run() self.connected_object.game.exit_state = 0 self.connected_object.music.stop_remember("Game") self.connected_object.music.play_remember("Menu") # Load the game else: clear_screen() print(self.connected_object.language.menu[6].word) time.sleep(2) elif entry_name.word == self.connected_object.language.menu[2].word: options_menu = OptionsMenu() options_menu.connect_game_object(self.connected_object) options_menu.entries_names = [] options_menu.add_position(self.connected_object.language.menu[7]) options_menu.add_position(self.connected_object.language.menu[8]) options_menu.add_position(self.connected_object.language.menu[14]) options_menu.add_position(self.connected_object.language.menu[9]) options_menu.add_position(self.connected_object.language.menu[10]) options_menu.add_position(self.connected_object.language.menu[11]) clear_screen() options_menu.print_menu() while str(options_menu.pressed_entry) != str(self.connected_object.language.menu[11]): temp = getch() options_menu.interact(temp) options_menu = None elif entry_name.word == self.connected_object.language.menu[3].word: with open(self.connected_object.language.location+"/help.txt", "r") as help: clear_screen() for x in help: print(x) keyboard = Colors.GREEN + "`" + Colors.ENDCOLOR + Colors.YELLOW + "1" + Colors.ENDCOLOR + Colors.YELLOW + "2" + Colors.ENDCOLOR + Colors.YELLOW + "3" + Colors.ENDCOLOR + Colors.RED + "4" + Colors.ENDCOLOR + Colors.BLUE + "5" + Colors.ENDCOLOR + Colors.BLUE + "6" + Colors.ENDCOLOR + Colors.BLUE + "7" + Colors.ENDCOLOR + Colors.RED + "8" + Colors.ENDCOLOR + Colors.YELLOW + "9" + Colors.ENDCOLOR + Colors.YELLOW + "0" + Colors.ENDCOLOR + Colors.YELLOW + "-" + Colors.ENDCOLOR + Colors.GREEN + "=" + Colors.ENDCOLOR + "\n" + Colors.GREEN + "TAB" + Colors.ENDCOLOR + Colors.YELLOW + "q" + Colors.ENDCOLOR + Colors.YELLOW + "w" + Colors.ENDCOLOR + Colors.RED + "e" + Colors.ENDCOLOR + Colors.BLUE + "r" + Colors.ENDCOLOR + Colors.BLUE + "t" + Colors.ENDCOLOR + Colors.BLUE + "y" + Colors.ENDCOLOR + Colors.BLUE + "u" + Colors.ENDCOLOR + Colors.RED + "i" + Colors.ENDCOLOR + Colors.YELLOW + "o" + Colors.ENDCOLOR + Colors.YELLOW + "p" + Colors.ENDCOLOR + Colors.YELLOW + \ "[" + Colors.ENDCOLOR + Colors.YELLOW + "]" + Colors.ENDCOLOR + Colors.GREEN + "\\" + Colors.ENDCOLOR + "\n" + Colors.GREEN + "CAPS" + Colors.ENDCOLOR + Colors.YELLOW + "a" + Colors.ENDCOLOR + Colors.YELLOW + "s" + Colors.ENDCOLOR + Colors.RED + "d" + Colors.ENDCOLOR + Colors.BLUE + "f" + Colors.ENDCOLOR + Colors.BLUE + "g" + Colors.ENDCOLOR + Colors.BLUE + "h" + Colors.ENDCOLOR + Colors.BLUE + "j" + Colors.ENDCOLOR + Colors.RED + "k" + Colors.ENDCOLOR + Colors.YELLOW + "l" + Colors.ENDCOLOR + Colors.YELLOW + ";" + Colors.ENDCOLOR + Colors.YELLOW + "'" + Colors.ENDCOLOR + \ Colors.GREEN + "ENTER" + Colors.ENDCOLOR + "\n" + Colors.GREEN + "SHIFT" + Colors.ENDCOLOR + Colors.YELLOW + "z" + Colors.ENDCOLOR + Colors.YELLOW + "x" + Colors.ENDCOLOR + Colors.RED + "c" + Colors.ENDCOLOR + Colors.BLUE + "v" + Colors.ENDCOLOR + Colors.BLUE + "b" + Colors.ENDCOLOR + \ Colors.BLUE + "n" + Colors.ENDCOLOR + Colors.BLUE + Colors.RED + "m" + Colors.ENDCOLOR + Colors.YELLOW + "," + Colors.ENDCOLOR + Colors.YELLOW + \ "." + Colors.ENDCOLOR + Colors.YELLOW + "/" + Colors.ENDCOLOR + \ Colors.GREEN + "SHIFT" + Colors.ENDCOLOR + "\n" + " SPACE" print(keyboard) print(self.connected_object.language.menu[11].word) getch() elif entry_name.word == self.connected_object.language.menu[4].word: with open(self.connected_object.language.location+ "/my_credits.txt", "r") as credits: clear_screen() for x in credits: print(x) time.sleep(1) print(self.connected_object.language.credits[0].word) getch() # open credits # elif entry_name.word == self.connected_object.language.menu[13].word: game_options=OptionsMenu() game_options.connect_game_object(self.connected_object) game_options.entries_names = [] self.connected_object.language.menu[16].restore() self.connected_object.language.menu[16].change(self.connected_object.language.menu[16].word + str(self.connected_object.game.max_length)) game_options.add_position(self.connected_object.language.menu[16]) self.connected_object.language.menu[17].restore() self.connected_object.language.menu[17].change(self.connected_object.language.menu[17].word + str(self.connected_object.box.xsize)) game_options.add_position(self.connected_object.language.menu[17]) self.connected_object.language.menu[18].restore() self.connected_object.language.menu[18].change(self.connected_object.language.menu[18].word + str(self.connected_object.box.ysize)) game_options.add_position(self.connected_object.language.menu[18]) game_options.add_position(self.connected_object.language.menu[11]) clear_screen() game_options.print_menu() while str(game_options.pressed_entry) != str(self.connected_object.language.menu[11]): temp = getch() game_options.interact(temp) game_options = None self.print_menu()