Question: Using Python I am creating a city war game but i am stuck, I would like for my code to do the following, everytime i

Using Python
I am creating a city war game but i am stuck, I would like for my code to do the following, everytime i upgrade a building to add experience to the player, also to start a clock from the moment the game starts, for a minute to equal and hour and so forth... and to make my code more readable
#Michal Albarran
#City Wars Game
import random
from sys import exit
class Commander:
def __init__(self, name, strength =0, skills =0, experience=0):
self.name = name
self.strength = strength
self.skills = skills
self.experience = experience
def show_playerStatus(self):
print(f"Player Stats: {self.name}
"
f"Strength: {self.strength}
"
f"Skills: {self.skills}
"
f"Experience: {(self.experience)}
")
class Building:
def __init__(self, name, cost, population_increase, level=1):
self.name = name
self.cost = cost
self.population_increase = population_increase
self.level = level
def upgrade(self):
if self.level <30:
self.level +=1
self.cost *=1.5
self.population_increase *=1.25
print(f"{self.name} upgraded to Level {self.level}.")
else:
print(f"{self.name} is already at the maximum level.")
class Clock:
def __init__(self):
self.current_day =0
self.current_time =0
def pass_day(self):
self.current_day +=1
print(f"Day {self.current_day}: A new day has begun.")
def pass_time(self, hours):
self.current_time += hours
print(f"Time passed: {hours} hours. Current time: {self.current_time %24}:00")
class City:
def __init__(self, name):
self.name = name
self.buildings =[]
self.money =100000
self.population =0
self.clock = Clock()
self.city_level =1
def pass_day(self):
self.clock.pass_day()
self.money +=150* self.population
print(f"A day has passed. Money increased by {150* self.population}. Total money: {self.money}")
def add_building(self, building):
self.buildings.append(building)
self.money -= building.cost
self.population += building.population_increase
print(f"{building.name} added to {self.name}.")
def upgrade_building(self, building_name):
for building in self.buildings:
if building.name == building_name:
self.money -= building.cost *0.5
building.upgrade()
self.check_city_upgrade()
return
print("Building not found.")
def check_city_upgrade(self):
# Simplistic condition: upgrade city level if all buildings are above level 1
if all(building.level >1 for building in self.buildings):
self.city_level +=1
print(f"City upgraded to Level {self.city_level}.")
def show_status(self):
print(f"City: {self.name}
"
f"Money: {self.money}
"
f"Population: {self.population}
"
f"Buildings: {len(self.buildings)}
"
f"City Level: {self.city_level}
"
f"Current Day: {self.clock.current_day}
"
f"Current Time: {self.clock.current_time}")
def main():
while True:
user_input = input("Would you like to play City Wars Game? yes/no: ")
if user_input.lower()== "yes":
city = City('level?')
break
elif user_input.lower()=="no":
print("Goodbye!")
exit()
else:
print("Invalid input. Please try again.")
while True:
commander_choice = input("Would you like to choose a commander? yes/no: ")
if commander_choice.lower()== "yes":
commander_name = input("Enter commander's name: ")
commander = Commander(commander_name)
break
elif commander_choice.lower()=="no":
commander_name = str(
random.randint(1000000000,9999999999))
commander = Commander(commander_name)
print(f"Commander's name: {commander.name}")
break
else:
print("Invalid input. Please try again.")
print("welcome "+ commander_name.upper(),"to City Wars")
while True:
action = input("
Choose an action type either (CITY INFORMATION or CONTINUE): ").lower()
if action == "city information":
city.show_status()
break
elif action == "continue":
commander.show_playerStatus()
else:
print("Invalid input")
continue
while True:
print(
"
1. Add Building
2. Upgrade Building
3. Show Status
4. Show Houses
5. Show Farms
6. Pass Day
7. Pass Time
8. Exit")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!