Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python to realize Xiaoxiangle Mini Game

Shulou Source: shulou.com Published: 2022-06-03 10:17:36 09月22日 Update

Today, I will talk to you about how to use Python to achieve Xiaoxiaole Mini Game, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

How to play: it can be eliminated by connecting three.

Source code sharing:

Import osimport sysimport cfgimport pygamefrom modules import * 'Game main Program' 'def main (): pygame.init () screen = pygame.display.set_mode (cfg.SCREENSIZE) pygame.display.set_caption (' Gemgem-Nine songs') # 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 = pygame.font.Font (os.path.join (cfg.ROOTDIR, 'resources/font/font.TTF')) 25) # Image loading gem_imgs = [] for i in range (1,8): gem_imgs.append (os.path.join (cfg.ROOTDIR, 'resources/images/gem%s.png'% I)) # main loop game = gemGame (screen, sounds, font, gem_imgs) Cfg) while True: score = game.start () flag = False # after a round of games, players choose to replay 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 Pygame.K_r () sys.exit () elif event.type = = pygame.KEYUP and event.key = = pygame.K_r: flag = True if flag: break screen.fill 206235) text0 = 'Final score:% s'% score text1 = 'Press to restart the game.' Text2 = 'Press 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 = 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 () read the above content Do you have any further understanding of how to use Python to implement Xiaoxiangle Mini Game? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Content Mini Game three main programs nine songs pictures fonts more source code players play knowledge articles background background music industry information information channels music sound effects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Linux Shulou Information macOS