def menu(self): self.update() selectionmenu = Selection(self.player) choice = selectionmenu.selectGeneral() master = choice.master if master is None: masterName = 'None' else: masterName = master.name Term.fprint('\nName: [cb{0}[cc\nMaster: [cb{1}[cc\nStrength [cb{2}[cc\n'.format(choice.name, masterName, str(choice.strength))) Term.fprint('Men: [cb{0}[cc\n ') return True
def StatusPrompt(self): self.update() Term.clear() status = "Territory:[cb {0} [cc\n\nAgriculture:[cb {1} [cc\n".format(self.location.name, str(self.location.agriculture)) generals = 0 for i in range(self.location.generals.__len__()): if self.location.generals[i].checkLoyalty(self.player): generals += 1 status += "Loyalty: [cb{0} [ccGenerals: [cb{1}[cc\n".format(str(self.location.loyalty), str(generals)) status += "Population: [cb{0}[cc Market: [cb{1}[cc\n".format(str(self.location.population), str(self.location.market)) Term.fprint(status) return
def eval(self, choices, prompt): try: Input = raw_input(Term.format(prompt)) if Input is '0' or Input is '': return False choice = choices[Input] return choice except KeyError: Term.fprint('[crThat is not a valid choice.[cc\n') del Input return Menu.eval(self, choices, prompt) except: print 'What? {0}'.format(sys.exc_info()[0]) sys.exit() return False
def Attack(self, target): if self.army == None: return elif isinstance(target, Land): targetStrength = target.population atk = (self.stats.Leadership() + self.army.experience)*self.army.strength*self.army.men dfn = (target.loyalty * target.defence)/targetStrength if target.population > atk-dfn: target.population -= atk-dfn Term.fprint('[cb{0}[cc attacks [cb{1}[cc, bringing their population down from [cr{2}[cc to [cr{3}[cc'.format(self.name, target.name, str(targetStrength), str(target.population))) #print 'atk:(' + str(atk) + ')\n' else: print self.name + ' has conquered ' + target.name + ' with an attack of ' + str(atk) oldLocation = self.location target.owner = self target.governor = self target.generals.append(self) oldLocation.generals.remove(self) if self.isPlayer or self.location.governor == self: if oldLocation.generals.__len__() == 0: oldLocation.governor = None else: for x in range(oldLocation.generals.__len__()): if oldLocation.generals[x].checkLoyalty(self): assigngov = AssignGovernor(self) assigngov.eval(oldLocation) del assigngov self.location = target return oldLocation.governor = oldLocation.generals[0] elif isinstance(target, general): atk = (self.stats.Leadership() + self.army.experience)*self.army.strength*self.army.men dfn = target.Defend(self, atk) print 'atk:(' + str(atk) + ') dfn:(' + str(dfn[0]) + ') total damage:(' + str(dfn[1]) + ')\n'
def eval(self): x = 1 list = [] menu = Selection(self.player) prompt = 'Who are you going to attack?\n' target = menu.selectBorder(Loyal=False) if not target: return False Term.fprint('Who shall attack? (Costs [cr20 strength[cc)\n') choice = menu.selectGeneral() del menu if choice is not False and target is not False: if choice.strength < 20: Term.fprint ('[cr20 strength[cc is required, but [cr{0}[cc only had [cr{1} strength[cc left.\n'.format(choice.name, choice.strength)) else: choice.Attack(target) choice.strength -= 20 return True else: return False
def market(self): Term.fprint('You chose to improve the market (costs [cr10 strength[cc)\n') if choice is not False: if choice.strength > 10: improvement = self.activeLocation.iMarket(choice) Term.fprint('Market of [cb{0}[cc improved by [cr{1}[cc.\n'.format(self.activeLocation.name, str(improvement))) Term.wait() self.next() else: Term.fprint('[cr10 strength[cc is required, but [cb{0}[cc only had [cr{1} strength[cc left.\n'.format(choice.name, choice.strength)) Term.wait() self.eval()
def agriculture(self): Term.fprint('You chose to improve agriculture (costs [cr10 strength[cc)\n') choice = self.menu.selectGeneral() if choice is not False: if choice.strength > 10: improvement = self.activeLocation.iAgriculture(choice) Term.fprint('Agriculture of [cb{0}[cc improved by [cr{1}[cc.\n'.format(self.activeLocation.name, str(improvement))) Term.wait() self.next() else: Term.fprint('[cr10 strength[cc is required, but [cb{0}[cc only had [cr{1} strength[cc left.\n'.format(choice.name, choice.strength)) Term.wait() self.eval()
def train(self): Term.fprint('\nChose a general to train his army (costs [cr30 strength[cc)\n') choice = self.menu.selectGeneral() if choice is False: self.eval() elif choice.strength < 30: Term.fprint('\n[cr30 strength[cc is required, but [cb{0}[cc only has [cr{1} strength[cc left.'.format(choice.name, str(choice.strength))) self.train() else: improvement = choice.stats.Leadership() choice.army.experience += improvement choice.strength -= 30 Term.fprint('[cb{0}[cc has increased their army\'s experience by {1}, and is now {2}'.format(choice.name, str(improvement), str(choice.army.experience))) Term.wait() self.eval()