In the final phase, you're going to add one last kick to the game by introducing a new type of place and new ants that are able to occupy this place. One of these ants is the most important ant of them all: the queen of the colony.
classWater(Place):"""Water is a place that can only hold watersafe insects."""defadd_insect(self,insect):"""Add an Insect to this place. If the insect is not watersafe, reduce its armor to 0."""# BEGIN Problem 11 Place.add_insect(self, insect)"*** YOUR CODE HERE ***"ifnot insect.is_watersafe: Insect.reduce_armor(insect, insect.armor)# END Problem 11
# BEGIN Problem 12# The ScubaThrower classclassScubaThrower(ThrowerAnt): name ='Scuba' food_cost =6 is_watersafe =True implemented =Truedef__init__(self,armor=1): self.armor =1# END Problem 12
# BEGIN Problem 13classQueenAnt(ScubaThrower):# END Problem 13"""The Queen of the colony. The game is over if a bee enters her place.""" name ='Queen' food_cost =7 first_queen =None# OVERRIDE CLASS ATTRIBUTES HERE# BEGIN Problem 13 implemented =True# Change to True to view in the GUI# END Problem 13def__init__(self,armor=1):# BEGIN Problem 13"*** YOUR CODE HERE ***" self.armor = armor self.buffed_ants ={}ifnot QueenAnt.first_queen: QueenAnt.first_queen = self# END Problem 13defaction(self,colony):"""A queen ant throws a leaf, but also doubles the damage of ants in her tunnel. Impostor queens do only one thing: reduce their own armor to 0. """# BEGIN Problem 13"*** YOUR CODE HERE ***"defbuff_ant(ant):if ant notin self.buffed_ants: ant.damage = ant.damage *2 self.buffed_ants[ant]=True#double damage of all ants behind first_queenif self is QueenAnt.first_queen: self.throw_at(self.nearest_bee(colony.hive)) prev_place = self.place.exitwhile prev_place !=None:if prev_place.ant:buff_ant(prev_place.ant)if prev_place.ant.is_container and prev_place.ant.contained_ant:buff_ant(prev_place.ant.contained_ant) prev_place = prev_place.exitelse:#reduce armor of impostor to 0 self.reduce_armor(self.armor)# END Problem 13defreduce_armor(self,amount):"""Reduce armor by AMOUNT, and if the True QueenAnt has no armor remaining, signal the end of the game. """# BEGIN Problem 13"*** YOUR CODE HERE ***" self.armor -= amountif self.armor <=0and self is QueenAnt.first_queen:bees_win()elif self.armor <=0: self.place.remove_insect(self)# END Problem 13