当前位置:   article > 正文

Python版儿童识字游戏源代码,结合植物大战僵尸和儿童识字的小游戏,含学习模式和娱乐模式_python 认字大全小游戏

python 认字大全小游戏

Python版儿童识字游戏源代码,结合植物大战僵尸和儿童识字的小游戏,含学习模式和娱乐模式。
娱乐模式下,僵尸会头顶不同的汉字,此时屏幕会提示要消灭的汉字,移动豌豆消灭对应汉字的僵尸,如果攻击非提示汉字的僵尸会反弹伤害到自己。
完整代码下载地址:Python版儿童识字游戏源代码
在这里插入图片描述
核心代码

import pygame
import sys
from pygame.locals import *
from db import *
from setting import *
from Player import Player, create_new_zombies
from Bullet import Bullet, ReturnBullet
from Button import menu_mode_buttons, game_over_buttons, all_pass_buttons, play_mode_menu
from Study import StudyModeEngine
from PlayShowCC import ShowCCGroup
from GameLevel import GameLevelShow, GameLevelProcess
from util import *

pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
game_play_mode_bgm = get_bg_music()

SPEAKER_TIP_EVENT = pygame.USEREVENT + 1
pygame.time.set_timer(SPEAKER_TIP_EVENT, 1000)
clock = pygame.time.Clock()
stage = GAME_MENU_MODE

