def map_3_handler(): interface = graphictools.import_graphic_from_file('graphics/interface.gfx', 80, 23) current_map = maptools.Map('map3', 'graphics/map3.gfx') display = graphictools.add_to_graphic(interface, current_map.map_graphic, 1, 1) game_loop_3(interface, current_map, display)
def map_2_handler(): interface = graphictools.import_graphic_from_file('graphics/interface.gfx', 80, 23) current_map = maptools.Map('map2', 'graphics/map1.gfx') hero = tiletools.Hero(100, 10, 2, 'up') display = graphictools.add_to_graphic(interface, current_map.map_graphic, 1, 1) game_loop_2(interface, current_map, display, hero)
def game_loop_2(interface, current_map, display, hero): info_box_message = [ 'Prepare yourself for', 'the final fight.', 'Gather all items marked', 'as "?" on the map.' ] while True: hero_string_pos = str(hero.x) + ',' + str(hero.y) if (maptools.Maps.items.__contains__(hero_string_pos)): item = maptools.Maps.items[hero_string_pos].split(',') add_to_inventory(item[0], item[1], item[2]) graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic( [[tiletools.Tiles.black.string] * 28] * 9)) info_box_message = [ 'You gained:', str('name: ' + item[0]), str('amount: ' + item[1]) ] current_map.map_graphic[hero.x - 1][hero.y - 1] = tiletools.Tiles.grass maptools.Maps.items.__delitem__(hero_string_pos) if (not maptools.Maps.items): graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic( [[tiletools.Tiles.black.string] * 28] * 9)) info_box_message = [ 'You are ready to face a God', 'Get to the boss cave using', 'black entrance at the bottom', 'of the map.' ] print(tiletools.Hero.inventory) display = graphictools.add_to_graphic(interface, current_map.map_graphic, 1, 1) graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic(info_box_message)) display = graphictools.add_single_tile_to_graphic( display, hero, hero.x, hero.y) os.system('clear') graphictools.print_graphic(display) key_pressed = getch() if (key_pressed == 'i' or key_pressed == 'i'): graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic( [[tiletools.Tiles.black.string] * 28] * 9)) info_box_message = prepare_inventory_list(hero.inventory) handle_user_input(display, current_map, key_pressed, hero) if (not maptools.Maps.items and hero_string_pos in ['13,18', '14,18', '15,18']): map_3_handler() break
def game_loop_3(interface, current_map, display): info_box_message = [ 'You have to kill the boss by', 'winning hot worm cold fight.', 'Type 3-number digit', 'without duplications.', ' ' ] answer_dict = {'Numbers': []} random_number = generate_random_number() while True: print(random_number.__str__()) display = graphictools.add_to_graphic(interface, current_map.map_graphic, 1, 1) graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic( [[tiletools.Tiles.black.string] * 28] * 9)) graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic(info_box_message)) graphictools.print_graphic(display) key_pressed = getch() if (key_pressed in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']): answers = answer_dict.__getitem__("Numbers") if (len(answers) == 3): hint = get_hint(answers, random_number) if (hint == True): time2 = time.time() timeDifference = time2 - maptools.Maps.start_time os.system('clear') print('\n' * 6) print(" " * 25, "You win! It took: ", int(timeDifference), 'seconds.') getch() save_to_scoreboard(tiletools.Hero.player_name, timeDifference) print_scoreboard() exit() else: info_box_message = hint answer_dict.__setitem__("Numbers", []) elif (not answers.__contains__(key_pressed)): answers.append(key_pressed) answer_dict.__setitem__("Numbers", answers) info_box_message = [ str('Your number: ' + str("".join(answers))) ] else: info_box_message = [ "Your number cannot", 'have any duplications', str('Your number: ' + str("".join(answers))) ] elif key_pressed == 'q': exit()
def game_loop_1(interface, current_map, display, hero, gold_coins, rabbits): while True: display = graphictools.add_to_graphic(interface, current_map.map_graphic, 1, 1) display = graphictools.add_single_tile_to_graphic( display, hero, hero.x, hero.y) if hero.gold < 100 or hero.rabbits_killed < 10: message = [ 'Collect 100 gold and kill', '10 rabbits as a sacrifice', 'to the Gods. They will help', 'you get past the gate.', "", 'Your gold: ' + str(hero.gold), 'Rabbits killed: ' + str(hero.rabbits_killed) ] else: message = [ 'You feel bad about yourself', 'but Gods are pleased. They', 'opened the gate for you.' ] for i in range(3): display[17 + i][21] = graphictools.Tiles.grass graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic()) graphictools.add_dialogue_to_display( interface, graphictools.get_dialogue_graphic(message)) for coin in gold_coins: if current_map.name == "map1" and coin.exist: display[coin.x][coin.y] = coin for rabbit in rabbits: if current_map.name == "map1" and rabbit.alive: display[rabbit.x][rabbit.y] = rabbit os.system('clear') graphictools.print_graphic(display) key_pressed = getch() handle_user_input(display, current_map, key_pressed, hero) for coin in gold_coins: coin.collision_check() if hero.y == 21: map_2_handler()
def map_1_handler(player_name): interface = graphictools.import_graphic_from_file('graphics/interface.gfx', 80, 23) hero = tiletools.Hero(100, 8, 12, 'up') tiletools.Hero.player_name = player_name """ map initialization """ map1 = maptools.Map('map1', 'graphics/map2.gfx', hero) gold1 = tiletools.Gold(4, 4, 10, hero) gold2 = tiletools.Gold(3, 11, 10, hero) gold3 = tiletools.Gold(15, 13, 10, hero) gold4 = tiletools.Gold(42, 19, 10, hero) gold5 = tiletools.Gold(42, 7, 10, hero) gold6 = tiletools.Gold(35, 15, 20, hero) gold7 = tiletools.Gold(22, 5, 10, hero) gold8 = tiletools.Gold(7, 19, 20, hero) gold_coins = [gold1, gold2, gold3, gold4, gold5, gold6, gold7, gold8] rabbit1 = tiletools.Rabbit(5, 5) rabbit2 = tiletools.Rabbit(10, 9) rabbit3 = tiletools.Rabbit(6, 5) rabbit4 = tiletools.Rabbit(7, 5) rabbit5 = tiletools.Rabbit(14, 3) rabbit6 = tiletools.Rabbit(33, 7) rabbit7 = tiletools.Rabbit(37, 15) rabbit8 = tiletools.Rabbit(26, 18) rabbit9 = tiletools.Rabbit(12, 18) rabbit10 = tiletools.Rabbit(44, 12) rabbits = [ rabbit1, rabbit2, rabbit3, rabbit4, rabbit5, rabbit6, rabbit7, rabbit8, rabbit9, rabbit10 ] current_map = map1 """ ------------------- """ display = graphictools.add_to_graphic(interface, current_map.map_graphic, 1, 1) game_loop_1(interface, current_map, display, hero, gold_coins, rabbits)