Python儿童数字消消乐游戏源代码,小朋友认数字游戏源代码

科技   科技   2023-06-15 18:23   云南  

Python儿童数字消消乐源代码,小朋友认数字游戏源代码,通过消消乐游戏的方式来让小朋友来学习数字,让孩子在玩中学数字


核心代码

import pygamefrom time import sleepfrom pygame.locals import *import sysfrom utils import *from cube import *pygame.init()screen = pygame.display.set_mode((WIDTH, HEIGHT))pygame.display.set_caption("数字消消乐_Python代码大全")bg_image = pygame.image.load("./imgs/bg.png")BG_MUSIC.play(-1)BG_MUSIC.set_volume(0.2)

game_level = 1current_choose = 1first = None
game_stage = 0 # 0:ready 1:playing 2:game pass 3:all_game_pass# game_about = Text(GAME_INFO)game_left_block = Text(LEFT_BLOCK_TEXT, font_size=35, color=(253, 196, 11), pos=(888, 38))game_left_block.update(MAX_BLOCK_PAIR)# game_kill_block = Text(KILL_BLOCK_TEXT, font_size=20, color="purple", pos=(810, 35))# game_kill_block.update(0)game_click_error = Text(CLICK_ERROR_TEXT, font_size=20, color=(253, 196, 11), pos=(146, 29))click_error_time = 0game_click_error.update(0)

while True: for event in pygame.event.get(): if event.type == QUIT: sys.exit() if event.type == MOUSEBUTTONDOWN: x, y = event.pos if game_stage == 1: for cube in player_group: if cube.rect.collidepoint(x, y): music_play = pygame.mixer.Sound("./sound/shuzi/" + str(cube.label) + ".wav") if current_choose == 1: # print(cube.label) music_play.play() cube.float(True) first = cube current_choose += 1 elif current_choose == 2: # cube与之前first 缓存的是不是同一个东西 # print(id(cube), id(first)) first_id = first.get_id() # 答对 if cube.get_label() == first.get_label() and \ cube.is_not_same(first_id):
cube.float(True) music_play.play() cube.yes() first.ready_to_kill() cube.ready_to_kill() emotion_flag = 0 count -= 1 well_done = WellDone() well_dones.add(well_done) # 答错 else: emotion_flag = 1 first.float(False) music_play.play() click_error_time += 1 # print(cube.label) current_choose = 1 elif game_stage == 2: if replay_again.collidepoint(x, y): game_level = game_level elif next_level.collidepoint(x, y): game_level += 1 # 初始化 game_stage = 0 elif game_stage == 3: if return_first_level.collidepoint(x, y): game_level = 1 game_stage = 0 elif game_exit.collidepoint(x, y): sys.exit()
if game_stage == 0: count = MAX_BLOCK_PAIR click_error_time = 0 sound_play = False face_emotion = Emotion(764, 32) emotion_flag = 2 game_level_show = "第" + str(game_level) + "关" + " " number_start = 1 + (game_level-1)*4 number_end = number_start + 7 game_level_show += "( " + str(number_start) + "~" + str(number_end) + " )" if game_level <= 3: game_level_display = Text(game_level_show, font_size=16, color=(253, 196, 11), pos=(99, 75)) elif game_level > 3: game_level_display = Text(game_level_show, font_size=13, color=(253, 196, 11), pos=(95, 78)) label = load_map(game_level) player_group = pygame.sprite.Group() well_dones = pygame.sprite.Group() for row in range(0, CUBE_MAX_ROW): for col in range(0, CUBE_MAX_COL): player = Word(col, row, label[row][col]) player_group.add(player) game_stage = 1
if game_stage in (1, 2): # screen.fill(BG_COLOR) screen.blit(bg_image, (0, 0)) player_group.update() for p in player_group: p.draw(screen) well_dones.update() # game_about.draw(screen) # 剩余方块数 game_left_block.update(count) game_left_block.draw(screen) # 已消方块数 # game_kill_block.update(MAX_BLOCK_PAIR - count) # game_kill_block.draw(screen) # 错误方块数 game_click_error.update(click_error_time) game_click_error.draw(screen) # 答对答错表情更新 face_emotion.update(emotion_flag) face_emotion.draw(screen) # 关卡显示 game_level_display.draw(screen) if count == 0: game_stage = 2 if game_level == MAX_GAME_LEVEL: if count == 0: game_stage = 3 if game_stage == 2: # print("xxx") if not sound_play: sound_play = True GAME_PASS_MUSIC.play() # screen.blit(GAME_PASS_BG, (0, 0))
screen.blit(GAME_PASS, (350, 300)) # screen.fill("black", replay_again) # screen.fill("black", next_level) # game_level += 1 # game_stage = 0 if game_stage == 3: screen.blit(GAME_ALL_PASS_BG, (0, 0))
pygame.draw.rect(screen, "gray", (5, 105, WIDTH - 10, HEIGHT - 115), 3) pygame.display.update()







完整代码下载地址:

https://download.csdn.net/download/weixin_42756970/87263935


Python代码大全
Python源程序、源代码、源码分享,Python代码大全,Python源代码学习,Python入门,Python基础教程。
 最新文章