資源簡介
下載后可以直接在python3.6的環境下直接運行(如果提醒沒有庫請自行安裝)游戲,游戲的素材存放在images目錄下,可以進行替換。代碼里面對一部分模塊做了較為清晰的解釋。適合新手參考,入門的練習。

代碼片段和文件信息
#!/usr/bin/env?python??
#?-*-?coding:?utf-8?-*-??
#?__author__:?xinlan?2017/11/28
import?pygame
from?pygame.sprite?import?Sprite
import?random
class?Alien(Sprite):
????“““表示單個外星人的類“““
????def?__init__(selfai_settingsscreen):
????????“““初始化外星人并設置其他位置“““
????????super(Alienself).__init__()
????????self.screen?=?screen
????????self.ai_settings?=?ai_settings
????????#加載外星人圖像,并設置其rect屬性
????????self.image?=?pygame.image.load(‘images/alien.bmp‘)
????????self.rect?=?self.image.get_rect()
????????#每個外星人最初都在屏幕左上角附近
????????self.rect.x?=?self.rect.width
????????self.rect.y?=?self.rect.height
????????#存儲外星人的準確位置
????????self.x?=?float(self.rect.x)
????def?blitme(self):
????????“““在指定位置繪制外星人“““
????????self.screen.blit(self.imageself.rect)
????def?check_edges(self):
????????“““如果外星人位于屏幕邊緣,就返回True“““
????????screen_rect?=?self.screen.get_rect()
????????if?self.rect.right?>=?screen_rect.right:
????????????return?True
????????elif?self.rect.left?<=?0:
????????????return?True
????def?update(self):
????????“““向右移動外星人“““
????????self.x?+=?(self.ai_settings.alien_speed_factor?*?self.ai_settings.fleet_direction)
????????self.rect.x?=?self.x
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1384??2018-10-24?23:46??外星人小游戲\alien.py
?????文件???????1839??2018-10-24?23:56??外星人小游戲\alien_invasion.py
?????文件???????1107??2018-10-24?23:29??外星人小游戲\bullet.py
?????文件???????1321??2018-10-25?00:01??外星人小游戲\button.py
?????文件???????8263??2018-10-24?23:30??外星人小游戲\game_functions.py
?????文件????????656??2018-10-24?23:31??外星人小游戲\game_stats.py
?????文件??????13854??2018-10-24?23:25??外星人小游戲\images\alien.bmp
?????文件??????58854??2018-10-24?23:35??外星人小游戲\images\ship.bmp
?????文件???????7046??2018-10-24?23:26??外星人小游戲\images\ship.png
?????文件???????2874??2018-10-24?23:31??外星人小游戲\scoreboard.py
?????文件???????1701??2018-10-24?23:32??外星人小游戲\settings.py
?????文件???????1823??2018-10-24?23:32??外星人小游戲\ship.py
?????文件???????1515??2018-10-24?23:46??外星人小游戲\__pycache__\alien.cpython-36.pyc
?????文件???????1192??2018-10-24?23:33??外星人小游戲\__pycache__\bullet.cpython-36.pyc
?????文件???????1418??2018-10-25?00:01??外星人小游戲\__pycache__\button.cpython-36.pyc
?????文件???????6208??2018-10-24?23:33??外星人小游戲\__pycache__\game_functions.cpython-36.pyc
?????文件????????837??2018-10-24?23:33??外星人小游戲\__pycache__\game_stats.cpython-36.pyc
?????文件???????2675??2018-10-24?23:33??外星人小游戲\__pycache__\scoreboard.cpython-36.pyc
?????文件???????1519??2018-10-24?23:33??外星人小游戲\__pycache__\settings.cpython-36.pyc
?????文件???????1577??2018-10-24?23:33??外星人小游戲\__pycache__\ship.cpython-36.pyc
?????目錄??????????0??2018-10-24?23:36??外星人小游戲\images
?????目錄??????????0??2018-10-25?00:01??外星人小游戲\__pycache__
?????目錄??????????0??2018-10-25?00:01??外星人小游戲
-----------?---------??----------?-----??----
???????????????117663????????????????????23
- 上一篇:BP算法Python代碼
- 下一篇:利用ECMWF風場運行SWAN使用步驟
評論
共有 條評論