Created
September 10, 2017 13:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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