Jun-22-2019, 10:55 PM
I'm following this video series but I seem to have messed up at some point. The error is at line 70. Can anyone spot where I have gone wrong?
import os
import datetime
from product import product
from city import City
MENU_DIVIDER = "-----------------------------"
GAME_TITLE = "Python Pirate Trader"
def welcome_message():
print("Welcome to Pirate Trader")
def get_firm_name():
#firm_name = input ("Please enter your firm: ")
return "Testing firm"
def get_starting_options():
#starting_options = input("How do you wish to start. 1) Cash & Debt 2) Cannons and no Debt.:")
starting_options = "1"
if starting_options == "1":
opts = (250,250,0)
else:
opts = (0,0,5)
return opts
def leave_port(city_list, current_date):
i = 1
for city in city_list:
print("{0}) {1}".format (i,city.name))
i += 1
select_city = input ("Which city do you wish to go to?: ")
current_date += datetime.timedelta(days=1)
return city_list[int(select_city)-1], current_date
def buy():
input("What do you want to buy?")
def sell():
input("What do you want to sell?")
def visit_bank():
input("How much to transfer to the bank?:")
def display_products():
for product in Product.products:
print(product.name + "--" + str(product.price))
class product(object):
products = []
def __init__(self, name, minprice, maxprice):
self.name = name
self.minprice = minprice
self.maxprice = maxprice
self.price = random.randint(self.minprice,self.maxprice)
@classmethod
def create_products(cls):
cls.products.append(Product("General Goods", 3, 20))
cls.products.append(Product("Arms", 3, 20))
class City(object):
cities = []
def __init__(self, name, has_warehouse, has_bank):
self.name = name
self.has_warehouse = has_warehouse
self.has_bank= has_bank
@classmethod
def create_cities(cls):
cls.cities.append(City("Hong Kong",True, True))
cls.cities.append(City("Shanghai", False, False))
cls.cities.append(City("London", False, False))
'#' # Create Products
Product.create_products()
City.create_cities()
'#'# Start Game
welcome_message()
firm_name = get_firm_name()
cash, debt, cannons = get_starting_options()
current_city = City.cities[0]
game_running = True
current_date = datetime.datetime(1820,1,1,0,0,0)
while game_running:
'#'# Display Main Game Interface
os.system("cls")
# Stuff to Debug
# ---------------
print(MENU_DIVIDER)
print(GAME_TITLE)
print(MENU_DIVIDER)
print("Firm Name: %s" % firm_name)
print("Cash: {}".format(cash))
print(f"Debt: {debt}")
print("Cannons: %d" % cannons)
print("City: %s" % current_city["City.name"])
print("Date: {:%B %d, %Y}".format(current_date))
print(MENU_DIVIDER)
print("------City Products-----")
display_products()
has_bank_string = ""
if current_city.has_bank == True:
has_bank_string = "V)isit the Bank,"
print("Menu: L)eave Port, B)uy, S)ell, T)ransfer Warehouse, %s Q)uit" % has_bank_string)
menu_option = input("What is your option")
if menu_option == "L":
current_city, current_date = leave_port(City.cities, current_date)
elif menu_option == "B":
buy()
elif menu_option == "S":
sell()
elif menu_option == "V" and current_city.has_bank == True:
visit_bank()
elif menu_option == "Q":
game_running = False
