예제 #1
0
 def get_inventory(player_id):
     conn = None
     try:
         conn = psycopg2.connect(host="localhost",
                                 database="roleplay",
                                 user="******",
                                 password="******")
         cur = conn.cursor()
         sql = 'SELECT weapon.id, weapon.name, weapon.rang_id, weapon.power, player_has_weapon.id FROM ' \
               'player_has_weapon JOIN weapon ON player_has_weapon.weapon_id = weapon.id ' \
               'where player_has_weapon.player_id = %s '
         cur.execute(sql, (player_id, ))
         records = cur.fetchall()
         items = []
         for record in records:
             item = Weapon(name=record[1],
                           rang=record[2],
                           power=record[3],
                           item_id=record[4])
             items.append(item)
         sql = 'SELECT armor.id, armor.armor_type, armor.name, armor.rang_id, armor.defense, player_has_armor.id FROM ' \
               'player_has_armor JOIN armor ON player_has_armor.armor_id = armor.id ' \
               'where player_has_armor.player_id = %s '
         cur.execute(sql, (player_id, ))
         records = cur.fetchall()
         for record in records:
             item = Armor.armor_from_db(armor_type_name=record[1],
                                        name=record[2],
                                        rang=record[3],
                                        defense=record[4],
                                        item_id=record[5])
             items.append(item)
         sql = 'SELECT potion.id, potion.name, rang.meaning, potion.effect_type_id, ' \
               ' potion_effect.meaning, ' \
               'potion.value FROM potion ' \
               'JOIN player_has_potion ON potion.id = player_has_potion.potion_id ' \
               'JOIN potion_effect ON potion_effect.id = potion.effect_type_id ' \
               'JOIN rang ON potion.rang_id = rang.id ' \
               'WHERE player_id = %s AND player_has_potion.used = false'
         cur.execute(sql, (player_id, ))
         records = cur.fetchall()
         for record in records:
             item = Potion.potion_from_db(name=record[1],
                                          rang=record[2],
                                          effect_name=record[4],
                                          effect_value=record[5])
             items.append(item)
         cur.close()
         return Inventory(items)
     except (Exception, psycopg2.DatabaseError) as error:
         print(error)
     finally:
         if conn is not None:
             conn.close()
def unpack_potions_into_objects(buff_output_dictionary):
    """unpacks potion attributes into objects within a dictionary"""

    output_potion_dictionary = {}

    for potion_key in potion_attribute_dictionary:
        potion_attributes = potion_attribute_dictionary[potion_key]
        potion_buff = buff_output_dictionary[potion_attributes['buff']]

        output_potion_dictionary[potion_key] = Potion(
            potion_attributes['name'], potion_attributes['description'],
            potion_buff, potion_attributes['cost'])

    return output_potion_dictionary
예제 #3
0
def make_shop(gauntletNum):
    if gauntletNum <= 5:
        itemLevel = 5
    else:
        itemLevel = gauntletNum + 1

    shopItems = []
    shopItems.append(Potion(itemLevel, randint(2, 5)))
    shopItems.append(Ether(itemLevel, randint(2, 5)))
    shopItems.append(Spear(itemLevel, randint(1, 6)))

    shop = Shop(shopItems)

    return shop
예제 #4
0
 def add(self):
     if self.Whattime >= 1.3:
         new_fireball1 = FireBall1()
         FB5.append(new_fireball1)
         new_fireball2 = FireBall2()
         FB5.append(new_fireball2)
         new_fireball3 = FireBall3()
         FB5.append(new_fireball3)
         new_fireball4 = FireBall4()
         FB5.append(new_fireball4)
         self.Whattime = 0
     if self.potintime >= 3.3 :
         new_potion = Potion()
         potion.append(new_potion)
         self.potintime =0
     if self.itemtime >= 2:
         new_item = Coin()
         item.append(new_item)
         self.itemtime = 0
예제 #5
0
from room import Room
from player import Player
from item import Potion
from item import Treasure

# Declare items
hp1 = Potion("Potion", "Adds +1 to your Health", "health 1")
bc = Treasure("Coin", "Bronze coin worth 5 coins", "coin", 5)
rg = Treasure("Gem", "A shiny red gem worth 10 coins", "gem", 10)

#item sets
item_set1 = [bc]
item_set2 = [bc, rg]
item_set3 = [bc, rg, hp1]
item_set4 = [rg, hp1]
# Declare all the rooms

outside = Room("Outside Cave Entrance", "North of you, the cave mount beckons",
               [])

