def saveImage(): global image, num try: image.save('Image_' + str(num) + '.png') num += 1 message("Сохранение", "Изображение сохранено") except NameError: message("Ошибка сохранения", "Изображение не создано!")
def walk_in_front_of_dude(self): choice = dialog.question( "I am the wise dude. What is it you would like to know?", [ "What am I supposed to do here?", "How does fighting work?", "Any hints on getting started?", "This seems too simple, is that it?" ]) if choice == 0: dialog.message("You're job is to destroy the evil Minotaur. " + "He lives in a cave north of town. You'll find " + "him on the 20th level. Yeah, its a big cave. " + "Should be pretty easy to find him though, the " + "levels are mostly just stops between stairs. " + "No one knows why he'd want to keep digging like " + "that, seems like it would be a pain to go up " + "and down the stairs all the time to mess with us.") elif choice == 1: dialog.message("Its pretty simple really, you can hack, slash, " + "or stab. Each method has a different chance of " + "hitting and does a different amount of damage. " + "Hack is the basic attack. It is the easiest to " + "hit with, but does the least damage. Slash is " + "a little harder to hit with, but does more " + "damage. Stab is the hardest to use, but does " + "the most damage. Now get out there and fight") elif choice == 2: dialog.message("Starting out is always the hardest part. You " + "have nothing but a little money. At least its " + "not zilch. There are two basic strategies for " + "you. Either save the money for the hospital, " + "or go get yourself armor or a weapon and get " + "fighting. If you buy armor, you have a better " + "chance of not getting hit. The weapon will " + "allow you to hit more often and do more damage. " + "I'd go with the weapon, personally, since the " + "early fights will be shorter and you won't have " + "as many opportunities to get hurt.") dialog.message("At the very beginning, you'll want to stick to " + "the area right outside of town. Then come back " + "to town after each fight. Heal and save, that " + "sort of thing. After you have a couple of " + "levels under your belt, and some decent " + "equiptment, you can head to the cave. Fight on " + "each level until you are comfortable with the " + "risk. That doesn't mean hang around levels " + "with no challenge! You won't get anywhere here " + "unless you take risks. The deeper you go into " + "the cave, the more money and experience you get.") elif choice == 3: dialog.message("Ummm... That really is about it. Oh yeah, if " + "you do manage to get rid of the evil Minotaur, " + "we'll make you mayor and all the girls will " + "want you. As mayor, you'll also have a nice " + "retirement plan and good benefits. The pay " + "isn't the greatest, but you'll get to live in " + "the town hall and have servants and food " + "provided for you. All in all, not a bad gig.")
def do_sell(self): all_items = core.game.save_data.hero.get_inventory()[:] items = filter(lambda x: x.get_value()>0, all_items) item_names = map(self.sell_text, items) item_names.append('Never mind') choice = dialog.question('Select the item you are interested in selling:', item_names) if choice == len(items): return else: item = items[choice] hero = core.game.save_data.hero hero.get_inventory().remove(item) hero.add_gold( int(item.get_value()*self.sell_factor) ) dialog.message('A bargain at twice the price!')
def fight_minotaur(self): monster = combat.gallery.get_monster('The evil Minotaur') hero = core.game.save_data.hero fight = combat.Combat(hero, monster) result = fight.run() if result == 'win': dialog.message('You breathe a sigh of relief at the sight of the once mighty ' + 'and fearsome minotaur lying defeated on the floor of his throne-room. ' + 'By your victory, you have secured freedom for your village and broken the ' + 'siege by the forces of darkness.'); dialog.message('Well, at least until they rise again. Dark forces have a ' + 'nasty habit of doing that. But by then, perhaps there will be a sequel.') self.end_game() else: self.end_game()
def activate(self): action = dialog.question(self.intro, ('I have an item to sell', 'I would like to make a purchase', 'Never mind')) if action == 0: self.do_sell() elif action == 1: choice = dialog.question('Select the item your heart desires:', self.item_names) if choice >= len(self.item_names)-1: dialog.message("Come back when you are ready to order!") return item = self.item_list[choice] hero = core.game.save_data.hero if item.value <= hero.get_gold(): hero.add_gold( -item.get_value() ) self.purchased(item) else: dialog.message('Come back when you have accumulated enough gold!')
def gain_level(self): self.level = self.level + 1 attribute = dice.roll('1d3') if attribute==1: self.strength = self.strength + 3 new_val = self.strength message = 'strength' elif attribute==2: self.agility = self.agility + 3 new_val = self.agility message = 'agility' elif attribute==3: self.vitality = self.vitality + 3 new_val = self.vitality message = 'vitality' self.exp_to_next_level = self.exp_to_next_level * 1.5 text = 'You have advanced to level %d. Your %s has increased to %d.' dialog.message(text % (self.level, message, new_val)) self.recalculate()
def walk_in_front_of_dude(self): dialog.message("You stand before the wise dude! Here is a lot " + "of text that you will need to split across at " + "least two lines, perhaps several more! And as " + "a special feature, if this first line is longer " + "than the next dialog, then it will even be trimmed " + "properly!") choice = dialog.question( "Since this is a very very wise man, he has much " + "to say to you. This may even spill over into " + "another dialog!", [ "No, make it stop!", "Yes, Continue!", "I can't decide", "Who knows?" ]) if choice == 0: dialog.message("No! Stopping is not an option!") elif choice == 1: dialog.message("Good, I appreciate your patience.") elif choice == 2: dialog.message("Well, hurry and make up your mind!") elif choice == 3: dialog.message("Ummm.. you're supposed to know that.")
def run(self): monster = self.monster hero = self.hero dialog.message('You have been attacked by a %s!' % monster.get_name()) hero_initiative = hero.get_initiative() monster_initiative = monster.get_initiative() while True: if hero_initiative > monster_initiative: monster_initiative = monster_initiative + monster.get_initiative() action = dialog.question('What is your bidding?', \ ( 'Hack', 'Slash', 'Stab' )) if action == 0: thaco = hero.get_thaco() - 2 mult = 1.0 elif action == 1: thaco = hero.get_thaco() mult = 1.5 elif action == 2: thaco = hero.get_thaco() + 2 mult = 2.0 if thaco - monster.ac <= dice.roll('1d20'): damage = int(hero.weapon.get_damage() * mult * hero.strength / 10.0) if monster.damage(damage): gold = monster.get_gold() hero.add_gold(gold) hero.gain_exp(monster.get_exp_value()) mess = 'You hit the %s for %d points of damage, ' + \ 'killing it! You find %d gold. For valor ' + \ 'in combat, you receive %d experience points.' mess = mess % (monster.get_name(), damage, gold, monster.get_exp_value()) dialog.message(mess) hero.check_level() return 'win' else: dialog.message('You hit the %s for %d points of damage.' % \ (monster.get_name(), damage)) else: dialog.message('You missed!') else: hero_initiative = hero_initiative + hero.get_initiative() if monster.thaco - hero.get_ac() <= dice.roll('1d20'): damage = monster.do_damage() message = monster.damage_text(damage) if hero.damage(damage): dialog.message(message + ' You have died!') return 'lose' else: dialog.message(message) else: dialog.message('The %s misses you!' % monster.get_name())
def activate(self): dialog.message(self.dialog_text[self.current_dialog]) self.current_dialog = self.current_dialog + 1 if self.current_dialog >= len(self.dialog_text): self.current_dialog = 0
def end_game(self): dialog.message('Thanks for playing Hack ''n Slash!') self.running = False core.game.quit()