game_level_process = GameLevelProcess()
game_level = game_level_process.get_max_game_level()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            game_level_process.update_game_level()
            sys.exit()
        elif event.type == MOUSEBUTTONDOWN:
            if stage == GAME_STUDY_MODE:
                x, y = event.pos
                study_controller.do_buttons_click(x, y, "DOWN")
        elif event.type == MOUSEBUTTONUP:
            x, y = event.pos
            if stage == GAME_STUDY_MODE:
                if study_controller.do_buttons_click(x, y, "UP"):
                    stage = GAME_MENU_MODE
            elif stage == GAME_MENU_MODE:
                for button in menu_mode_buttons:
                    if button.rect.collidepoint(x, y):
                        if button.name == "study_mode":
                            stage = GAME_STUDY_MODE
                            study_controller = StudyModeEngine()
                        elif button.name == "play_mode":
                            stage = GAME_LEVEL_MODE
                            game_play_mode_bgm.play(-1)
                        elif button.name == "game_exit":
                            game_level_process.update_game_level()
                            sys.exit()
            elif stage == GAME_LEVEL_MODE:
                x, y = event.pos
                # 是否和rect碰撞
                is_collide, game_level = game_level_process.choose_game_level(x, y)
                if is_collide:
                    player = Player()
                    bullets = pygame.sprite.Group()
                    zombies = pygame.sprite.Group()
                    return_bullets = pygame.sprite.Group()
                    game_level_process.set_playing_level(game_level)
                    show_cc_group = ShowCCGroup(screen, game_level)
                    current_text_index = game_level_process.get_current_text_index()
                    show_cc_group.set_speak_cc(current_text_index)
                    zombies = create_new_zombies(current_text_index)
                    stage = GAME_PLAY_MODE
            elif stage == GAME_PLAY_MODE:
                if play_mode_menu.rect.collidepoint(x, y):
                    stage = GAME_MENU_MODE
                    game_play_mode_bgm.stop()
            elif stage == GAME_OVER_FAIL_MODE:
                for button in game_over_buttons:
                    if button.rect.collidepoint(x, y):
                        if button.name == "play_again":
                            player = Player()
                            bullets = pygame.sprite.Group()
                            zombies = pygame.sprite.Group()
                            return_bullets = pygame.sprite.Group()
                            game_level_process.set_playing_level(game_level)
                            show_cc_group = ShowCCGroup(screen, game_level)
                            current_text_index = game_level_process.get_current_text_index()
                            show_cc_group.set_speak_cc(current_text_index)
                            zombies = create_new_zombies(current_text_index)
                            stage = GAME_PLAY_MODE
                        elif button.name == "game_over_menu":
                            stage = GAME_MENU_MODE
                            game_play_mode_bgm.stop()
            elif stage == GAME_PASS_ALL_MODE:
                for button in all_pass_buttons:
                    if button.rect.collidepoint(x, y):
                        if button.name == "pass_return":
                            stage = GAME_MENU_MODE
                            game_play_mode_bgm.stop()
                        elif button.name == "pass_exit":
                            game_level_process.update_game_level()
                            sys.exit()
        elif event.type == MOUSEMOTION:
            x, y = event.pos
            if stage == GAME_MENU_MODE:
                for menu_choice in menu_mode_buttons:
                    menu_choice.do_mouse_on(x, y)
            elif stage == GAME_PLAY_MODE:
                play_mode_menu.do_mouse_on(x, y)
            elif stage == GAME_OVER_FAIL_MODE:
                for choice_button in game_over_buttons:
                    choice_button.do_mouse_on(x, y)
            elif stage == GAME_PASS_ALL_MODE:
                for choice_button in all_pass_buttons:
                    choice_button.do_mouse_on(x, y)
        elif event.type == KEYDOWN:
            if event.key == K_DOWN:
                player.update_pos("DOWN")
            elif event.key == K_UP:
                player.update_pos("UP")
            elif event.key == K_SPACE:
                bullet = Bullet(screen, player.get_pos_index())
                bullets.add(bullet)
        elif event.type == SPEAKER_TIP_EVENT:
            if stage == GAME_PLAY_MODE:
                show_cc_group.do_text_sound_play()

    # update and draw
    if stage == GAME_MENU_MODE:
        screen.blit(menu_mode_bg, (0, 0))
        menu_mode_buttons.update()
        menu_mode_buttons.draw(screen)
    elif stage == GAME_STUDY_MODE:
        screen.blit(study_mode_bg, (0, 0))
        study_controller.update()
        study_controller.draw(screen)
    elif stage == GAME_LEVEL_MODE:
        screen.blit(level_choose_mode_bg, (0, 0))
        game_level_process.draw_game_level(screen)
    elif stage == GAME_PLAY_MODE:
        screen.blit(play_mode_bg, (0, 0))
        play_mode_menu.update()
        play_mode_menu.draw(screen)

        op_code, pos_x, pos_y = zombies_hit_by_bullets(zombies, bullets, current_text_index)
        if op_code == ZOMBIE_DIE:
            kill_sprites(zombies)
            #  答对了,翻牌
            show_cc_group.change_question_to_cc()
            stage = game_level_process.go_next()
            current_text_index = game_level_process.get_current_text_index()
            show_cc_group.set_speak_cc(current_text_index)
            zombies = create_new_zombies(current_text_index)
        elif op_code == ZOMBIE_WRONG:
            return_bullet = ReturnBullet(pos_x, pos_y)
            return_bullets.add(return_bullet)
        player_die = player.is_collide_with_them(zombies, return_bullets)
        if player_die:
            stage = GAME_OVER_FAIL_MODE
        player.update()
        player.draw(screen)
        bullets.update()
        bullets.draw(screen)
        for zombie in zombies:
            zombie.update()
            zombie.draw(screen)
        return_bullets.update()
        return_bullets.draw(screen)
        show_cc_group.update()
    elif stage == GAME_OVER_FAIL_MODE:
        screen.blit(game_over_bg, (0, 0))
        screen.blit(game_fail_widget, (443, 151))
        game_over_buttons.update()
        game_over_buttons.draw(screen)
    elif stage == GAME_PASS_ALL_MODE:
        screen.blit(game_pass_all_bg, (0, 0))
        print_pass_all_info(screen, total_cc_count)
        all_pass_buttons.update()
        all_pass_buttons.draw(screen)

    pygame.display.update()
    clock.tick(FPS)



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179

在这里插入图片描述
完整代码下载地址:Python版儿童识字游戏源代码

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/571890
推荐阅读
相关标签
  

闽ICP备14008679号