foyer = Room(
    "Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", item_set1)

overlook = Room(
    "Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""", item_set3)

narrow = Room(
    "Narrow Passage", """The narrow passage bends here from west
예제 #6
0
class Room:
    def __init__(self, door, info_text):
        self.exit = door
        self.items = []
        self.creatures = []
        self.info_text = info_text

    def inspect_items(self):
        return ', '.join(x.name for x in self.items)

    def inspect_creatures(self):
        return ', '.join(['a ' + x.species for x in self.creatures if not x.is_player])

    def describe(self):
        return 'You are standing in {}. {}.'.format(self.info_text, self.exit)


if __name__ == '__main__':
    start = Room('a door', 'a dark room')
    player = Creature('Li', 'human')
    monster = Creature('Klarg', 'hugbear')
    p = Potion()
    w = Weapon()
    start.creatures.append(player)
    start.creatures.append(monster)
    start.items.append(p)
    start.items.append(w)
    print(start.describe())
    print(start.inspect_creatures())
    print(start.inspect_items())
예제 #7
0
from skill import *
from fighter import *
from move import *

armor = Armor('shield', 'F', 100, ArmorType.shield.value)
equipment1 = Equipment(shield=armor)
equipment2 = Equipment(weapon=Weapon('sword', 'F', 120))
player1 = Player(10, 'Ivan', 63, 63, 20, 15, 40, 40, 10, [
    ActiveSkill('knife', 'F', 'first skill', 5,
                ActiveSkillEffect(15, ActiveSkillEffectType.damage.value))
], [
    PassiveSkill(
        'power increase', 'F', 'first passive skill',
        PassiveSkillEffect(5, PassiveSkillEffectType.increase_power.value))
], equipment1, Inventory([]), [
    Potion('power buff', 'F', PotionEffect(500, PotionEffectType.power.value))
])
player2 = Player(12, 'Igor', 60, 60, 21, 16, 45, 45, 11, [
    ActiveSkill('knife', 'F', 'first skill', 5,
                ActiveSkillEffect(15, ActiveSkillEffectType.damage.value))
], [
    PassiveSkill(
        'defense increase', 'F', 'increases your defense',
        PassiveSkillEffect(6, PassiveSkillEffectType.increase_defense.value))
], equipment2, Inventory([]), [
    Potion('defense buff', 'F',
           PotionEffect(600, PotionEffectType.defense.value))
])
fighter = Fighter(player1, player2)

while True:
예제 #8
0
def teatime_with_klarg():
    ext = Room('Before you is a heavy stone gate',
               'a large, open field, facing a stone wall')
    first_chamber = Room(
        'There is a trap door in the floor',
        'a massive stone walled chamber. There is dust on the walls, and the room is lit by an extravagant but tattered chandelier'
    )
    second_chamber = Room(
        'In the middle of the room sits a glittering gold chest',
        'a small dirt room')
    chest = Room('', 'In the golden chest, you find: ')
    p_name = input('What is your name? ')
    p_species = input('What type of creature are you? ')
    player = Creature(p_name, p_species, is_player=True)
    ext.creatures.append(player)
    klarg = Creature('Klarg', 'Hugbear')
    first_chamber.creatures.append(klarg)
    pot = Potion()
    chest.items.append(pot)

    print(ext.describe())
    sleep(2)
    print('You are {}.'.format(player.describe()))
    sleep(2.5)
    while True:
        if player.weapon:
            choice = input(
                'What would you like to do? O for open gate, Q for quit, D for drop weapon. '
            ).upper()
        else:
            choice = input(
                'What would you like to do? O for open gate, Q for quit. '
            ).upper()
        if choice == 'O':
            break
        elif choice == 'D':
            ext.items.append(player.weapon)
            player.drop_weapon()
            print('You are unarmed.')
            sleep(1.5)
            print('On the ground, you see {}'.format(ext.items[0].describe()))
            sleep(1.5)
            choice = input(
                'Enter I to put the weapon in your inventory, E to equip it, or L to leave it on the ground: '
            ).upper()
            if choice == 'I':
                player.store_item(ext.items[0])
            elif choice == 'E':
                player.equip_weapon(ext.items[0])
                sleep(1.5)
                print('You are armed with {}.'.format(player.weapon.name))
            elif choice == 'L':
                pass
            continue
        elif choice == 'Q':
            print('Goodbye!')
            sleep(1.5)
            exit()
        else:
            print('That wasn\'t a valid entry.')
            continue
    print(first_chamber.describe())
    sleep(3)
    ext.creatures.remove(player)
    first_chamber.creatures.append(player)
    print('In the room you see {}.'.format(first_chamber.inspect_creatures()))
    sleep(1.5)
    print('The {} says "Hello, my name is {}!"'.format(klarg.species,
                                                       klarg.name))
    sleep(1.5)
    print('{}: Welcome to my home! Would you like some tea?'.format(
        klarg.name))
    sleep(1.5)
    while True:
        choice = input('Enter Y for yes or N for no thank you: ').upper()
        if choice == 'Y':
            print('{}: I have sleepytime. Let me get you some.'.format(
                klarg.name))
            sleep(1.5)
            print('You and {} the {} have a nice cup of tea together.'.format(
                klarg.name, klarg.species))
            break
        elif choice == 'N':
            print(
                '{}: You come into my house, looking for my treasure, I assume, and you won\'t even sit and drink a cup of tea with me?'
                .format(klarg.name))
            sleep(2.5)
            print('{} looks offended.'.format(klarg.name))
            sleep(1.5)
            print('{}: Please leave.'.format(klarg.name))
            sleep(1.5)
            print(
                '{} escorts you out. You have lost the game and will not get the treasure.'
                .format(klarg.name))
            sleep(1.5)
            exit()
        else:
            print('That wasn\'t a valid entry.')
            continue
    sleep(1.5)
    print('{}: I assume you\'re here for the treasure? '.format(klarg.name))
    sleep(1.5)
    while True:
        choice = input('Enter Y for yes or N for no: ').upper()
        if choice == 'Y':
            print('{}: Right this way.'.format(klarg.name))
            sleep(1.5)
            print('{} opens the trap door.'.format(klarg.name))
            break
        elif choice == 'N':
            print(
                'You and {} have another cup of tea, then you go home. You didn\'t get the treasure, but you made a new friend.'
                .format(klarg.name))
            sleep(1.5)
            exit()
        else:
            print('That wasn\'t a valid entry.')
            continue
    sleep(1)
    while True:
        choice = input(
            'Enter D to go down into the trap door, or S to stay up here: '
        ).upper()
        if choice == 'D':
            first_chamber.creatures.remove(player)
            first_chamber.creatures.remove(klarg)
            second_chamber.creatures.append(player)
            second_chamber.creatures.append(klarg)
            print(second_chamber.describe())
            break
        elif choice == 'S':
            sleep(2.5)
            print('{} closes the trap door.'.format(klarg.name))
            sleep(1.5)
            print('{}: You changed your mind? Ok!'.format(klarg.name))
            sleep(1.5)
            print(
                'You and {} have another cup of tea, then you go home. You didn\'t get the treasure, but you made a new friend.'
                .format(klarg.name))
            sleep(1.5)
            exit()
        else:
            print('That wasn\'t a valid entry.')
            continue
    sleep(1.5)
    while True:
        choice = input('Enter O to open the chest, or L to leave: ').upper()
        if choice == 'O':
            print(chest.info_text)
            sleep(1.5)
            print('...')
            sleep(.7)
            print('...')
            sleep(.7)
            print(chest.items[0].name)
            break
        elif choice == 'L':
            print('{}: You changed your mind? Ok!'.format(klarg.name))
            sleep(1.5)
            print(
                'You and {} have another cup of tea, then you go home. You didn\'t get the treasure, but you made a new friend.'
                .format(klarg.name))
            sleep(1.5)
            exit()
        else:
            print('That wasn\'t a valid entry.')
            continue
    sleep(1)
    while True:
        choice = input(
            'Enter I to put the potion in your inventory, D to drink the potion, or L to leave: '
        ).upper()
        if choice == 'L':
            print('{}: You changed your mind? Ok!'.format(klarg.name))
            sleep(1.5)
            print(
                'You and {} have another cup of tea, then you go home. You didn\'t get the treasure, but you made a new friend.'
                .format(klarg.name))
            sleep(1.5)
            exit()
        elif choice == 'D':
            sleep(1.5)
            print(player.drink_potion(chest.items[0]))
            sleep(1.5)
            print('You have won the game. Congratulations!')
            sleep(1.5)
            exit()
        elif choice == 'I':
            print('You got {}!'.format(chest.items[0].name))
            player.store_item(chest.items.pop())
            sleep(1.5)
            print('Your inventory: {}'.format(player.show_inventory()))
            sleep(1.5)
            print('You have won the game. Congratulations!')
            sleep(1.5)
            exit()
        else:
            print('That wasn\'t a valid entry.')
            continue