def attack(self): UI.nextMsg = 'Fortify' UI.nextHover = False UI.update() #loop to get appropriate attacking territory or advance to fortify while self.pick and not self.restart: UI.nextColor = True UI.box1 = Data.playerList[self.player].name+' - Attack' UI.box2 = 'Select one of your territories' UI.box3 = 'to launch attack from' UI.update() base = self.clickMapAny(True) if base == None or not base: self.pick = False else: self.choice = True #set default troops to max attackers, can be changed by player self.numAttackers = min(Data.terrList[base].units-1, 3) UI.numBoxSetArray(base, self.numAttackers) #loop to get target or handle break to send back to first loop while self.choice and not self.restart: UI.nextColor = False UI.update() GUI.drawLines(base, None) target = self.clickMapSpecific(base) if target != None and target != False: #roll dice, handle results defender = Data.terrList[target].owner attLoss, defLoss, change = self.dice(base, target) logging.info('Attacker lost '+str(attLoss)+', defender lost '+str(defLoss)+', change: '+str(change)) UI.box2 = ('You lost '+str(attLoss)+', defender lost '+str(defLoss)) UI.box3 = ('Click to attack again or water to reset') UI.update() #handle for less available attackers if Data.terrList[base].units-1 < self.numAttackers: self.numAttackers = Data.terrList[base].units-1 GUI.displayUnits() #not enough units to keep attacking if change == False: logging.info('Too few units to continue attacking') GUI.highlight(base, False) GUI.highlight(target, False) self.choice = False #territory conquered if change: self.territoryConquered(base, target, defender)
def clickMapSpecific(self, base, style=None): while True and not self.restart: GUI.drawLines(base, style) #add numberBox here - or in clickMapSpecific if style == None: UI.numBoxSetArray(base, self.numAttackers) UI.numBox() #could be handled with a none (x,y), click = getMouseClick(style) else: (x,y), click = getMouseClick() if y > 512: #handle for menu - button will not be live if 305 < x < 333 and 518 < y < 546: Intro.menu() if Data.reset == True: logging.info('Restart selected') self.breakMove() if style == None: return None else: return None, None else: continue else: waterBreak = True #set self.numAttackers without resetting from water click margin = 80 for i in range(3): if style == None and (405+margin*i) < x < (405+margin*i+30) and (470) < y < (470+30): self.numAttackers = i+1 waterBreak = False p = GUI.MasterMap.get_at((x,y)) #handle for water click reset if p[0] == 162 and style == None and waterBreak: self.choice = False logging.info('Water clicked - resetting') UI.box2 = ('Resetting selected territory') UI.box3 = ('Select territory to attack from') UI.update() GUI.highlight(base, False) return False elif 0 < p[0] < 43: #redistribute - only base or conquered territory if type(style) is int and 0 < style < 43: if p[0] == style or p[0] == base: return p[0], click else: logging.info('Must be attacking or new territory') UI.box3 = 'Must be attacking or new territory' UI.update() continue else: if p[0] not in Data.terrList[base].touch or p[0] != base: logging.info('Territories must be touching') UI.box2 = 'Territories must be touching' if p[0] in Data.terrList[base].touch or p[0] == base: #fortify - base or connected owned territories if style == False: if Data.terrList[p[0]].owner == self.player: return p[0], click else: logging.info('Must choose your own territory') UI.box3 = 'Must choose your own territory' UI.update() continue #attack - connected non-owned territories elif style == None: if Data.terrList[p[0]].owner != self.player: return p[0] #handle for clicking same country - reset elif p[0] == base: self.choice = False logging.info('Resetting selected territory') UI.box2 = ('Resetting selected territory') UI.box3 = ('Select territory to attack from') UI.update() GUI.highlight(p[0], False) return False else: logging.info('Cannot attack owned territory') UI.box2 = 'Cannot attack owned territory' UI.update() continue