Esempio n. 1
0
 def generate(self):
     #description item and gold
     description = self.get_room_description()
     gold = random.randrange(101)
     #generate creature
     chance = random.randrange(1000)
     if( chance > 300 ):
         cf = Creature_Factory()
         creature = cf.generate()
     else:
         creature = None
     #generate items
     items = list()
     itf = Item_Factory()
     items.append( itf.generate() )
     wf = Weapon_Factory()
     items.append( wf.generate() )
     af = Armor_Factory()
     items.append( af.generate() )
     return Room( description, creature, items, gold )
Esempio n. 2
0
    def execute(self):
        #allow these commands regardless
        creature = self.level.get_current_room().creature
        if( self.command == "help" ):
            self.execute_help()
        elif( self.command == "vhelp" ):
            self.execute_vhelp()
        elif( self.command == "map" ):
            self.execute_map()
        elif( self.command == "look-around" ):
            self.execute_lookaround()
        elif( self.command == "study" ):
            self.execute_study()
        elif( self.command[0:9] == "inventory" ):
            self.execute_inventory()
        elif( self.command[0:7] == "inspect" ):
            self.execute_inspect()
        elif( self.command == "switch-weapon" ):
            self.execute_switch_weapon()
        elif( self.command == "switch-armor" ):
            self.execute_switch_armor()
        elif( self.command == "status" ):
            self.execute_status()
        #if there are NO creatures in the room, then allow these
        #command    
        elif( self.level.get_current_room().creature == None ):
            if( self.command == "pickup" ):
                self.execute_pickup()
            elif( self.command[0:4] == "drop" ):
                self.execute_drop()
            elif( self.command == 'use-potion' ):
                self.execute_use_potion()
            elif( self.command == 'buy-attribute' ):
                self.execute_buy_attribute()

            #possibly generate mob since there is no creature in a room
            if( creature == None and self.level.mob_size > 0):
                if( random.randrange(100) > 80 ):
                    cf = Creature_Factory()
                    c = cf.generate()
                    self.level.get_current_room().creature = c
                    self.level.mob_size -= 1
                    print c.name + " entered the room!"

        #if there is a creature in the room, then allow these commands
        elif( self.level.get_current_room().creature != None ):
            if( self.command == "flee" ):
                self.execute_flee()
            elif( self.command == "attack" ):
                self.execute_attack()
            elif( self.command == "magic-attack" ):
                self.execute_magic_attack()
            elif(self.command == 'use-potion' ):
                self.execute_use_potion()

        #check if the creature or the player is dead
        if(creature != None):
            if( creature.hp <= 0 ):
                diff = creature.level - self.player.level
                xp = 0
                if diff >= 0:
                    xp = creature.calc_experience() * (diff+1)
                else:
                    tmp = (diff * -20) // 100
                    xp = int(creature.calc_experience() * tmp)

                self.player.grant_xp(xp)
                print "You gained %s XP for slaying the" % xp,
                print creature.name + "."
                print "You collected %s gold coins from the corpse." % creature.gold
                self.player.gold += creature.gold
                tf = Treasure()
                treasure = tf.generate(creature.level)
                for t in treasure:
                    self.level.get_current_room().item.append(t)
                for p in creature.all_equipment():
                    self.level.get_current_room().item.append(p)

                self.level.get_current_room().creature = None
        if(self.player.hp <= 0):
            print "Game Over! You died sucka!"
            sys.exit()