def buy_sell(screen, buyer, seller, n, msg1, msg2): display.init_colors() inp = 0 a_row = 2 cur_row = 2 for i in seller.inventory: i.cost_str = str(i.cost) while inp != 27: screen.clear() a_row = invlib.arrow(a_row, inp, len(seller.inventory)) if invlib.exit_selected(seller.inventory, inp, a_row): break elif inp == 10: selected_item = seller.inventory[a_row - 2] new_msg = msg2 if msg2 == "You bought ": new_msg = msg2 + selected_item.name trade(buyer, seller, selected_item, new_msg, screen) #"\"Thanks! Here is your gold\"" display.display_store( cur_row, a_row, screen, buyer, seller, msg1) #"\"Hello, I am %s, can I buy stuff from you.\""% n screen.refresh() inp = screen.getch()
def warning(screen): init_colors() a_row = 7 key = 0 curses.curs_set(False) while key != 10: screen.clear() screen.addstr( 5, 5, "WARNING: genrating a new world will destroy the old world. would you like to...", curses.color_pair(14)) screen.addstr( 7, 7, "enter the old world, or", curses.color_pair(1) if a_row == 7 else curses.color_pair(0)) screen.addstr( 8, 7, "destroy old world and create new one", curses.color_pair(1) if a_row == 8 else curses.color_pair(0)) screen.addstr(a_row, 1, "->", curses.color_pair(1)) key = screen.getch() a_row = arrow(a_row, key, 1, 7) return 1 if a_row == 7 else 0
def do_menu(screen): init_colors() a_row = 7 key = 0 curses.curs_set(False) while key != 10: screen.clear() write_cool_word("WEREWOLF", 20, 1, screen) screen.addstr(5, 5, "would you like to...") screen.addstr( 7, 7, "enter the old world, or", curses.color_pair(1) if a_row == 7 else curses.color_pair(0)) screen.addstr( 8, 7, "generate a new one?", curses.color_pair(1) if a_row == 8 else curses.color_pair(0)) screen.addstr(a_row, 1, "->", curses.color_pair(1)) key = screen.getch() a_row = arrow(a_row, key, 1, 7) if a_row == 8: return warning(screen) else: return 1
def main(screen): global score curses.curs_set(False) # Disable blinking cursor init_colors() stars = init_stars() player = make_player() ships = [player] for x in range(10): ships.append(new_meteor()) inp = 0 laser_timer = 3 KEY_Q = 113 news.append("WELCOME TO SPACE ATTACK!!!") while (inp != KEY_Q): # Quit game if player presses "q" screen.clear() #TIMERS laser_timer -= 1 if laser_timer == 0: if player.energy_num <= 10: player.energy_num += 1 laser_timer = 3 # Filter ships list to only include non-explosions ships = list(filter(lambda s: s.type != "explosion", ships)) #NEW ENEMIES for x in range(3): ships.append(new_meteor()) for x in range(randint(0, 1)): ships.append(new_UFO()) #PLAYER INPUT if player in ships: keyboard_input(inp, player, ships) # If there a shield on # remove some power #MOVE ENEMIES/CHECK COLLISIONS/ETC... ships = update_world(player, ships) shield = first(lambda s: s.type == "shield", ships) if shield != None: player.energy_num -= 2 if player.energy_num <= 0 and shield != None: ships.remove(shield) if player not in ships and shield != None: ships.remove(shield) #OUTPUT display_screen(player, score, screen, ships, stars) #GET KEYBOARD INPUT/END TURN inp = screen.getch()
def main(stdscr): inp = 0 current_level = 7 curses.curs_set(False) # Disable blinking cursor init_colors() creatures, objects, floorplan, timer = change_level(current_level, coins=0) width = len(floorplan[1]) height = len(floorplan) while (inp != 113): # Quit game if player presses "q" stdscr.clear() player = list(filter(lambda c: c.type == "player", creatures))[0] timer = update_timers(creatures, player, timer) invisibility_check(player, floorplan) # if player is alive, do all the things if player.health <= 0 and timer <= 0: death_screen(height, stdscr, width) break # creature movement ]]]] player.status = "safe" if player.speedtimer <= 0 or player.speedtimer % 2 == 0: tick_creatures(creatures, floorplan, objects, player) # Draw player info/visibility alert status_color, status_symbol = generate_alert(creatures, player) stdscr.addstr(height, 0, status_symbol, curses.color_pair(status_color)) stdscr.addstr(height, 5, "coins-" + str(player.coins), curses.color_pair(15)) stdscr.addstr(height, 20, "TIME LEFT-" + str(timer), curses.color_pair(10)) draw_map(stdscr, floorplan, tiles) # Draw all creatures for c in creatures: stdscr.addstr(c.y, c.x, c.tile, curses.color_pair(c.curcolor)) for o in objects: stdscr.addstr(o.y, o.x, o.tile, curses.color_pair(o.color)) status_y = 25 csy = 0 display_news(stdscr, news, width, height) display_inv(stdscr, player.inv, width, True) stdscr.addstr(height, 40, "health " + ("+" * player.health), curses.color_pair(1)) stdscr.refresh() inp = stdscr.getch( ) # "Get character" -- pauses and waits for player to type a key keyboard_input(inp, player, floorplan, objects, creatures, stdscr) if current_level == 0 and player.y == 0: current_level += 1 creatures, objects, floorplan, timer = change_level( current_level, player.inv, player.coins) width = len(floorplan[1]) height = len(floorplan) for o in objects: if player.x == o.x and player.y == o.y and o.pickupable == True: if o.buyable == False: objects.remove(o) if o.type == "coin": player.coins += 1 else: player.inv.append(o) else: if player.coins >= o.cost: prompt_str = "Do you want to buy this " + o.type + "? It costs " + str( o.cost) + " coins." resp = prompt(stdscr, height, prompt_str) if resp == ord("y"): player.inv.append(o) objects.remove(o) player.coins -= o.cost else: prompt_str = "You dont have enough money to buy this " + o.type + "." prompt(stdscr, height, prompt_str) # Are we at the end of the level? tilenum = floorplan[player.y][player.x] if tilenum == 7: # and any(lambda o: o.type == "treasure chest", player.inv): current_level += 1 creatures, objects, floorplan, timer = change_level( current_level, player.inv, player.coins) width = len(floorplan[1]) height = len(floorplan)