def __init__(self, x, y): super().__init__(x, y, items.Dagger(), "It's a dagger!")
def __init__(self): self.inventory = [items.Rock(), items.Dagger(), items.Crusty_Bread()] self.gold = 5 self.hp = 100 self.x = 2 self.y = 3
import time import re import creatures as cr import items as it import objects as ob import random brokenSword = it.Longsword('Broken Sword', 'Longsword', 'common', 1, 1, 3, 0.05, 0, 1) dagger = it.Dagger('Dagger', 'Dagger', 'Common', 3, 2, 4, 0.2, 0, 2) axe = it.SmallAxe('Axe', 'Small Axe', 'Common', 5, 3, 6, 0.1, 0, 5) longsword = it.Longsword('Longsword', 'Longsword', 'Common', 5, 4, 7, 0.05, 0, 4) greatsword = it.Greatsword('Greatsword', 'Greatsword', 'Common', 8, 6, 10, 0.1, 0.5, 8) greataxe = it.Greataxe('Greataxe', 'Greataxe', 'Common', 9, 5, 11, 0.15, 0.5, 10) swiftDagger = it.Dagger('Swift Dagger', 'Dagger', 'Uncommon', 7, 3, 7, 0.2, 0, 2) battleAxe = it.SmallAxe('Battle Axe', 'Small Axe', 'Uncommon', 8, 4, 9, 0.1, 0, 5) noblemansSword = it.Longsword('Nobleman\'s sword', 'Longsword', 'Uncommon', 8, 6, 11, 0.05, 0, 4) balancedGreatSword = it.Greatsword('Balanced Greatsword', 'Greatsword', 'Uncommon', 13, 9, 15, 0.1, 0.5, 8) chieftainsGreataxe = it.Greataxe('Chieftain\'s Greataxe', 'Greataxe', 'Uncommon', 12, 8, 14, 0.15, 0.5, 10) shadowStrike = it.Dagger('Shadow Strike', 'Dagger', 'Rare', 23, 8, 14, 0.2, 0, 2) peaceMaker = it.SmallAxe('Peace Maker', 'Small Axe', 'Rare', 28, 11, 17, 0.1, 0, 6)
def __init__(self, x, y): super().__init__(x, y, items.Dagger())
def __init__(self, x, y): #self.beenThere = False super().__init__(x, y, items.Dagger(), beenThere = False)
class Player: def_init_(self): self.inventory = [items.Rock(), items.Dagger(), items.CrustyBread()] self.x = world.start_tile_location[0] self.y = world.start_tile_location[1] self.hp = 100 self.gold = 5 self.victory = False def is_alive(self): return self.hp > 0 def print_inventory(self): print("Inventory:") for item in self.inventory: print("Gold: {}".format(self.gold)) def heal(self): consumables = [item for item in self.inventory if isinstance(iitem, dict_items.Consumable)] if not consumables: print("You don't have any items to heal you!") return for i, item in enumerate(consumables, 1): print("Choose an item to use to heal:") print("{}.{}".format(i,item)) valid = False while not valid: choice = input("") try: to_eat = consumables[int(choice) - 1] self.hp = min(100, self.hp + to_eat.healing_value) self.inventory.remove(to eat) print("Current HP:{}".format(self.hp)) valid = True except (ValueError, IndexError): print("Invalid choice, try again.") def most_powerful_weapon(self): max_damage = 0 best_weapon = None for item in self.inventory: try: if dict_items.damage > max_damage: best_weapon = item max_damage = item.damage except AttributeError: pass return best_weapon def move(self, dx, dy): self.x += dx self.y += dy def move_north(self): self.move(dx=0, dy=-1) def move_south(self): self.move(dx=0, dy=-1) def move_east(self): self.move(dx=1, dy=0) def move_west(self): self.move(dx=-1, dy=0) def attack(self): best_weapon = self.most_powerful_weapon() room = world.tile_at(self.x, self.y) enemy = room.enemy print("You use{} against {}!".format(best_weapon.name, enemy.name)) enemy.hp -= best_weapon.damage if not enemy.is_alive(): print("{} HP is {}.".format(enemy.name, enemy.hp)) def trade(self): room = world.tile_at(self.x, self.y) room.check_if_trade(self)
def __init__(self): self.inventory = [ items.Rock(), items.Dagger(), 'Gold(5)', 'Crusty Bread' ]
def __init__(self): self.name = "Blacksmith" self.gold = 100 self.inventory = [items.Dagger(), items.RustySword(), items.Axe()]
def __init__(self): self.weapon = items.Dagger() self.health = 30 self.name = ork
def __init__(self, x, y): super().__init__(x, y, enemies.Goblin(), items.Dagger())
def __init__(self): self.name = "Blacksmith" self.gold = 120 self.inventory = [items.Dagger(), items.Bow(), items.LongSword()]
class SlimeTile(MapTile): description = "You enter a dimly lit room with a goo that looks like...slime?" enemies = [enemies.BossSlime('e')] class FinalBattle(MapTile): description = "You enter a room that looks to be an arena." enemies = [enemies.BossElf('w', 'e')] normalChest = items.Old_Chest() goldCoins = items.Gold_Coins() goldCoins.Gold_Amount(5) normalChest.contents = [items.Dagger(), goldCoins] bossChest1 = items.Locked_Chest() bossChest1.contents = [items.Flame_Sword(), items.Red_Potion()] class World: # I choose to define the world as a class. This makes it more straightforward to import into the game. map = [ [ SlimeTile(), FinalBattle(), NearVictory(), None, None, FalseVictory(enemies=[enemies.BossOgre('e')], items=[bossChest1]), NearFalseVictory(), None ], [ Corridor(), None,
def __init__(self, name, current_room): super().__init__(name, current_room) self.inventory = [items.Book('red book'), items.Dagger('obsidian dagger'), items.Dagger('silver dagger')]
def __init__(self, game): super().__init__(game, items.Dagger(game))
def __init__(self): self.inventory = [items.Gold(15), items.Dagger()] self.hp = 100 self.location_x, self.location_y = world.starting_position self.outofcave = False self.victory = False
def __init__(self): self.inventory = [items.Rock(), items.Dagger(), items.CrustyBread()] self.x = world.start_tile_location[0] self.y = world.start_tile_location[1] self.hp = 100 self.gold = 5
def enter(self, character): print("As you enter the general store, the sign says:") print("Daggers: 6 coins. Swords: 6 coins. Health potion: 3 coins.") print( "The dagger seems to be fast, but do less damage, where-as the sword is slow but does far greater damage." ) print("The health potions looks like it'll heal you 30hp.") print("Would you like to buy anyting?\n1. Yes\n2. No") user_input = input('> ') if user_input == '1': print( "What would you like to buy?\n1. Sword\n2. Dagger\n3. Health Potion" ) choice = input('> ') if choice == '1': #checks if the character has sufficient coins to purchase the item if character.coins > 5: #if they do have enough, buy the item and remove coins. then add the sword to the characters inventory. character.coins -= 5 print( f"You purchase the sword. You have {character.coins} coins left." ) character.inventory['sword'] = items.Sword() print( "You walk back to the sign to see if there's anything else you want." ) return 'general_store' else: print("Sorry, you can't afford that!") return 'general_store' elif choice == '2': if character.coins > 5: character.coins -= 5 print( f"You purchase the dagger. You have {character.coins} coins left." ) character.inventory['dagger'] = items.Dagger() print( "You walk back to the sign to see if there's anything else you want." ) return 'general_store' else: print("Sorry, you can't afford that!") return 'general_store' elif choice == '3': if character.coins > 2: character.coin -= 2 print( f"You purchase the health potion. You have {character.coins} coins left." ) character.inventory['health-potion'] = items.HealthPotion() print( "You walk back to the sign to see if there's anything else you want." ) return 'general_store' else: print("Sorry, you can't afford that!") return 'general_store' else: print("Not a valid choice, you head back to try again.") return 'general_store' elif user_input == '2': print("You head back out into the town center.") return 'town_center' else: print( 'The shop owner catches you loitering and kicks you out into the town center.' ) return 'town_center'
#setup_world.py import rooms import items import persons #Room A A = rooms.Room('Testroom A') #Room B B = rooms.Room('Testroom B') B.desc = 'Testroom B is kind of an empty test room.' B.items = [items.Dagger('rusty dagger'), items.Ring("white gold ring")] #Room C C = rooms.Room('Testroom C') #Room D D = rooms.Room('Testroom D') #Exits A.exits = {B: ['forest', 'east'], C: ['river', 'north']} B.exits = {A: ['house', 'west'], D: ['shed', 'south']} C.exits = [B, D] D.exits = [A, B, C, D] #Set of rooms in game roomset = {A, B, C, D} #Startroom startroom = B
def modify_player(self, player): player.inventory.append(items.Dagger()) print("Picked up {}".format(items.Dagger()))
def __init__(self, item=items.Dagger(1)): self.item = item super().__init__(item)
def __init__(self, x, y): super(FindDaggerRoom, self).__init__(x, y, items.Dagger())
class OldMan(NPC): name = "Old Man" goods = [ items.Dagger(), items.Red_Potion(value=50), items.Crusty_Bread(value=5) ] quantities = [1, -1, 2] # Set quantity to -1 if you want it to be infinite. description = "An old man in a red robe is standing in the middle of the room." def talk( self ): # Add to this method if you want to be able to talk to your NPC. print( "The old man says: I can sell you an item or two, if you are interested:" ) for item in self.goods: if item.value > 0: if (self.quantities[self.goods.index(item)] > 0): quantity = "quantity = %d" % self.quantities[ self.goods.index(item)] else: quantity = "quantity = unlimited" print("* " + item.name.title() + " (" + str(item.value) + " gold, " + quantity + ")") return "" def give(self, item, inventory): for good in self.goods: if (good == item): inventory.append(good) if (self.quantities[self.goods.index(good)] > 0): self.quantities[self.goods.index(good)] -= 1 for index in reversed(range(len( self.quantities))): # Get rid of items with zero quantity. if (self.quantities[index] == 0): self.quantities.pop(index) self.goods.pop(index) return inventory def first_time( self ): # Used to have your NPC do something different the first time you see them. self.first_encounter = False text = self.description text += " As he holds out a dagger, he says: 'It is dangerous to go alone... take this.'" return text def handle_input(self, verb, noun1, noun2, inventory): if (noun1 == 'old man' or noun1 == 'man'): if (verb == 'check'): return [True, self.check_text(), inventory] elif (verb == 'talk'): text = self.talk() return [True, text, inventory] elif (verb == 'take'): for good in self.goods: if (good.name.lower() == noun1): if (good.value == 0): inventory = self.give(good, inventory) return [ True, "The old man gave you the %s." % good.name, inventory ] else: return [ True, "'Hey, what are you trying to pull? If you want that, the cost is %d gold.'" % good.value, inventory ] return [False, "", inventory]
def __init__(self, x, y): super(FindDaggerRoom, self).__init__(x, y, items.Dagger()) self.id = "Treasure: Dagger"
import items player_inventory = [ items.Rock(), items.WoodenShield(), items.Dagger(), items.Fist(), items.CrustyBread(), items.CrustyBread(), items.Apple(), items.StickWand() ] def get_inventory(): return player_inventory def get_player_inventory(item): player_inventory.append(item)