import random
class Game:
def __init__(self):
self.day = 1
self.money = 1000
self.inventory = {}
self.drugs = {
'Weed': {
'buy_price': 50,
'sell_price': 100,
'min_quantity': 5,
'max_quantity': 20,
},
'Cocaine': {
'buy_price': 200,
'sell_price': 400,
'min_quantity': 1,
'max_quantity': 5,
},
'Heroin': {
'buy_price': 300,
'sell_price': 600,
'min_quantity': 1,
'max_quantity': 3,
},
}
self.locations = {
'Home': {},
'Subway Station': {
'drugs': ['Weed', 'Cocaine'],
'police_chance': 0.1,
},
'Park': {
'drugs': ['Weed', 'Heroin'],
'police_chance': 0.2,
},
'Alley': {
'drugs': ['Cocaine', 'Heroin'],
'police_chance': 0.3,
},
'Warehouse': {
'drugs': ['Weed', 'Cocaine', 'Heroin'],
'police_chance': 0.4,
},
}
self.generate_store()
def generate_store(self):
items = []
for drug in self.drugs:
buy_price = random.randint(self.drugs[drug]['buy_price'] // 2, self.drugs[drug]['buy_price'])
sell_price = random.randint(self.drugs[drug]['sell_price'], self.drugs[drug]['sell_price'] * 2)
items.append({'name': drug, 'buy_price': buy_price, 'sell_price': sell_price})
self.locations['Store'] = {'items': items}
def print_inventory(self):
print('Your inventory:')
for drug in self.inventory:
print(f'{drug}: {self.inventory[drug]}')
def print_store(self):
store = self.locations['Store']
print('Store inventory:')
for item in store['items']:
print(f"{item['name']}: Buy for {item['buy_price']}, sell for {item['sell_price']}")
def print_money(self):
print(f'You have ${self.money}')
def print_day(self):
print(f'Day {self.day}')
def print_location(self, location):
print(f'You are at {location}')
def get_location(self):
return random.choice(list(self.locations.keys()))
def get_drug_quantity(self, drug):
return random.randint(self.drugs[drug]['min_quantity'], self.drugs[drug]['max_quantity'])
def get_price(self, drug, buy=True):
price = self.locations['Store']['items'][self.drugs.index(drug)][buy ? 'buy_price' : 'sell_price']
return price
def buy_drug(self, drug, quantity):
if self.money >= self.get_price(drug, True) * quantity:
if drug in self.inventory:
self.inventory[drug] += quantity
else:
self.inventory[drug] = quantity
self.money -= self.get_price(drug, True) * quantity
print(f'You bought {quantity} {drug}(s) for ${self.get_price(drug, True) * quantity}')
else:
def sell_drug(self, drug, quantity):
if drug in self.inventory and self.inventory[drug] >= quantity:
self.inventory[drug] -= quantity
self.money += self.get_price(drug, False) * quantity
print(f'You sold {quantity} {drug}(s) for ${self.get_price(drug, False) * quantity}')
else:
print('You do not have that much of that drug to sell')
def travel(self, location):
if location in self.locations:
self.day += 1
self.print_day()
self.print_location(location)
self.locations[location]['police_chance'] = random.uniform(0, 0.5)
drugs = self.locations[location]['drugs']
for drug in drugs:
quantity = self.get_drug_quantity(drug)
price = self.get_price(drug, True)
print(f'{drug} is available for ${price} per unit (quantity: {quantity})')
else:
print('Invalid location')
def run(self):
print('Welcome to Dope Wars RPG')
print('------------------------')
while True:
self.print_day()
self.print_money()
self.print_inventory()
location = self.get_location()
self.print_location(location)
self.print_store()
action = input('What do you want to do? (buy, sell, travel, quit) ')
if action == 'buy':
drug = input('What drug do you want to buy? ')
quantity = int(input('How many units do you want to buy? '))
self.buy_drug(drug, quantity)
elif action == 'sell':
drug = input('What drug do you want to sell? ')
quantity = int(input('How many units do you want to sell? '))
self.sell_drug(drug, quantity)
elif action == 'travel':
location = input('Where do you want to travel? ')
self.travel(location)
elif action == 'quit':
print('Thanks for playing!')
break
else:
print('Invalid action')