def can_attack(self, tile): if not self.acted: dist = calculate_distance(tile, self.location) if dist <= self._attack.range: self.acted = True return True return False
def can_move(self, tile): if not tile.occupant and tile.passable and not self.acted: dist = calculate_distance(tile, self.location) if dist <= self.speed: path = a_star(self.location, tile) if path: self.acted = True return path return False
def attack(state, player): print "\nEnter the coordinates of the unit to attack with. (x,y)" coords = get_coords(state.map) unit = state.locate_unit(coords[0], coords[1]) if unit and unit.player.name is player.name: print "Enter the coordinates to attack. (x,y)" attackto = get_coords(state.map) tile = state.map.tile(attackto[0], attackto[1]) if unit.can_attack(tile): player.attack_number +=1 player.paradox += logic.calculate_distance(unit.location, tile)/2 player.attacks.append(game.AttackAction(player.attack_number, player, unit, unit.location, tile)) else: print "Couldn't use that unit to attack there." raw_input() else: print "You don't have a unit at that location." raw_input()
def move_unit(state, player): print "\nEnter the coordinates of the unit to move. (x,y)" coords = get_coords(state.map) unit = state.locate_unit(coords[0], coords[1]) if unit and unit.player.name is player.name: print "Enter the coordinates to move to. (x,y)" moveto = get_coords(state.map) tile = state.map.tile(moveto[0], moveto[1]) path = unit.can_move(tile) if path: player.move_number +=1 player.paradox += logic.calculate_distance(unit.location, tile)/2 player.moves.append(game.MoveAction(player.move_number, player, unit, unit.location, tile, path)) if not path: print "Couldn't move that unit there." raw_input() else: print "You don't have a unit at that location." raw_input()