import random
class Planet:
def init(self, name, resource, price):
self.name = name
self.resource = resource
self.price = price
class Player:
def init(self, name):
self.name = name
self.resources = 100 # Starting resources
self.cargo = 0 # Cargo space
self.current_planet = None
def move_to(self, planet):
self.current_planet = planet
print(f"{self.name} has moved to {planet.name}.")
def trade(self, amount):
if amount > self.cargo:
print("Not enough cargo space!")
return
if amount * self.current_planet.price > self.resources:
print("Not enough resources!")
return
self.resources -= amount * self.current_planet.price
self.cargo += amount
print(f"{self.name} traded {amount} units of {self.current_planet.resource}.")
def sell(self, amount):
if amount > self.cargo:
print("Not enough cargo to sell!")
return
self.resources += amount * self.current_planet.price
self.cargo -= amount
print(f"{self.name} sold {amount} units of {self.current_planet.resource}.")
def main():
# Create planets
planets = [
Planet("Earth", "Food", 10),
Planet("Mars", "Metal", 20),
Planet("Venus", "Water", 15)
]
# Create player
player_name = input("Enter your name: ")
player = Player(player_name)
# Game loop
while True:
print(f"\n{player.name}'s Resources: {player.resources}, Cargo: {player.cargo}")
print("Current Planet:", player.current_planet.name if player.current_planet else "None")
print("Available Planets:")
for i, planet in enumerate(planets):
print(f"{i + 1}. {planet.name} (Resource: {planet.resource}, Price: {planet.price})")
action = input("Choose an action: (M)ove, (T)rade, (S)ell, (Q)uit: ").upper()
if action == 'M':
planet_choice = int(input("Choose a planet number to move to: ")) - 1
if 0 <= planet_choice < len(planets):
player.move_to(planets[planet_choice])
else:
print("Invalid planet choice.")
elif action == 'T':
amount = int(input(f"How much {player.current_planet.resource} do you want to trade? "))
player.trade(amount)
elif action == 'S':
amount =
[–]WoodyWoodPecker[S] 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 0 fun2 insightful - 1 fun - (0 children)