import random def dice(numdice): success = 0 for i in numdice: x = random.randrange(10) if x >= 5: success++ return success class Company: def __init__(self, mig, tre, inf, ter, sov): self.might = mig self.treasure = tre self.influence = inf self.territory = ter self.sovereignty = sov self.workingMight = mig self.workingTreasure = tre self.workingInfluence = inf self.workingTerritory = ter self.workingSovereignty = sov def reset(self): self.workingMight = self.Might self.workingTreasure = self.treasure self.workingTerritory = self.territory self.workingInfluence = self.influence self.workingSovereignty = self.sovereignty def attack(self, target): if self.workingMight > 0 && self.workingTreasure > 0: attackdice = self.workingMight + self.workingTreasure defencedice = target.might + target.territory attacksuccess = dice(attackdice) defencesuccess = dice(defencedice) if attacksuccess > defencesuccess: print("Attack was a success") else: print("Attack was a failure") self.workingMight-- self.workingTreasure-- else: print("Might or Treasury has been used too many times this round") def terror(self, target): if self.workingMight > 0 && self.workingInfluence > 0: attackdice = self.workingMight + self.workingInfluence defencedice = target.might + target.sovereignty attacksuccess = dice(attackdice) defencesuccess = dice(defencedice) if attacksuccess > defencesuccess: print("Terror was a success") else: print("Terror was a failure") self.workingMight-- self.workingInfluence-- else: print("Might or Influence has been used too many times this round") def spy(self, target): if self.workingTreasure > 0 && self.workingInfluence > 0: attackdice = self.workingTreasure + self.workingInfluence defencedice = target.influence + target.territory attacksuccess = dice(attackdice) defencesuccess = dice(defencedice) if attacksuccess > defencesuccess: print("Espionage was a success") else: print("Espionage was a failure") self.workingTreasure-- self.workingInfluence-- else: print("Treasure or Influence has been used too many times this round") def improveCulture(self): if self.sovereignty > 4: print("Sovereignty too high to improve via this method") elif self.workingTreasure > 0 && self.workingTerritory > 0: attackdice = self.workingTreasure + self.workingTerritory attacksuccess = dice(attackdice) if attacksuccess > self.sovereignty: self.sovereignty++ print("Culture was successfully improved!") else: print("Culture was not improved") self.workingTreasure-- self.workingTerritory-- else: print("Treasure or Territory has been used too many times this round") def improveReputation(self): if self.influence > 4: print("Influence too high to improve via this method") elif self.workingTreasure > 0 && self.workingSovereignty > 0: attackdice = self.workingTreasure + self.workingSovereignty attacksuccess = dice(attackdice) if attacksuccess > self.influence: self.influence++ print("Reputation was successfully improved!") else: print("Reputation was not improved") self.workingTreasure-- self.workingSovereignty-- else: print("Treasure or Sovereignty has been used too many times this round") def improveMight(self): if self.might > 4: print("Might too high to improve via this method") elif self.workingTerritory > 0 && self.workingSovereignty > 0: attackdice = self.workingTerritory + self.workingSovereignty attacksuccess = dice(attackdice) if attacksuccess > self.might: self.might++ print("Might was successfully improved!") else: print("Might was not improved") self.workingTerritory-- self.workingSovereignty-- else: print("Territory or Sovereignty has been used too many times this round") x = Company(1,2,3,4,5) y = Company(5,4,3,2,1) x.attack(y)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question