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 initself name, strength skills experience:
self.name name
self.strength strength
self.skills skills
self.experience experience
def showplayerStatusself:
printfPlayer Stats: selfname
fStrength: selfstrength
fSkills: selfskills
fExperience: selfexperience
class Building:
def initself name, cost, populationincrease, level:
self.name name
self.cost cost
self.populationincrease populationincrease
self.level level
def upgradeself:
if self.level :
self.level
self.cost
self.populationincrease
printfselfname upgraded to Level selflevel
else:
printfselfname is already at the maximum level."
class Clock:
def initself:
self.currentday
self.currenttime
def passdayself:
self.currentday
printfDay selfcurrentday: A new day has begun."
def passtimeself hours:
self.currenttime hours
printfTime passed: hours hours. Current time: selfcurrenttime :
class City:
def initself name:
self.name name
self.buildings
self.money
self.population
self.clock Clock
self.citylevel
def passdayself:
self.clock.passday
self.money self.population
printfA day has passed. Money increased by self.population Total money: selfmoney
def addbuildingself building:
self.buildings.appendbuilding
self.money building.cost
self.population building.populationincrease
printfbuildingname added to selfname
def upgradebuildingself buildingname:
for building in self.buildings:
if building.name buildingname:
self.money building.cost
building.upgrade
self.checkcityupgrade
return
printBuilding not found."
def checkcityupgradeself:
# Simplistic condition: upgrade city level if all buildings are above level
if allbuildinglevel for building in self.buildings:
self.citylevel
printfCity upgraded to Level selfcitylevel
def showstatusself:
printfCity: selfname
fMoney: selfmoney
fPopulation: selfpopulation
fBuildings: lenselfbuildings
fCity Level: selfcitylevel
fCurrent Day: selfclock.currentday
fCurrent Time: selfclock.currenttime
def main:
while True:
userinput inputWould you like to play City Wars Game? yesno:
if userinput.lower "yes":
city Citylevel
break
elif userinput.lowerno:
printGoodbye
exit
else:
printInvalid input. Please try again."
while True:
commanderchoice inputWould you like to choose a commander? yesno:
if commanderchoice.lower "yes":
commandername inputEnter commander's name:
commander Commandercommandername
break
elif commanderchoice.lowerno:
commandername str
random.randint
commander Commandercommandername
printfCommanders name: commandername
break
else:
printInvalid input. Please try again."
printwelcome commandername.upperto City Wars"
while True:
action input
Choose an action type either CITY INFORMATION or CONTINUE: lower
if action "city information":
city.showstatus
break
elif action "continue":
commander.showplayerStatus
else:
printInvalid input"
continue
while True:
print
Add Building
Upgrade Building
Show Status
Show Houses
Show Farms
Pass Day
Pass Time
Exit"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
