[pyGame practice] happiness — xiaoxiaole, you, me and everyone~

Time:2021-12-1

”’
Function:

Xiaole games

Source base: #959755565#
”’
import os
import sys
import cfg
import pygame
from modules import *
” game main program ” ‘
def main():

pygame.init()
screen = pygame.display.set_mode(cfg.SCREENSIZE)
pygame.display.set_ Caption ('happy Xiaole ')
#Load background music
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)
#Load sound
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)))
#Load font
Font = [perfectmoney Download]( https://www.gendan5.com/wallet/PerfectMoney.html )pygame.font.Font(os.path.join(cfg.ROOTDIR, 'resources/font/font.TTF'), 25)
#Picture loading
gem_imgs = []
for i in range(1, 8):
    gem_imgs.append(os.path.join(cfg.ROOTDIR, 'resources/images/gem%s.png' % i))
#Main cycle
game = gemGame(screen, sounds, font, gem_imgs, cfg)
while True:
    score = game.start()
    flag = False
    #After a round of the game, players choose to play again or exit
    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 = True
        if flag:
            break
        screen.fill((135, 206, 235))
        text0 = 'Final score: %s' % score
        text1 = 'Press <R> to restart the game.'
        text2 = 'Press <Esc> to quit the game.'
        y = 150
        for 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 += 100
            screen.blit(text_render, rect)
        pygame.display.update()
    game.reset()

”’run”’
if name == ‘__main__’:

main()

Recommended Today

Linux batch unzip shell scripts with password rar into the directory with the same file name

I wrote a batch decompression shell with the password rar, which can be decompressed to a folder with the same file name as RAR. If necessary, please refer to it. #!/bin/bash #———————————– #Batch unzip the RAR with password to the directory with the same file name #———————————– #Unzip password pwd=’123456′ for i in *.rar do […]