def reset_game(): ''' >>> reset_game() False ''' curses.clear() curses.refresh() return False
def game(speed): snake.food() # main loop for the game global KEY curses.nodelay(stdscr, True) while True: KEY = get_key(KEY) if snake.get_status() == 'dead' or KEY == 27: # game over curses.clear() curses.wborder(stdscr) curses.mvwaddstr(stdscr, middley-1, middlex-6, '--GAME OVER--') curses.mvwaddstr(stdscr, middley, middlex-8,'Your score is -') curses.mvwaddstr(stdscr, middley, middlex+8, snake.lenght - snake.starting_lenght-1) curses.mvwaddstr(stdscr, middley+1, middlex-8,'Press Esc to quit') KEY = choice([RIGHT, LEFT]) snake.food() curses.refresh() curses.nodelay(stdscr, False) while get_key(KEY) != 27: pass reset_game() snake.__init__() break if snake.get_status() == 'grow': # eaten food snake.food() snake.draw(KEY) snake.delete(snake.lenght) time.sleep(1/speed/2)
def _selected(self): if self.topics_pointer == 0: if self.game_interface.game_initialized: self.game_interface.game_menu_interface.unblock() self.game_interface.game_field.unblock() self.locked_topics.append(1) self.game_interface.game_initialized = False self.start_new_game() elif self.topics_pointer == 1: self.locked_topics.append(1) self.game_interface.game_menu_interface.unblock() self.game_interface.game.pause() if self.game_interface.game_field.blocked: self.game_interface.game_field.unblock() self.disable() elif self.topics_pointer == 5: clear() endwin() exit(0)
def display(self): #self.panel.top() uni.top_panel(self.panel) uni.show_panel(self.panel) #self.panel.show() uni.clear() #self.window.clear() while True: uni.refresh() #self.window.refresh() uni.doupdate() for index, item in enumerate(self.items): if index == self.position: mode = uni.A_REVERSE else: mode = uni.A_NORMAL msg = '%d. %s' % (index, item[0]) uni.mvaddstr(1 + index, 1, msg, mode) key = uni.getch() if key in [uni.KEY_ENTER, ord('\n')]: if self.position == len(self.items) - 1: break else: self.items[self.position][1]() elif key == uni.KEY_UP: self.navigate(-1) elif key == uni.KEY_DOWN: self.navigate(1) uni.clear() #self.window.clear() uni.hide_panel(self.panel) #self.panel.hide() uni.update_panels() #panel.update_panels() uni.doupdate()
self.game_menu_interface.disable() def key_event(self, key): if not self.game_menu_interface.enabled and not self.game_field.enabled and not self.game_stat.enabled: self.main_menu.key_event(key) elif self.main_menu.enabled and self.game_menu_interface.blocked: self.main_menu.key_event(key) elif not self.main_menu.enabled and self.game_menu_interface.blocked: self.game_field.key_event(key) else: self.game_menu_interface.key_event(key) if __name__ == "__main__": stdscr = initscr() clear() noecho() cbreak() curs_set(0) keypad(stdscr, True) start_color() use_default_colors() nodelay(stdscr, True) init_pair(1, COLOR_BLACK, COLOR_WHITE) init_pair(2, COLOR_WHITE, COLOR_BLUE) init_pair(3, COLOR_BLACK, COLOR_BLUE) init_pair(4, COLOR_WHITE, COLOR_CYAN) init_pair(5, COLOR_YELLOW, COLOR_GREEN) init_pair(6, COLOR_GREEN, COLOR_BLACK) init_pair(7, COLOR_RED, COLOR_BLACK) init_pair(8, COLOR_BLUE, COLOR_YELLOW)
y += 1 uni.wrefresh(menu_win) def report_choice(mouse_x, mouse_y): i = startx + 2 j = starty + 3 for choice in range(0, n_choices): if (mouse_y == j + choice) and (mouse_x >= i) and (mouse_x <= i + len(choices[choice])): if choice == n_choices - 1: return -1 else: return choice + 1 break stdscr = uni.initscr() uni.clear() uni.noecho() uni.cbreak() uni.curs_set(0) startx = int((80 - WIDTH) / 2) starty = int((24 - HEIGHT) / 2) menu_win = uni.newwin(HEIGHT, WIDTH, starty, startx) uni.keypad(menu_win, True) uni.mvaddstr(0, 0, "Click on Exit to quit (works best in a virtual console)") uni.refresh() print_menu(menu_win, 1) uni.mouseinterval(0) uni.mousemask(uni.ALL_MOUSE_EVENTS)
def reset_game(): curses.clear() curses.refresh() return False
self.game_field.disable() self.game_menu_interface.disable() def key_event(self, key): if not self.game_menu_interface.enabled and not self.game_field.enabled and not self.game_stat.enabled: self.main_menu.key_event(key) elif self.main_menu.enabled and self.game_menu_interface.blocked: self.main_menu.key_event(key) elif not self.main_menu.enabled and self.game_menu_interface.blocked: self.game_field.key_event(key) else: self.game_menu_interface.key_event(key) if __name__ == "__main__": stdscr = initscr() clear() noecho() cbreak() curs_set(0) keypad(stdscr, True) start_color() use_default_colors() nodelay(stdscr, True) init_pair(1, COLOR_BLACK, COLOR_WHITE) init_pair(2, COLOR_WHITE, COLOR_BLUE) init_pair(3, COLOR_BLACK, COLOR_BLUE) init_pair(4, COLOR_WHITE, COLOR_CYAN) init_pair(5, COLOR_YELLOW, COLOR_GREEN) init_pair(6, COLOR_GREEN, COLOR_BLACK) init_pair(7, COLOR_RED, COLOR_BLACK) init_pair(8, COLOR_BLUE, COLOR_YELLOW)