资源简介
一个非常好玩的简易版植物大战僵尸,用python写的,你应该下载一下!
代码片段和文件信息
“““The ants module implements game logic for Ants Vs. SomeBees.“““
# Name: Anqi Song
# Email: anqisong@berkeley.edu
import random
import sys
from ucb import main interact trace
from collections import OrderedDict
################
# Core Classes #
################
class Place:
“““A Place holds insects and has an exit to another Place.“““
def __init__(self name exit=None):
“““Create a Place with the given exit.
name -- A string; the name of this Place.
exit -- The Place reached by exiting this Place (may be None).
“““
self.name = name
self.exit = exit
self.bees = [] # A list of Bees
self.ant = None # An Ant
self.entrance = None # A Place
# Phase 1: Add an entrance to the exit
“*** YOUR CODE HERE ***“
if self.exit:
exit.entrance = self
def add_insect(self insect):
“““Add an Insect to this Place.
There can be at most one Ant in a Place unless exactly one of them is
a BodyguardAnt (Phase 2) in which case there can be two. If add_insect
tries to add more Ants than is allowed an assertion error is raised.
There can be any number of Bees in a Place.
“““
if insect.is_ant():
# Phase 2: Special handling for BodyguardAnt
“*** YOUR CODE HERE ***“
if self.ant:
if self.ant.can_contain(insect):
self.ant.contain_ant(insect)
elif insect.can_contain(self.ant):
insect.contain_ant(self.ant)
self.ant = insect
else:
assert self.ant is None ‘Two ants in {0}‘.format(self)
else:
assert self.ant is None ‘Two ants in {0}‘.format(self)
self.ant = insect
else:
self.bees.append(insect)
insect.place = self
def remove_insect(self insect):
“““Remove an Insect from this Place.“““
if not insect.is_ant():
self.bees.remove(insect)
else:
assert self.ant == insect ‘{0} is not in {1}‘.format(insect self)
“*** YOUR CODE HERE ***“
if type(insect) == QueenAnt and insect.constructed_time == 1:
return
self.ant = None
if insect.container:
self.ant = insect.ant
insect.place = None
def __str__(self):
return self.name
class Insect:
“““An Insect the base class of Ant and Bee has armor and a Place.“““
watersafe = False
def __init__(self armor place=None):
“““Create an Insect with an armor amount and a starting Place.“““
self.armor = armor
self.place = place # set by Place.add_insect and Place.remove_insect
def reduce_armor(self amount):
“““Reduce armor by amount and remove the insect from its place if it
ha
相关资源
- python实现2048游戏
- python36实现打外星人小游戏图形界面游
- python管道小鸟游戏
- Python2.7 贪吃蛇小游戏源码
- python五子棋代码
- python 战棋游戏六边形地图代码实现
- python实现贪吃蛇小游戏
- python大作业--爬虫完美应付大作业.z
- python小游戏大全——30个
- 贪吃蛇外加优化界面,质量保证pyth
- python 滑雪小游戏
- python小游戏完美解决大作业.zip
- python2048游戏源代码
- 基于python的猜单词游戏开发
- pygame实现的贪吃蛇游戏RetroSnaker.py
- 在我的世界Minecraft 中用Python搭建剑球
- python实现猜数游戏(保存游戏记录
- python编写2048小游戏
- python编程小游戏汉诺塔hanoi
- excel转化成lua 表
- python 数独游戏源码
- Python WxPython开源扫雷游戏PyMine新版1
- Python 扫雷游戏 完整源代码+图片素材
- python飞机小游戏源代码
- 零基础学习python pygame 飞机大战可执行
- python开发飞机大战游戏图片素材
- Python 雷电飞机射击 躲避游戏.rar
- Python爬虫教程+游戏+框架全套源码课件
- python小游戏——打外星人
- 贪吃蛇大作战小游戏 python源代码
评论
共有 条评论