第一版游戲demo
添加計分系統:中間是最高得分,右邊是本次得分。
顯示余下的飛船數
主函數如下,完整程序將上傳到筆者的github:https://github.com/shizhengLi/learning_python
import pygame
from pygame
.sprite
import Group
from settings
import Settings
from game_stats
import GameStats
from scoreboard
import Scoreboard
from button
import Button
from ship
import Ship
import game_functions
as gf
def run_game():pygame
.init
()ai_settings
= Settings
()screen
= pygame
.display
.set_mode
((ai_settings
.screen_width
, ai_settings
.screen_height
))pygame
.display
.set_caption
("Alien Invasion")play_button
= Button
(ai_settings
, screen
, "Play")stats
= GameStats
(ai_settings
)bg_color
= (230, 230, 230)ship
= Ship
(ai_settings
, screen
)bullets
= Group
()aliens
= Group
()gf
.create_fleet
(ai_settings
, screen
, ship
, aliens
)stats
= GameStats
(ai_settings
)sb
= Scoreboard
(ai_settings
, screen
, stats
)while True:gf
.check_events
(ai_settings
, screen
, stats
, sb
, play_button
, ship
, aliens
, bullets
)if stats
.game_active
:ship
.update
()gf
.update_bullets
(ai_settings
, screen
, stats
, sb
, ship
, aliens
, bullets
)gf
.update_aliens
(ai_settings
, screen
, stats
, sb
, ship
, aliens
, bullets
)gf
.update_screen
(ai_settings
, screen
, stats
, sb
, ship
, aliens
, bullets
, play_button
)run_game
()
這算是學習python真正入門的一次嘗試,算是班門弄斧啦。
總結
以上是生活随笔為你收集整理的python基础学习[python编程从入门到实践读书笔记(连载二)]:外星人入侵项目的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。