91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

所上傳的資源為用Python實現的一個“植物大戰僵尸”小游戲,游戲內容豐富。游戲代碼簡潔,適合Python下載學習,希望我所上傳的資源對你有所幫助。

資源截圖

代碼片段和文件信息

#1?引入需要的模塊
import?pygame
import?random
#1?配置圖片地址
IMAGE_PATH?=?‘imgs/‘
#1?設置頁面寬高
scrrr_width=800
scrrr_height?=560
#1?創建控制游戲結束的狀態
GAMEOVER?=?False
#4?圖片加載報錯處理
LOG?=?‘文件:{}中的方法:{}出錯‘.format(__file____name__)
#3?創建地圖類
class?Map():
????#3?存儲兩張不同顏色的圖片名稱
????map_names_list?=?[IMAGE_PATH?+?‘map1.png‘?IMAGE_PATH?+?‘map2.png‘]
????#3?初始化地圖
????def?__init__(self?x?y?img_index):
????????self.image?=?pygame.image.load(Map.map_names_list[img_index])
????????self.position?=?(x?y)
????????#?是否能夠種植
????????self.can_grow?=?True
????#3?加載地圖
????def?load_map(self):
?????????MainGame.window.blit(self.imageself.position)
#4?植物類
class?Plant(pygame.sprite.Sprite):
????def?__init__(self):
????????super(Plant?self).__init__()
????????self.live=True

????#?加載圖片
????def?load_image(self):
????????if?hasattr(self?‘image‘)?and?hasattr(self?‘rect‘):
????????????MainGame.window.blit(self.image?self.rect)
????????else:
????????????print(LOG)
#5?向日葵類
class?Sunflower(Plant):
????def?__init__(selfxy):
????????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

????#5?新增功能:生成陽光
????def?produce_money(self):
????????self.time_count?+=?1
????????if?self.time_count?==?25:
????????????MainGame.money?+=?5
????????????self.time_count?=?0
????#5?向日葵加入到窗口中
????def?display_sunflower(self):
????????MainGame.window.blit(self.imageself.rect)
#6?豌豆射手類
class?PeaShooter(Plant):
????def?__init__(selfxy):
????????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

????#6?增加射擊方法
????def?shot(self):
????????#6?記錄是否應該射擊
????????should_fire?=?False
????????for?zombie?in?MainGame.zombie_list:
????????????if?zombie.rect.y?==?self.rect.y?and?zombie.rect.x??self.rect.x:
????????????????should_fire?=?True
????????#6?如果活著
????????if?self.live?and?should_fire:
????????????self.shot_count?+=?1
????????????#6?計數器到25發射一次
????????????if?self.shot_count?==?25:
????????????????#6?基于當前豌豆射手的位置,創建子彈
????????????????peabullet?=?PeaBullet(self)
????????????????#6?將子彈存儲到子彈列表中
????????????????MainGame.peabullet_list.append(peabullet)
????????????????self.shot_count?=?0

????#6?將豌豆射手加入到窗口中的方法
????def?display_peashooter(self):
????????MainGame.window.blit(self.imageself.rect)

#7?豌豆子彈類
class?PeaBullet(pygame.sprite.Sprite):
????def?__init__(selfpeashooter):
????????self.live?=?True
????????self.image?=?pygame.image.load(‘imgs/peabullet.png‘)
????????self.damage?=?50
????????self.speed??=?10
????????self.rect?=?self.image.get_rect()
????????self.rect.x?=?peashooter.rect.x?+?60
????????self.rect.y?=?peashooter

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-06-08?11:40??Python植物大戰僵尸\
?????文件?????????127??2019-06-08?11:40??Python植物大戰僵尸\README.md
?????文件???????13408??2019-06-08?11:40??Python植物大戰僵尸\game.py
?????目錄???????????0??2019-06-08?11:40??Python植物大戰僵尸\imgs\
?????文件????????3264??2019-06-08?11:40??Python植物大戰僵尸\imgs\grassland.png
?????文件?????????240??2019-06-08?11:40??Python植物大戰僵尸\imgs\map1.png
?????文件?????????240??2019-06-08?11:40??Python植物大戰僵尸\imgs\map2.png
?????文件????????1065??2019-06-08?11:40??Python植物大戰僵尸\imgs\peabullet.png
?????文件???????13486??2019-06-08?11:40??Python植物大戰僵尸\imgs\peashooter.png
?????文件???????12766??2019-06-08?11:40??Python植物大戰僵尸\imgs\sunflower.png
?????文件????????9812??2019-06-08?11:40??Python植物大戰僵尸\imgs\zombie.png

評論

共有 條評論