日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python小游戏(消消乐)

發(fā)布時間:2024/8/26 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python小游戏(消消乐) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

玩法:三個相連就能消除

源碼分享:

import os import sys import cfg import pygame from modules import *'''游戲主程序''' def main():pygame.init()screen = pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('Gemgem —— 九歌')# 加載背景音樂pygame.mixer.init()pygame.mixer.music.load(os.path.join(cfg.ROOTDIR, "resources/audios/bg.mp3"))pygame.mixer.music.set_volume(0.6)pygame.mixer.music.play(-1)# 加載音效sounds = {}sounds['mismatch'] = pygame.mixer.Sound(os.path.join(cfg.ROOTDIR, 'resources/audios/badswap.wav'))sounds['match'] = []for i in range(6):sounds['match'].append(pygame.mixer.Sound(os.path.join(cfg.ROOTDIR, 'resources/audios/match%s.wav' % i)))# 加載字體font = pygame.font.Font(os.path.join(cfg.ROOTDIR, 'resources/font/font.TTF'), 25)# 圖片加載gem_imgs = []for i in range(1, 8):gem_imgs.append(os.path.join(cfg.ROOTDIR, 'resources/images/gem%s.png' % i))# 主循環(huán)game = gemGame(screen, sounds, font, gem_imgs, cfg)while True:score = game.start()flag = False# 一輪游戲結(jié)束后玩家選擇重玩或者退出while True:for event in pygame.event.get():if event.type == pygame.QUIT or (event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE):pygame.quit()sys.exit()elif event.type == pygame.KEYUP and event.key == pygame.K_r:flag = Trueif flag:breakscreen.fill((135, 206, 235))text0 = 'Final score: %s' % scoretext1 = 'Press <R> to restart the game.'text2 = 'Press <Esc> to quit the game.'y = 150for idx, text in enumerate([text0, text1, text2]):text_render = font.render(text, 1, (85, 65, 0))rect = text_render.get_rect()if idx == 0:rect.left, rect.top = (212, y)elif idx == 1:rect.left, rect.top = (122.5, y)else:rect.left, rect.top = (126.5, y)y += 100screen.blit(text_render, rect)pygame.display.update()game.reset()'''run''' if __name__ == '__main__':main()

祝大家玩得開心,歡迎點(diǎn)贊、關(guān)注、評論,歡迎一健三聯(lián)。

總結(jié)

以上是生活随笔為你收集整理的Python小游戏(消消乐)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。