class Store():
Money = 5.00
Day = 1
Stores = []
def __init__(self,StoreName,StoreProfit,storecost):
self.StoreName = StoreName
self.StoreCount = 0
self.StoreProfit = StoreProfit
self.StoreCost = storecost
def BuyStore(self):
whichStore = int(input("Which store do you wish to buy?"))
store = Store.Stores[whichStore-1]
if store.StoreCost <= Store.Money:
store.StoreCount+=1
Store.Money -= store.StoreCost
else:
print("You do not have enough money")
@classmethod
def DisplayGameInfo(cls):
print("--------------------")
print("Day # "+str(cls.Day))
print("Money = $"+str(cls.Money))
i = 1
for store in cls.Stores:
store.DisplayStoreInfo(i)
i+=1
def DisplayStoreInfo(self,i):
print("Store name # "+ str(self.StoreName))
print("Money = $"+str(Store.Money))
print("Store Count " + str(self.StoreCount))
print(str(i))
def NextDay(self):
Store.Day+=1
DailyProfit = self.StoreProfit * self.StoreCount
Store.Money += DailyProfit
Store.Stores.append(Store('Lemonade Stand',1.5,3))
Store.Stores.append(Store('Record Store',5,15))
Store.Stores.append(Store('Ice Cream Shop',10,90))
while True:
Store.DisplayGameInfo()
print("Available options N, B, Q")
result = input("Please enter your selection")
if result == 'B' or result == 'b':
Store.Stores[0].BuyStore()
elif result == 'N' or result == 'n':
Store.Stores[0].NextDay()
elif result == 'Q' or result == 'q':
break
else:
print("Bad input")
print("Thank you for playing Python Idle Tycoon")The problem is with the logic inside of of the while loop. Store.Stores[0].BuyStore() and Store.Stores[0].NextDay() Why is the index 0 for Stores - wouldn't that just call the first class everytime? Though, when testing it - it doesn't follow. It doesn't seem to change anything no matter what the index is. I'm afraid I don't understand what's happening here. Secondly. How is Store.Stores[0].NextDay() working at all. I understand you're calling the class store and then the class variable that's a list, but what does that list have to do with NextDay which is its own instance method? If this is TL;DR How is this working? Primarily the '0' Index? From my understanding it should just access the Lemonade Stand everytime.
if result == 'B' or result == 'b':
Store.Stores[0].BuyStore()
elif result == 'N' or result == 'n':
Store.Stores[0].NextDay()
