项目说明:https://inst.eecs.berkeley.edu/~cs61a/sp21/proj/ants/
蚂蚁大战蜜蜂 灵感来源:植物大战僵尸(Plants Vs. Zombies,PVZ)
Phase 1: https://www.cnblogs.com/ikventure/p/14986805.html
Phase 2: https://www.cnblogs.com/ikventure/p/14988467.html
Phase 3: https://www.cnblogs.com/ikventure/p/14992754.html
Phase 4: https://www.cnblogs.com/ikventure/p/14994734.html
目前place有Hive和基本场地两种类型,现在引入水池类型Water。
只有watersafe的insect可以放置在Water中,在Insect引入is_watersafe的类属性,蜜蜂可以飞,所以Bee.is_watersafe是True。
Water类:
add_insect方法,放置insect到place上,如果insect不是watersafe的,将该insect的生命值降至0,调用Insect类的reduce_health方法。
class Insect:
"""An Insect, the base class of Ant and Bee, has health and a Place."""
damage = 0
# ADD CLASS ATTRIBUTES HERE
is_watersafe = False
class Bee(Insect):
"""A Bee moves from place to place, following exits and stinging ants."""
name = ‘Bee‘
damage = 1
# OVERRIDE CLASS ATTRIBUTES HERE
is_watersafe = True
class Water(Place):
"""Water is a place that can only hold watersafe insects."""
def add_insect(self, insect):
"""Add an Insect to this place. If the insect is not watersafe, reduce
its health to 0."""
# BEGIN Problem 10
"*** YOUR CODE HERE ***"
super().add_insect(insect)
if not insect.is_watersafe:
insect.reduce_health(insect.health)
# END Problem 10
引入水上射手ScubaThrower,继承自ThrowerAnt,可以放置在Water场地中,只需要重写name, is_watersafe, food_cost。
Class | Food Cost | Initial Health |
---|---|---|
ScubaThrower | 6 | 1 |
代码:
# BEGIN Problem 11
# The ScubaThrower class
class ScubaThrower(ThrowerAnt):
"""ScubaThrower is a watersafe ThrowerAnt."""
name = ‘Scuba‘
food_cost = 6
is_watersafe = True
implemented = True
# END Problem 11
引入QueenAnt,一种防水的ScubaThrower,除了标准的ScubaThrower.action,每次行动时,它身后的所有蚂蚁damage加倍(不包括FireAnt的反伤)。
Class | Food Cost | Initial Health |
---|---|---|
QueenAnt | 7 | 1 |
QueenAnt有三种特殊的规则:
思路:
[2021 Spring] CS61A Project 3: Ants Vs. SomeBees (Phase 4)
原文:https://www.cnblogs.com/ikventure/p/14994734.html