資源簡介
pygame 編寫連連看
代碼片段和文件信息
“““
?Name:?連連看游戲
?Athor:?盧華東
?Email:?luhuadong@163.com
?Date:?2018-07-07
?Description:?哎呀,反正就是連連看啦
“““
import?sys?time
import?math?random
import?pygame
from?pygame.locals?import?*
#?全局的設置類
class?Settings:
????def?__init__(self):
????????#?定義游戲窗口大小,為背景圖片的一半
????????self.screen_size?=?(self.screen_width?self.screen_height)?=?(800?480)
????????self.game_size?=?(self.game_row?self.game_col)?=?(6?10)
????????self.map_total?=?self.game_row?*?self.game_col
????????self.element_num?=?12
????????self.bg_color?=?(220?220?220)
????????self.title?=?‘Pig?Pig?連連看‘
????????self.win_image?=?‘./images/you_win.png‘
????????self.grid_size?=?80
????????self.scale_size?=?(76?76)
????????self.points?=?[]
#?實例化設置對象
settings?=?Settings()
#?圖像列表映射
map_list?=?[]
#global?map_list
image_list?=?[]
#?圖片按鈕
class?ImageBtn:
????__checkable?=?True
????__checked?=?False
????def?__init__(self?screen?image_path?x?y?number?element):
????????self.x?=?x
????????self.y?=?y
????????self.element?=?element
????????self.number?=?number
????????self.screen?=?screen
????????self.image?=?pygame.image.load(image_path)
????????#?因為圖片原始大小為?200x200,所以要進行縮放
????????self.image?=?pygame.transform.scale(self.image?settings.scale_size)
????def?__del__(self):
????????pass
????def?display(self):
????????#?描邊
????????“““
????????if?self.__checked:
????????????#self.image?=?pygame.transform.laplacian(self.image)
????????????pygame.draw.rect(self.image?(0205205)?(00self.image.get_width()-1self.image.get_height()-1)?2)
????????“““
????????“““
????????if?not?self.__checkable:
????????????self.image.fill((255?255240))
????????“““
????????if?self.__checked:
????????????pygame.draw.rect(self.image?(0205205255)?(00self.image.get_width()-1self.image.get_height()-1)?2)
????????else:
????????????pygame.draw.rect(self.image?(02052050)?(00self.image.get_width()-1self.image.get_height()-1)?2)
????????self.screen.blit(self.image?(self.x?self.y))
????def?hide(self):
????????self.__checked?=?False
????????self.__checkable?=?False
????????#?圖片不可視
????????#self.image.set_alpha(255)
????????self.image.fill((255?255240))
????def?is_checkable(self):
????????return?self.__checkable
????def?click(self):
????????self.__checked?=?not?self.__checked
????????return?self.__checked
????def?reset(self):
????????self.__checked?=?False
????def?get_geometry(self):
????????return?(int(self.x)?int(self.y)?settings.scale_size[0]?settings.scale_size[1])
#?水平掃描
def?horizontal_scan(points):
????“““
????水平標定
????以?p1?和?p2?所在的兩個行作為基準線,然后用垂直線在有效范圍內掃描,
????一旦發現可行路徑,直接返回。
??????hLine1??和???hLine2???分別是掃描的上邊線和下邊線
????leftLimit?和?rightLimit?分別是掃描的左邊線和右邊線
????“““
????column?=?settings.game_col
????p1_x?=?int(points[0].number?%?column)
????p1_y?=?int(points[0].number?/?column)
????p2_x?=?int(points[1].number?%?column)
????p2_y?=?int(points[1].number?/?column)
????#?如果?p1?和?p2?在同一行,則不符合要求
????if?p1_y?==?p2_y:
????????return?False
????print(“Horizontal?Scanning?...“)
????#?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-09-10?23:19??images\
?????文件?????????284??2020-09-10?23:19??images\element_0.png
?????文件???????83693??2020-09-10?23:19??images\element_1.png
?????文件???????63794??2020-09-10?23:19??images\element_10.png
?????文件???????26292??2020-09-10?23:19??images\element_11.png
?????文件???????62496??2020-09-10?23:19??images\element_12.png
?????文件???????58338??2020-09-10?23:19??images\element_2.png
?????文件???????40689??2020-09-10?23:19??images\element_3.png
?????文件???????22883??2020-09-10?23:19??images\element_4.png
?????文件???????36238??2020-09-10?23:19??images\element_5.png
?????文件???????34105??2020-09-10?23:19??images\element_6.png
?????文件???????27157??2020-09-10?23:19??images\element_7.png
?????文件???????47194??2020-09-10?23:19??images\element_8.png
?????文件???????39296??2020-09-10?23:19??images\element_9.png
?????文件???????41533??2020-09-10?23:19??images\icon.png
?????文件???????41533??2020-09-10?23:19??images\test.png
?????文件??????108228??2020-09-10?23:19??images\you_win.png
?????文件???????15221??2020-09-10?23:19??li
- 上一篇:基于PyQt5的視頻播放器設計
- 下一篇:python疫情卡UN管控
評論
共有 條評論