omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. resserone13v2.0

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    R
    • Profile
    • Following 4
    • Followers 0
    • Topics 1
    • Posts 2
    • Best 0
    • Controversial 0
    • Groups 0

    resserone13v2.0

    @resserone13v2.0

    0
    Reputation
    3
    Profile views
    2
    Posts
    0
    Followers
    4
    Following
    Joined Last Online

    resserone13v2.0 Unfollow Follow

    Latest posts made by resserone13v2.0

    • RE: update and print list

      @cvp yes it worked perfect i used

      items = ''.join(str(item) for item in self.items)
      

      I did not add the + at the end of the f strings. it seems to be working fine.

      Thanks for your help.

      Ever since is been using Pythonista I've received lots of great help from the all of you in the forum.

      posted in Pythonista
      R
      resserone13v2.0
    • update and print list

      Im working on a game. its a remake of the nes game spy vs spy.

      when i print the self.items list its just giving me a memory loc. i made str method but im missing some thing. its hard to keep track of the player items without seeing the name and being able to update them.
      it currently prints like this

      ITEMS: <generator object Spy.__str__.<locals>.<genexpr> at 0x0000016C796456D0>
      
      class Game():
          def __init__(self):
              pass
      
          def move(self):
              pass
      
      
      class Room():
          def __init__(self, exit_to_plane, furniture, doors):
              self.exit_to_plane = False
              self.furniture = []
              self.doors = doors
      
      
      class Spy():
          def __init__(self):
              self.health = 100
              self.items = []
              self.able_to_fly = False
      
          def fly_airplane(self):
              if key not in self.items:
                  self.able_to_fly = True
      
          def pick_up_item(self, item):
              self.items.append(item)
      
          def remove_item(self, item):
              self.items.remove(item)
      
          def switch_weapons():
              pass
      
          def use_weapon(self, item):
              item.item_quantity -= 1
      
          def __str__(self):
              return (
                  f'HEALTH: {self.health}\n'
                  f'ITEMS: {print(item) for item in self.items}\n'
                  f'ABLE TO FLY: {self.able_to_fly}\n'
                  )
      
      
      class Item():
          def __init__(self, name, type, damage_amount, quantity):
              self.name = name
              self.type = type
              self.damage_amount = damage_amount
              self.item_quantity = quantity
      
          def __str__(self):
              return (
                  f'NAME: {self.name}\n'
                  f'TYPE: {self.type}\n'
                  f'DAMAGE AMOUNT: {self.damage_amount}\n'
                  f'item_quantity: {self.item_quantity}\n'
                  )
      
      
      # Items
      knife = Item('knife', 'weapon', 2, None)
      bomb = Item('bomb', 'weapon', 5, 2)
      oil_can = Item('oil can', 'weapon', 3, 1)
      key = Item('Key', 'key', 0, 1)
      
      print('ITEMS:')
      print(knife)
      print(bomb)
      print(oil_can)
      print(key)
      print()
      
      # Spies
      spy1 = Spy()
      spy2 = Spy()
      spy1.pick_up_item(Item('knife', 'weapon', 2, 1000))
      spy1.pick_up_item(key)
      spy1.fly_airplane()
      
      print('SPIES:')
      print('SPY 1')
      print(spy1)
      print('SPY 2')
      print(spy2)
      print()
      
      spy1.remove_item(key)
      spy1.fly_airplane()
      print(spy1)
      
      # Use an item
      
      print(bomb)
      
      
      
      posted in Pythonista
      R
      resserone13v2.0