What are the childhood games that can be played in Python code?
In this issue, the editor will bring you about the Python code, which can play more than 30 childhood games, the article is rich in content and professional analysis and description for you, after reading this article, I hope you can get something.
There are tens of millions of big games on Mini Game, and these Mini Game should only be played and understood in the post-90s generation.
International Children's Day is coming, although bald programmers have no hair, but childlike innocence has always been there, today to share some private childhood games, more than a dozen lines of code can enter Mini Game developed using Python to have fun!
Use the tool:
Python3.8 、 pycharm2020
You can also run it directly without installing pycharm2020, but it would be better if you installed it.
1. Five-in-a-Row
Source code:
Class gameStartUI (QWidget): def _ init__ (self, parent=None, * * kwargs): super (gameStartUI, self). _ _ init__ (parent) self.setFixedSize Self.setWindowTitle ('Gobang-Nine songs') self.setWindowIcon (QIcon (cfg.ICON_FILEPATH)) # background picture palette = QPalette () palette.setBrush (self.backgroundRole () QBrush (QPixmap (cfg.BACKGROUND_IMAGEPATHS.get ('bg_start') self.setPalette (palette) # Button #-Man-Machine Battle self.ai_button = PushButton (cfg.BUTTON_IMAGEPATHS.get (' ai'), self) self.ai_button.move Self.ai_button.show () self.ai_button.click_signal.connect (self.playWithAI) #-- online fighting self.online_button = PushButton (cfg.BUTTON_IMAGEPATHS.get ('online'), self) self.online_button.move Self.online_button.show () self.online_button.click_signal.connect (self.playOnline)''Man-Machine War' 'def playWithAI (self): self.close () self.gaming_ui = playWithAIUI (cfg) self.gaming_ui.exit_signal.connect (lambda: sys.exit ()) self.gaming_ui.back_signal.connect (self) .show) self.gaming_ui.show ()''online fighting' def playOnline (self): self.close () self.gaming_ui = playOnlineUI (cfg) Self) self.gaming_ui.show ()''run''' if _ name__ = =' _ _ main__': app = QApplication (sys.argv) handle = gameStartUI () font = QFont () font.setPointSize (12) handle.setFont (font) handle.show () sys.exit (app.exec_ ()) 2. Super Mary else: break Interface (screen, cfg, mode='game_end') me.display.update () clock.tick (cfg.FPS) if is_win_flag:
3. The bomber.
Source code:
Def main (cfg): # initialize pygame.init () pygame.mixer.init () pygame.mixer.music.load (cfg.BGMPATH) pygame.mixer.music.play (- 1,0.0) screen = pygame.display.set_mode (cfg.SCREENSIZE) pygame.display.set_caption ('Bomber Man-Nine songs') # start interface Interface (screen, cfg) Mode='game_start') # Game main cycle font = pygame.font.SysFont ('Consolas', 15) for gamemap_path in cfg.GAMEMAPPATHS: #-Map map_parser = mapParser (gamemap_path, bg_paths=cfg.BACKGROUNDPATHS, wall_paths=cfg.WALLPATHS Blocksize=cfg.BLOCKSIZE) #-Fruit fruit_sprite_group = pygame.sprite.Group () used_spaces = [] for i in range (5): coordinate= map_parser.randomGetSpace (used_spaces) used_spaces.append (coordinate) fruit_sprite_group.add (Fruit (random.choice (cfg.FRUITPATHS), coordinate=coordinate Blocksize=cfg.BLOCKSIZE) #-our Hero coordinate= map_parser.randomGetSpace (used_spaces) used_spaces.append (coordinate) ourhero = Hero (imagepaths=cfg.HEROZELDAPATHS, coordinate=coordinate, blocksize=cfg.BLOCKSIZE, map_parser=map_parser) Hero_name='ZELDA') #-computer Hero aihero_sprite_group = pygame.sprite.Group () coordinate= map_parser.randomGetSpace (used_spaces) aihero_sprite_group.add (Hero (imagepaths=cfg.HEROBATMANPATHS, coordinate=coordinate, blocksize=cfg.BLOCKSIZE, map_parser=map_parser) Hero_name='BATMAN') used_spaces.append (coordinate) coordinate= map_parser.randomGetSpace (used_spaces) aihero_sprite_group.add (Hero (imagepaths=cfg.HERODKPATHS, coordinate=coordinate, blocksize=cfg.BLOCKSIZE, map_parser=map_parser) Hero_name='DK')) used_spaces.append (coordinate) #-bomb bomb bomb_sprite_group = pygame.sprite.Group () #-flag is_win_flag = False #-main loop screen = pygame.display.set_mode (map_parser.screen_size) clock = pygame .time.clock () while True: dt = clock.tick (cfg.FPS) for event in pygame.event.get (): if event.type = = pygame.QUIT: pygame.quit () sys.exit (- 1) #-↑↓←→ key controls up and down The space bar drops bombs elif event.type = = pygame.KEYDOWN: if event.key = = pygame.K_UP: ourhero.move ('up') elif event.key = = pygame.K_DOWN: ourhero.move (' down') elif event.key = pygame.K_LEFT: ourhero.move ('left') elif event.key = = pygame.K_RIGHT: ourhero.move (' right') elif event.key = = pygame.K_SPACE: if ourhero.bomb_cooling_count