Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to realize Xiaoxiangle Mini Game

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report