Skip to content

Instantly share code, notes, and snippets.

@savolla
Created September 10, 2017 13:37
Show Gist options
  • Save savolla/d8ffcc88ea8ec9a2fc289da92c3ced4d to your computer and use it in GitHub Desktop.
Save savolla/d8ffcc88ea8ec9a2fc289da92c3ced4d to your computer and use it in GitHub Desktop.
My first game! also first class (useful class). I'll put similar functions onto my roguelike game later.
class Inventory():
#attributes
capasity = 10
stack = []
#methods
def addItem(self,item):
if len(self.stack) == self.capasity:
print("My stack is full.. gotta get a bigger one.")
else:
self.stack.append(item)
def removeItem(self,item):
if len(self.stack) == 0:
print("My stack is already empty. Nothing to remove..")
else:
self.stack.remove(item)
def showInventory(self):
for i in self.stack:
print(i)
while True:
bag = Inventory()
command = input()
if command == "pick":
bag.addItem("apple")
elif command == "remove":
bag.removeItem("apple")
elif command == "show":
bag.showInventory()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment