字节跳动一轮面试用Python写一个植物大战僵尸,找找90后童年的乐趣,面试学习

def load_image(self):

if hasattr(self, ‘image’) and hasattr(self, ‘rect’):

MainGame.window.blit(self.image, self.rect)

else:

print(LOG)

向日葵类

class Sunflower(Plant):

def init(self, x, y):

super(Sunflower, self).init()

self.image = pygame.image.load(‘imgs/sunflower.png’)

self.rect = self.image.get_rect()

self.rect.x = x

self.rect.y = y

self.price = 50

self.hp = 100

5 时间计数器

self.time_count = 0

新增功能:生成阳光

def produce_money(self):

self.time_count += 1

if self.time_count == 25:

MainGame.money += 5

self.time_count = 0

向日葵加入到窗口中

def display_sunflower(self):

MainGame.window.blit(self.image, self.rect)

豌豆射手类

class PeaShooter(Plant):

def init(self, x, y):

super(PeaShooter, self).init()

self.image 为一个 surface

self.image = pygame.image.load(‘imgs/peashooter.png’)

self.rect = self.image.get_rect()

self.rect.x = x

self.rect.y = y

self.price = 50

self.hp = 200

6 发射计数器

self.shot_count = 0

增加射击方法

def shot(self):

6 记录是否应该射击

should_fire = False

for zombie in MainGame.zombie_list:

if zombie.rect.y == self.rect.y and zombie.rect.x < 800 and zombie.rect.x > self.rect.x:<

  • 23
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值