当前位置:首页>python>10个Python小游戏(含源码),这个寒假让我们一起边玩边学,开学后小白变大神!

10个Python小游戏(含源码),这个寒假让我们一起边玩边学,开学后小白变大神!

  • 2026-07-01 15:50:45
10个Python小游戏(含源码),这个寒假让我们一起边玩边学,开学后小白变大神!
相信不少同学都已经放寒假了,是不是已经把学习抛之脑后了

这个时候就会有人说:学习编程是一件非常枯燥无味的事情。其实,大家有没有认真想过,可能是我们的学习方法不对?

比方说,你有没有想过,可以通过打游戏来学编程?

今天我想跟大家分享10个Python小游戏,教你如何通过边打游戏边学编程!

【文末领取更多Python游戏项目源码】

接下来就一起来看看吧~

1、飞机大战

源码分享:
import randomimport pygamefrom objects import Background, Player, Enemy, Bullet, Explosion, Fuel, \                    Powerup, Button, Message, BlinkingTextpygame.init()SCREEN = WIDTH, HEIGHT = 288512info = pygame.display.Info()width = info.current_wheight = info.current_hif width >= height:    win = pygame.display.set_mode(SCREEN, pygame.NOFRAME)else:    win = pygame.display.set_mode(SCREEN, pygame.NOFRAME | pygame.SCALED | pygame.FULLSCREEN)clock = pygame.time.Clock()FPS = 60# COLORS **********************************************************************WHITE = (255255255)BLUE = (30144,255)RED = (25500)GREEN = (02550)BLACK = (0020)# IMAGES **********************************************************************plane_img = pygame.image.load('Assets/plane.png')logo_img = pygame.image.load('Assets/logo.png')fighter_img = pygame.image.load('Assets/fighter.png')clouds_img = pygame.image.load('Assets/clouds.png')clouds_img = pygame.transform.scale(clouds_img, (WIDTH, 350))home_img = pygame.image.load('Assets/Buttons/homeBtn.png')replay_img = pygame.image.load('Assets/Buttons/replay.png')sound_off_img = pygame.image.load("Assets/Buttons/soundOffBtn.png")sound_on_img = pygame.image.load("Assets/Buttons/soundOnBtn.png")# BUTTONS *********************************************************************home_btn = Button(home_img, (2424), WIDTH // 4 - 18, HEIGHT//2 + 120)replay_btn = Button(replay_img, (36,36), WIDTH // 2  - 18, HEIGHT//2 + 115)sound_btn = Button(sound_on_img, (2424), WIDTH - WIDTH // 4 - 18, HEIGHT//2 + 120)# FONTS ***********************************************************************game_over_font = 'Fonts/ghostclan.ttf'tap_to_play_font = 'Fonts/BubblegumSans-Regular.ttf'score_font = 'Fonts/DalelandsUncialBold-82zA.ttf'final_score_font = 'Fonts/DroneflyRegular-K78LA.ttf'game_over_msg = Message(WIDTH//223030, 'Game Over', game_over_font, WHITE, win)score_msg = Message(WIDTH-502830, '0', final_score_font, RED, win)final_score_msg = Message(WIDTH//228030, '0', final_score_font, RED, win)tap_to_play_msg = tap_to_play = BlinkingText(WIDTH//2, HEIGHT-6025"Tap To Play",                 tap_to_play_font, WHITE, win)# SOUNDS **********************************************************************player_bullet_fx = pygame.mixer.Sound('Sounds/gunshot.wav')click_fx = pygame.mixer.Sound('Sounds/click.mp3')collision_fx = pygame.mixer.Sound('Sounds/mini_exp.mp3')blast_fx = pygame.mixer.Sound('Sounds/blast.wav')fuel_fx = pygame.mixer.Sound('Sounds/fuel.wav')pygame.mixer.music.load('Sounds/Defrini - Spookie.mp3')pygame.mixer.music.play(loops=-1)pygame.mixer.music.set_volume(0.1)# GROUPS & OBJECTS ************************************************************bg = Background(win)p = Player(144, HEIGHT - 100)enemy_group = pygame.sprite.Group()player_bullet_group = pygame.sprite.Group()enemy_bullet_group = pygame.sprite.Group()explosion_group = pygame.sprite.Group()fuel_group = pygame.sprite.Group()powerup_group = pygame.sprite.Group()# FUNCTIONS *******************************************************************def shoot_bullet():    x, y = p.rect.center[0], p.rect.y    if p.powerup > 0:        for dx in range(-34):            b = Bullet(x, y, 4, dx)            player_bullet_group.add(b)        p.powerup -= 1    else:        b = Bullet(x-30, y, 6)        player_bullet_group.add(b)        b = Bullet(x+30, y, 6)        player_bullet_group.add(b)    player_bullet_fx.play()def reset():    enemy_group.empty()    player_bullet_group.empty()    enemy_bullet_group.empty()    explosion_group.empty()    fuel_group.empty()    powerup_group.empty()    p.reset(p.x, p.y)# VARIABLES *******************************************************************level = 1plane_destroy_count = 0plane_frequency = 5000start_time = pygame.time.get_ticks()moving_left = Falsemoving_right = Falsehome_page = Truegame_page = Falsescore_page = Falsescore = 0sound_on = Truerunning = Truewhile running:    for event in pygame.event.get():        if event.type == pygame.QUIT:            running = False        if event.type == pygame.KEYDOWN:            if event.key == pygame.K_ESCAPE or event.key == pygame.K_q:                running = False        if event.type == pygame.KEYDOWN and game_page:            if event.key == pygame.K_LEFT:                moving_left = True            if event.key == pygame.K_RIGHT:                moving_right = True            if event.key == pygame.K_SPACE:                shoot_bullet()        if event.type == pygame.MOUSEBUTTONDOWN:            if home_page:                home_page = False                game_page = True                click_fx.play()            elif game_page:                x, y = event.pos                if p.rect.collidepoint((x,y)):                    shoot_bullet()                elif x <= WIDTH // 2:                    moving_left = True                elif x > WIDTH // 2:                    moving_right = True        if event.type == pygame.KEYUP:            moving_left = False            moving_right = False        if event.type == pygame.MOUSEBUTTONUP:            moving_left = False            moving_right = False    if home_page:        win.fill(BLACK)        win.blit(logo_img, (3080))        win.blit(fighter_img, (WIDTH//2 - 50, HEIGHT//2))        pygame.draw.circle(win, WHITE, (WIDTH//2, HEIGHT//2 + 50), 504)        tap_to_play_msg.update()    if score_page:        win.fill(BLACK)        win.blit(logo_img, (3050))        game_over_msg.update()        final_score_msg.update(score)        if home_btn.draw(win):            home_page = True            game_page = False            score_page = False            reset()            click_fx.play()            plane_destroy_count = 0            level = 1            score = 0        if replay_btn.draw(win):            score_page = False            game_page = True            reset()            click_fx.play()            plane_destroy_count = 0            score = 0        if sound_btn.draw(win):            sound_on = not sound_on            if sound_on:                sound_btn.update_image(sound_on_img)                pygame.mixer.music.play(loops=-1)            else:                sound_btn.update_image(sound_off_img)                pygame.mixer.music.stop()    if game_page:        current_time = pygame.time.get_ticks()        delta_time = current_time - start_time        if delta_time >= plane_frequency:            if level == 1:                type = 1            elif level == 2:                type = 2            elif level == 3:                type = 3            elif level == 4:                type = random.randint(45)            elif level == 5:                type = random.randint(15)            x = random.randint(10, WIDTH - 100)            e = Enemy(x, -150, type)            enemy_group.add(e)            start_time = current_time        if plane_destroy_count:            if plane_destroy_count % 5 == 0 and level < 5:                level += 1                plane_destroy_count = 0        p.fuel -= 0.05        bg.update(1)        win.blit(clouds_img, (070))        p.update(moving_left, moving_right, explosion_group)        p.draw(win)        player_bullet_group.update()        player_bullet_group.draw(win)        enemy_bullet_group.update()        enemy_bullet_group.draw(win)        explosion_group.update()        explosion_group.draw(win)        fuel_group.update()        fuel_group.draw(win)        powerup_group.update()        powerup_group.draw(win)        enemy_group.update(enemy_bullet_group, explosion_group)        enemy_group.draw(win)        if p.alive:            player_hit = pygame.sprite.spritecollide(p, enemy_bullet_group, False)            for bullet in player_hit:                p.health -= bullet.damage                x, y = bullet.rect.center                explosion = Explosion(x, y, 1)                explosion_group.add(explosion)                bullet.kill()                collision_fx.play()            for bullet in player_bullet_group:                planes_hit = pygame.sprite.spritecollide(bullet, enemy_group, False)                for plane in planes_hit:                    plane.health -= bullet.damage                    if plane.health <= 0:                        x, y = plane.rect.center                        rand = random.random()                        if rand >= 0.9:                            power = Powerup(x, y)                            powerup_group.add(power)                        elif rand >= 0.3:                            fuel = Fuel(x, y)                            fuel_group.add(fuel)                        plane_destroy_count += 1                        blast_fx.play()                    x, y = bullet.rect.center                    explosion = Explosion(x, y, 1)                    explosion_group.add(explosion)                    bullet.kill()                    collision_fx.play()            player_collide = pygame.sprite.spritecollide(p, enemy_group, True)            if player_collide:                x, y = p.rect.center                explosion = Explosion(x, y, 2)                explosion_group.add(explosion)                x, y = player_collide[0].rect.center                explosion = Explosion(x, y, 2)                explosion_group.add(explosion)                p.health = 0                p.alive = False            if pygame.sprite.spritecollide(p, fuel_group, True):                p.fuel += 25                if p.fuel >= 100:                    p.fuel = 100                fuel_fx.play()            if pygame.sprite.spritecollide(p, powerup_group, True):                p.powerup += 2                fuel_fx.play()        if not p.alive or p.fuel <= -10:            if len(explosion_group) == 0:                game_page = False                score_page = True                reset()        score += 1        score_msg.update(score)        fuel_color = RED if p.fuel <= 40 else GREEN        pygame.draw.rect(win, fuel_color, (3020, p.fuel, 10), border_radius=4)        pygame.draw.rect(win, WHITE, (302010010), 2, border_radius=4)        pygame.draw.rect(win, BLUE, (3032, p.health, 10), border_radius=4)        pygame.draw.rect(win, WHITE, (303210010), 2, border_radius=4)        win.blit(plane_img, (1015))    pygame.draw.rect(win, WHITE, (0,0, WIDTH, HEIGHT), 5, border_radius=4)    clock.tick(FPS)    pygame.display.update()pygame.quit()

2、愤怒的墙

源码分享:
import pygameimport randomfrom objects import Player, Bar, Ball, Block, ScoreCard, Message, Particle, generate_particlespygame.init()SCREEN = WIDTH, HEIGHT = 288512info = pygame.display.Info()width = info.current_wheight = info.current_hif width >= height:    win = pygame.display.set_mode(SCREEN, pygame.NOFRAME)else:    win = pygame.display.set_mode(SCREEN, pygame.NOFRAME | pygame.SCALED | pygame.FULLSCREEN)clock = pygame.time.Clock()FPS = 45# COLORSRED = (25500)WHITE = (255255255)BLACK = (000)GRAY = (546979)c_list = [RED, BLACK, WHITE]# Fontspygame.font.init()score_font = pygame.font.Font('Fonts/BubblegumSans-Regular.ttf', 50)# Soundscoin_fx = pygame.mixer.Sound('Sounds/coin.mp3')death_fx = pygame.mixer.Sound('Sounds/death.mp3')move_fx = pygame.mixer.Sound('Sounds/move.mp3')# backgroundsbg_list = []for i in range(1,5):    if i == 2:        ext = "jpeg"    else:        ext = "jpg"    img = pygame.image.load(f"Assets/Backgrounds/bg{i}.{ext}")    img = pygame.transform.scale(img, (WIDTH, HEIGHT))    bg_list.append(img)home_bg = pygame.image.load(f"Assets/Backgrounds/home.jpeg")bg = home_bg# objectsbar_group = pygame.sprite.Group()ball_group = pygame.sprite.Group()block_group = pygame.sprite.Group()destruct_group = pygame.sprite.Group()win_particle_group = pygame.sprite.Group()bar_gap = 120particles = []p = Player(win)score_card = ScoreCard(14040, win)# Functionsdef destroy_bird():    x, y = p.rect.center    for i in range (50):        c = random.choice(c_list)        particle = Particle(x,y, 1,c, win)        destruct_group.add(particle)def win_particles():    for x,y in [(40, 120), (WIDTH - 20, 240), (15, HEIGHT - 30)]:        for i in range(10):            particle = Particle (x,y, 2, WHITE, win)            win_particle_group.add(particle)# Messagestitle_font = "Fonts/Robus-BWqOd.otf"dodgy = Message(134, 90, 100, "Angry",title_font, WHITE, win)walls = Message(164, 145, 80, "Walls",title_font, WHITE, win)tap_to_play_font = "Fonts/DebugFreeTrial-MVdYB.otf"tap_to_play = Message(144, 400, 32, "TAP TO PLAY",tap_to_play_font, WHITE, win)tap_to_replay = Message(144, 400, 30, "Tap to Replay",tap_to_play_font, WHITE, win)# Variablesbar_width_list = [i for i in range (40,150,10)]bar_frequency = 1200bar_speed = 4touched = Falsepos = Nonehome_page = Truescore_page = Falsebird_dead = Falsescore = 0high_score = 0move_left = Falsemove_right = Trueprev_x = 0p_count = 0running = Truewhile running:    win.blit(bg, (0,0))    for event in pygame.event.get():        if event.type == pygame.QUIT:            running = False        if event.type == pygame.KEYDOWN:            if event.key == pygame.K_ESCAPE:                running = False        if event.type == pygame.MOUSEBUTTONDOWN and (home_page or score_page):            home_page = False            score_page = False            win_particle_group.empty()            bg = random.choice(bg_list)            particles = []            last_bar = pygame.time.get_ticks() - bar_frequency            next_bar = 0            bar_speed = 4            bar_frequency = 1200            bird_dead = False            score = 0            p_count = 0            score_list = []            for _ in range(15):                x = random.randint(30, WIDTH - 30)                y = random.randint(60, HEIGHT - 60)                max = random.randint(8,16)                b = Block(x,y,max, win)                block_group.add(b)        if event.type == pygame.MOUSEBUTTONDOWN and not home_page:            if p.rect.collidepoint(event.pos):                touched = True                x, y = event.pos                offset_x = p.rect.x - x        if event.type == pygame.MOUSEBUTTONUP and not home_page:            touched = False        if event.type == pygame.MOUSEMOTION and not home_page:            if touched:                x, y = event.pos                if move_right and prev_x > x:                    move_right = False                    move_left = True                    move_fx.play()                if move_left and  prev_x < x:                    move_right = True                    move_left = False                    move_fx.play()                prev_x = x                p.rect.x =  x + offset_x    if home_page:        bg = home_bg        particles = generate_particles(p, particles, WHITE, win)        dodgy.update()        walls.update()        tap_to_play.update()        p.update()    elif score_page:        bg = home_bg        particles = generate_particles(p, particles, WHITE, win)        tap_to_replay.update()        p.update()        score_msg.update()        score_point.update()        if p_count % 5 == 0:            win_particles()        p_count += 1        win_particle_group.update()    else:        next_bar = pygame.time.get_ticks()        if next_bar - last_bar >= bar_frequency and not bird_dead:            bwidth = random.choice(bar_width_list)            b1prime = Bar(0,0,bwidth+3,GRAY, win)            b1 = Bar(0,-3,bwidth,WHITE,win)            b2prime = Bar(bwidth+bar_gap+30, WIDTH - bwidth - bar_gap, GRAY, win)            b2 = Bar(bwidth+bar_gap, -3, WIDTH - bwidth - bar_gap, WHITE, win)            bar_group.add(b1prime)            bar_group.add(b1)            bar_group.add(b2prime)            bar_group.add(b2)            color = random.choice(["red""white"])            pos = random.choice([0,1])            if pos == 0:                x = bwidth + 12            elif pos == 1:                x = bwidth + bar_gap - 12            ball = Ball(x, 101, color, win)            ball_group.add(ball)            last_bar = next_bar        for ball in ball_group:            if ball.rect.colliderect(p):                if ball.color == "white":                    ball.kill()                    coin_fx.play()                    score += 1                    if score > high_score:                        high_score += 1                    score_card.animate = True                elif ball.color == "red":                    if not bird_dead:                        death_fx.play()                        destroy_bird()                    bird_dead = True                    bar_speed = 0        if pygame.sprite.spritecollide(p, bar_group, False):            if not bird_dead:                death_fx.play()                destroy_bird()            bird_dead = True            bar_speed = 0        block_group.update()        bar_group.update(bar_speed)        ball_group.update(bar_speed)        if bird_dead:                destruct_group.update()        score_card.update(score)        if not bird_dead:            particles = generate_particles(p, particles, WHITE, win)            p.update()        if score and score % 10 == 0:            rem = score // 10            if rem not in score_list:                score_list.append(rem)                bar_speed += 1                bar_frequency -= 200        if bird_dead and len(destruct_group) == 0:            score_page = True            font =  "Fonts/BubblegumSans-Regular.ttf"            if score < high_score:                score_msg = Message(1446055"Score",font, WHITE, win)            else:                score_msg = Message(1446055"New High",font, WHITE, win)            score_point = Message(14411045, f"{score}", font, WHITE, win)        if score_page:            block_group.empty()            bar_group.empty()            ball_group.empty()            p.reset()    clock.tick(FPS)    pygame.display.update()pygame.quit()

3、圆弧冲刺

源码分享:
import randomimport pygamefrom objects import Player, Balls, Dot, Shadow, Particle, Message, BlinkingText, Buttonpygame.init()SCREEN = WIDTH, HEIGHT = 288512CENTER = WIDTH //2, HEIGHT // 2info = pygame.display.Info()width = info.current_wheight = info.current_hif width >= height:    win = pygame.display.set_mode(SCREEN, pygame.NOFRAME)else:    win = pygame.display.set_mode(SCREEN, pygame.NOFRAME | pygame.SCALED | pygame.FULLSCREEN)clock = pygame.time.Clock()FPS = 60# COLORS **********************************************************************RED = (255,0,0)GREEN = (0,177,64)BLUE = (30144,255)ORANGE = (252,76,2)YELLOW = (254,221,0)PURPLE = (155,38,182)AQUA = (0,103,127)WHITE = (255,255,255)BLACK = (0,0,0)color_list = [RED, GREEN, BLUE, ORANGE, YELLOW, PURPLE]color_index = 0color = color_list[color_index]# FONTS ***********************************************************************title_font = "Fonts/Aladin-Regular.ttf"tap_to_play_font = "Fonts/BubblegumSans-Regular.ttf"score_font = "Fonts/DalelandsUncialBold-82zA.ttf"game_over_font = "Fonts/ghostclan.ttf"# MESSAGES ********************************************************************arc = Message(WIDTH-9020080"Arc", title_font, WHITE, win)dash = Message(8030060"Dash", title_font, WHITE, win)tap_to_play = BlinkingText(WIDTH//2, HEIGHT-6020"Tap To Play", tap_to_play_font, WHITE, win)game_msg = Message(8015040"GAME", game_over_font, BLACK, win)over_msg = Message(21015040"OVER!", game_over_font, WHITE, win)score_text = Message(9023020"SCORE", None, BLACK, win)best_text = Message(20023020"BEST", None, BLACK, win)score_msg = Message(WIDTH-605050"0", score_font, WHITE, win)final_score_msg = Message(9028040"0", tap_to_play_font, BLACK, win)high_score_msg = Message(20028040"0", tap_to_play_font, BLACK, win)# SOUNDS **********************************************************************score_fx = pygame.mixer.Sound('Sounds/point.mp3')death_fx = pygame.mixer.Sound('Sounds/dead.mp3')score_page_fx = pygame.mixer.Sound('Sounds/score_page.mp3')pygame.mixer.music.load('Sounds/hk.mp3')pygame.mixer.music.play(loops=-1)pygame.mixer.music.set_volume(0.5)# Button imageshome_img = pygame.image.load('Assets/homeBtn.png')replay_img = pygame.image.load('Assets/replay.png')sound_off_img = pygame.image.load("Assets/soundOffBtn.png")sound_on_img = pygame.image.load("Assets/soundOnBtn.png")# Buttonshome_btn = Button(home_img, (2424), WIDTH // 4 - 18390)replay_btn = Button(replay_img, (36,36), WIDTH // 2  - 18382)sound_btn = Button(sound_on_img, (2424), WIDTH - WIDTH // 4 - 18390)# GAME VARIABLES **************************************************************MAX_RAD = 120rad_delta = 50# OBJECTS *********************************************************************ball_group = pygame.sprite.Group()dot_group = pygame.sprite.Group()shadow_group = pygame.sprite.Group()particle_group = pygame.sprite.Group()p = Player(win)ball_positions = [(CENTER[0]-105, CENTER[1]), (CENTER[0]+105, CENTER[1]),                    (CENTER[0]-45, CENTER[1]), (CENTER[0]+45, CENTER[1]),                    (CENTER[0], CENTER[1]-75), (CENTER[0], CENTER[1]+75)]for index, pos in enumerate(ball_positions):    if index in (0,1):        type_ = 1        inverter = 5    if index in (2,3):        type_ = 1        inverter = 3    if index in (4,5):        type_ = 2        inverter = 1    ball = Balls(pos, type_, inverter, win)    ball_group.add(ball)dot_list = [(CENTER[0], CENTER[1]-MAX_RAD+3), (CENTER[0]+MAX_RAD-3, CENTER[1]),            (CENTER[0], CENTER[1]+MAX_RAD-3), (CENTER[0]-MAX_RAD+3, CENTER[1])]dot_index = random.choice([1,2,3,4])dot_pos = dot_list[dot_index-1]dot = Dot(*dot_pos, win)dot_group.add(dot)shadow = Shadow(dot_index, win)shadow_group.add(shadow)# VARIABLES *******************************************************************clicked = Falsenum_clicks = 0player_alive = Truesound_on = Truescore = 0highscore = 0home_page = Truegame_page = Falsescore_page = Falserunning = Truewhile running:    win.fill(color)    for event in pygame.event.get():        if event.type == pygame.QUIT:            running = False        if event.type == pygame.KEYDOWN:            if event.key == pygame.K_ESCAPE or \                event.key == pygame.K_q:                running = False        if event.type == pygame.MOUSEBUTTONDOWN and home_page:            home_page = False            game_page = True            score_page = False            rad_delta = 50            clicked = True            score = 0            num_clicks = 0            player_alive = True        if event.type == pygame.MOUSEBUTTONDOWN and game_page:            if not clicked:                clicked = True                for ball in ball_group:                    if num_clicks % ball.inverter == 0:                        ball.dtheta *= -1                p.set_move(dot_index)                num_clicks += 1                if num_clicks % 5 == 0:                    color_index += 1                    if color_index > len(color_list) - 1:                        color_index = 0                    color = color_list[color_index]        if event.type == pygame.MOUSEBUTTONDOWN and game_page:            clicked = False    if home_page:        for radius in [30, 60, 90, 120]:            pygame.draw.circle(win, (0,0,0), CENTER, radius, 8)            pygame.draw.circle(win, (255,255,255), CENTER, radius, 5)        pygame.draw.rect(win, color, [CENTER[0]-10, CENTER[1]-MAX_RAD, MAX_RAD+50, MAX_RAD])        pygame.draw.rect(win, color, [CENTER[0]-MAX_RAD, CENTER[1]-10, MAX_RAD, MAX_RAD+50])        arc.update()        dash.update()        tap_to_play.update()    if score_page:        game_msg.update()        over_msg.update()        score_text.update(shadow=False)        best_text.update(shadow=False)        final_score_msg.update(score, shadow=False)        high_score_msg.update(highscore, shadow=False)        if home_btn.draw(win):            home_page = True            score_page = False            game_page = False            score = 0            score_msg = Message(WIDTH-60, 50, 50, "0", score_font, WHITE, win)        if replay_btn.draw(win):            home_page = False            score_page = False            game_page = True            player_alive = True            score = 0            score_msg = Message(WIDTH-60, 50, 50, "0", score_font, WHITE, win)            p = Player(win)        if sound_btn.draw(win):            sound_on = not sound_on            if sound_on:                sound_btn.update_image(sound_on_img)                pygame.mixer.music.play(loops=-1)            else:                sound_btn.update_image(sound_off_img)                pygame.mixer.music.stop()    if game_page:        for radius in [30 + rad_delta, 60 + rad_delta, 90 + rad_delta, 120 + rad_delta]:            if rad_delta > 0:                radius -= 1                rad_delta -= 1            pygame.draw.circle(win, (0,0,0), CENTER, radius, 5)        pygame.draw.rect(win, color, [CENTER[0]-10, CENTER[1]-MAX_RAD, 20, MAX_RAD*2])        pygame.draw.rect(win, color, [CENTER[0]-MAX_RAD, CENTER[1]-10, MAX_RAD*2, 20])        if rad_delta <= 0:            p.update(player_alive, color, shadow_group)            shadow_group.update()            ball_group.update()            dot_group.update()            particle_group.update()            score_msg.update(score)            for dot in dot_group:                if dot.rect.colliderect(p):                    dot.kill()                    score_fx.play()                    score += 1                    if highscore <= score:                        highscore = score            if pygame.sprite.spritecollide(p, ball_group, False) and player_alive:                death_fx.play()                x, y = p.rect.center                for i in range(20):                    particle = Particle(x, y, WHITE, win)                    particle_group.add(particle)                player_alive = False                p.reset()            if p.can_move and len(dot_group) == 0 and player_alive:                dot_index = random.randint(1,4)                dot_pos = dot_list[dot_index-1]                dot = Dot(*dot_pos, win)                dot_group.add(dot)                shadow_group.empty()                shadow = Shadow(dot_index, win)                shadow_group.add(shadow)            if not player_alive and len(particle_group) == 0:                game_page = False                score_page = True                dot_group.empty()                shadow_group.empty()                for ball in ball_group:                    ball.reset()                score_page_fx.play()    pygame.draw.rect(win, WHITE, (00, WIDTH, HEIGHT), 5, border_radius=10)    clock.tick(FPS)    pygame.display.update()pygame.quit()

4、吃金币

源码分享:

import osimport cfgimport sysimport pygameimport randomfrom modules import *'''游戏初始化'''def initGame():    # 初始化pygame, 设置展示窗口    pygame.init()    screen = pygame.display.set_mode(cfg.SCREENSIZE)    # 加载必要的游戏素材    game_images = {}    for key, value in cfg.IMAGE_PATHS.items():        if isinstance(value, list):            images = []            for item in value: images.append(pygame.image.load(item))            game_images[key] = images        else:            game_images[key] = pygame.image.load(value)    game_sounds = {}    for key, value in cfg.AUDIO_PATHS.items():        if key == 'bgm'continue        game_sounds[key] = pygame.mixer.Sound(value)    # 返回初始化数据    return screen, game_images, game_sounds'''主函数'''def main():    # 初始化    screen, game_images, game_sounds = initGame()    # 播放背景音乐    pygame.mixer.music.load(cfg.AUDIO_PATHS['bgm'])    pygame.mixer.music.play(-10.0)    # 字体加载    font = pygame.font.Font(cfg.FONT_PATH, 40)    # 定义hero    hero = Hero(game_images['hero'], position=(375520))    # 定义食物组    food_sprites_group = pygame.sprite.Group()    generate_food_freq = random.randint(1020)    generate_food_count = 0    # 当前分数/历史最高分    score = 0    highest_score = 0 if not os.path.exists(cfg.HIGHEST_SCORE_RECORD_FILEPATH) else int(open(cfg.HIGHEST_SCORE_RECORD_FILEPATH).read())    # 游戏主循环    clock = pygame.time.Clock()    while True:        # --填充背景        screen.fill(0)        screen.blit(game_images['background'], (00))        # --倒计时信息        countdown_text = 'Count down: ' + str((90000 - pygame.time.get_ticks()) // 60000) + ":" + str((90000 - pygame.time.get_ticks()) // 1000 % 60).zfill(2)        countdown_text = font.render(countdown_text, True, (000))        countdown_rect = countdown_text.get_rect()        countdown_rect.topright = [cfg.SCREENSIZE[0]-305]        screen.blit(countdown_text, countdown_rect)        # --按键检测        for event in pygame.event.get():            if event.type == pygame.QUIT:                pygame.quit()                sys.exit()        key_pressed = pygame.key.get_pressed()        if key_pressed[pygame.K_a] or key_pressed[pygame.K_LEFT]:            hero.move(cfg.SCREENSIZE, 'left')        if key_pressed[pygame.K_d] or key_pressed[pygame.K_RIGHT]:            hero.move(cfg.SCREENSIZE, 'right')        # --随机生成食物        generate_food_count += 1        if generate_food_count > generate_food_freq:            generate_food_freq = random.randint(1020)            generate_food_count = 0            food = Food(game_images, random.choice(['gold',] * 10 + ['apple']), cfg.SCREENSIZE)            food_sprites_group.add(food)        # --更新食物        for food in food_sprites_group:            if food.update(): food_sprites_group.remove(food)        # --碰撞检测        for food in food_sprites_group:            if pygame.sprite.collide_mask(food, hero):                game_sounds['get'].play()                food_sprites_group.remove(food)                score += food.score                if score > highest_score: highest_score = score        # --画hero        hero.draw(screen)        # --画食物        food_sprites_group.draw(screen)        # --显示得分        score_text = f'Score: {score}, Highest: {highest_score}'        score_text = font.render(score_text, True, (000))        score_rect = score_text.get_rect()        score_rect.topleft = [55]        screen.blit(score_text, score_rect)        # --判断游戏是否结束        if pygame.time.get_ticks() >= 90000:            break        # --更新屏幕        pygame.display.flip()        clock.tick(cfg.FPS)    # 游戏结束, 记录最高分并显示游戏结束画面    fp = open(cfg.HIGHEST_SCORE_RECORD_FILEPATH, 'w')    fp.write(str(highest_score))    fp.close()    return showEndGameInterface(screen, cfg, score, highest_score)'''run'''if __name__ == '__main__':    while main():        pass

5、打地鼠

源码分享:
import cfgimport sysimport pygameimport randomfrom modules import *'''游戏初始化'''def initGame():    pygame.init()    pygame.mixer.init()    screen = pygame.display.set_mode(cfg.SCREENSIZE)    pygame.display.set_caption('打地鼠 —— 九歌')    return screen'''主函数'''def main():    # 初始化    screen = initGame()    # 加载背景音乐和其他音效    pygame.mixer.music.load(cfg.BGM_PATH)    pygame.mixer.music.play(-1)    audios = {        'count_down': pygame.mixer.Sound(cfg.COUNT_DOWN_SOUND_PATH),        'hammering': pygame.mixer.Sound(cfg.HAMMERING_SOUND_PATH)    }    # 加载字体    font = pygame.font.Font(cfg.FONT_PATH, 40)    # 加载背景图片    bg_img = pygame.image.load(cfg.GAME_BG_IMAGEPATH)    # 开始界面    startInterface(screen, cfg.GAME_BEGIN_IMAGEPATHS)    # 地鼠改变位置的计时    hole_pos = random.choice(cfg.HOLE_POSITIONS)    change_hole_event = pygame.USEREVENT    pygame.time.set_timer(change_hole_event, 800)    # 地鼠    mole = Mole(cfg.MOLE_IMAGEPATHS, hole_pos)    # 锤子    hammer = Hammer(cfg.HAMMER_IMAGEPATHS, (500250))    # 时钟    clock = pygame.time.Clock()    # 分数    your_score = 0    flag = False    # 初始时间    init_time = pygame.time.get_ticks()    # 游戏主循环    while True:        # --游戏时间为60s        time_remain = round((61000 - (pygame.time.get_ticks() - init_time)) / 1000.)        # --游戏时间减少, 地鼠变位置速度变快        if time_remain == 40 and not flag:            hole_pos = random.choice(cfg.HOLE_POSITIONS)            mole.reset()            mole.setPosition(hole_pos)            pygame.time.set_timer(change_hole_event, 650)            flag = True        elif time_remain == 20 and flag:            hole_pos = random.choice(cfg.HOLE_POSITIONS)            mole.reset()            mole.setPosition(hole_pos)            pygame.time.set_timer(change_hole_event, 500)            flag = False        # --倒计时音效        if time_remain == 10:            audios['count_down'].play()        # --游戏结束        if time_remain < 0break        count_down_text = font.render('Time: '+str(time_remain), True, cfg.WHITE)        # --按键检测        for event in pygame.event.get():            if event.type == pygame.QUIT:                pygame.quit()                sys.exit()            elif event.type == pygame.MOUSEMOTION:                hammer.setPosition(pygame.mouse.get_pos())            elif event.type == pygame.MOUSEBUTTONDOWN:                if event.button == 1:                    hammer.setHammering()            elif event.type == change_hole_event:                hole_pos = random.choice(cfg.HOLE_POSITIONS)                mole.reset()                mole.setPosition(hole_pos)        # --碰撞检测        if hammer.is_hammering and not mole.is_hammer:            is_hammer = pygame.sprite.collide_mask(hammer, mole)            if is_hammer:                audios['hammering'].play()                mole.setBeHammered()                your_score += 10        # --分数        your_score_text = font.render('Score: '+str(your_score), True, cfg.BROWN)        # --绑定必要的游戏元素到屏幕(注意顺序)        screen.blit(bg_img, (00))        screen.blit(count_down_text, (8758))        screen.blit(your_score_text, (800430))        mole.draw(screen)        hammer.draw(screen)        # --更新        pygame.display.flip()        clock.tick(60)    # 读取最佳分数(try块避免第一次游戏无.rec文件)    try:        best_score = int(open(cfg.RECORD_PATH).read())    except:        best_score = 0    # 若当前分数大于最佳分数则更新最佳分数    if your_score > best_score:        f = open(cfg.RECORD_PATH, 'w')        f.write(str(your_score))        f.close()    # 结束界面    score_info = {'your_score': your_score, 'best_score': best_score}    is_restart = endInterface(screen, cfg.GAME_END_IMAGEPATH, cfg.GAME_AGAIN_IMAGEPATHS, score_info, cfg.FONT_PATH, [cfg.WHITE, cfg.RED], cfg.SCREENSIZE)    return is_restart'''run'''if __name__ == '__main__':    while True:        is_restart = main()        if not is_restart:            break

6、小恐龙

玩法:上下控制起跳躲避
源码分享:
import cfgimport sysimport randomimport pygamefrom modules import *'''main'''def main(highest_score):    # 游戏初始化    pygame.init()    screen = pygame.display.set_mode(cfg.SCREENSIZE)    pygame.display.set_caption('九歌')    # 导入所有声音文件    sounds = {}    for key, value in cfg.AUDIO_PATHS.items():        sounds[key] = pygame.mixer.Sound(value)    # 游戏开始界面    GameStartInterface(screen, sounds, cfg)    # 定义一些游戏中必要的元素和变量    score = 0    score_board = Scoreboard(cfg.IMAGE_PATHS['numbers'], position=(53415), bg_color=cfg.BACKGROUND_COLOR)    highest_score = highest_score    highest_score_board = Scoreboard(cfg.IMAGE_PATHS['numbers'], position=(43515), bg_color=cfg.BACKGROUND_COLOR, is_highest=True)    dino = Dinosaur(cfg.IMAGE_PATHS['dino'])    ground = Ground(cfg.IMAGE_PATHS['ground'], position=(0, cfg.SCREENSIZE[1]))    cloud_sprites_group = pygame.sprite.Group()    cactus_sprites_group = pygame.sprite.Group()    ptera_sprites_group = pygame.sprite.Group()    add_obstacle_timer = 0    score_timer = 0    # 游戏主循环    clock = pygame.time.Clock()    while True:        for event in pygame.event.get():            if event.type == pygame.QUIT:                pygame.quit()                sys.exit()            elif event.type == pygame.KEYDOWN:                if event.key == pygame.K_SPACE or event.key == pygame.K_UP:                    dino.jump(sounds)                elif event.key == pygame.K_DOWN:                    dino.duck()            elif event.type == pygame.KEYUP and event.key == pygame.K_DOWN:                dino.unduck()        screen.fill(cfg.BACKGROUND_COLOR)        # --随机添加云        if len(cloud_sprites_group) < 5 and random.randrange(0300) == 10:            cloud_sprites_group.add(Cloud(cfg.IMAGE_PATHS['cloud'], position=(cfg.SCREENSIZE[0], random.randrange(3075))))        # --随机添加仙人掌/飞龙        add_obstacle_timer += 1        if add_obstacle_timer > random.randrange(50150):            add_obstacle_timer = 0            random_value = random.randrange(010)            if random_value >= 5 and random_value <= 7:                cactus_sprites_group.add(Cactus(cfg.IMAGE_PATHS['cacti']))            else:                position_ys = [cfg.SCREENSIZE[1]*0.82, cfg.SCREENSIZE[1]*0.75, cfg.SCREENSIZE[1]*0.60, cfg.SCREENSIZE[1]*0.20]                ptera_sprites_group.add(Ptera(cfg.IMAGE_PATHS['ptera'], position=(600, random.choice(position_ys))))        # --更新游戏元素        dino.update()        ground.update()        cloud_sprites_group.update()        cactus_sprites_group.update()        ptera_sprites_group.update()        score_timer += 1        if score_timer > (cfg.FPS//12):            score_timer = 0            score += 1            score = min(score, 99999)            if score > highest_score:                highest_score = score            if score % 100 == 0:                sounds['point'].play()            if score % 1000 == 0:                ground.speed -= 1                for item in cloud_sprites_group:                    item.speed -= 1                for item in cactus_sprites_group:                    item.speed -= 1                for item in ptera_sprites_group:                    item.speed -= 1        # --碰撞检测        for item in cactus_sprites_group:            if pygame.sprite.collide_mask(dino, item):                dino.die(sounds)        for item in ptera_sprites_group:            if pygame.sprite.collide_mask(dino, item):                dino.die(sounds)        # --将游戏元素画到屏幕上        dino.draw(screen)        ground.draw(screen)        cloud_sprites_group.draw(screen)        cactus_sprites_group.draw(screen)        ptera_sprites_group.draw(screen)        score_board.set(score)        highest_score_board.set(highest_score)        score_board.draw(screen)        highest_score_board.draw(screen)        # --更新屏幕        pygame.display.update()        clock.tick(cfg.FPS)        # --游戏是否结束        if dino.is_dead:            break    # 游戏结束界面    return GameEndInterface(screen, cfg), highest_score'''run'''if __name__ == '__main__':    highest_score = 0    while True:        flag, highest_score = main(highest_score)        if not flag: break

7、消消乐

源码分享:

import osimport sysimport cfgimport pygamefrom modules import *'''游戏主程序'''def main():    pygame.init()    screen = pygame.display.set_mode(cfg.SCREENSIZE)    pygame.display.set_caption('Gemgem —— 九歌')    # 加载背景音乐    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)    # 加载音效    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)))    # 加载字体    font = pygame.font.Font(os.path.join(cfg.ROOTDIR, 'resources/font/font.TTF'), 25)    # 图片加载    gem_imgs = []    for i in range(18):        gem_imgs.append(os.path.join(cfg.ROOTDIR, 'resources/images/gem%s.png' % i))    # 主循环    game = gemGame(screen, sounds, font, gem_imgs, cfg)    while True:        score = game.start()        flag = False        # 一轮游戏结束后玩家选择重玩或者退出        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.quit()                    sys.exit()                elif event.type == pygame.KEYUP and event.key == pygame.K_r:                    flag = True            if flag:                break            screen.fill((135206235))            text0 = 'Final score: %s' % score            text1 = 'Press <R> to restart the game.'            text2 = 'Press <Esc> to quit the game.'            y = 150            for idx, text in enumerate([text0, text1, text2]):                text_render = font.render(text, 1, (85650))                rect = text_render.get_rect()                if idx == 0:                    rect.left, rect.top = (212, y)                elif idx == 1:                    rect.left, rect.top = (122.5, y)                else:                    rect.left, rect.top = (126.5, y)                y += 100                screen.blit(text_render, rect)            pygame.display.update()        game.reset()'''run'''if __name__ == '__main__':    main()

8、俄罗斯方块

源码分享:
import osimport sysimport randomfrom modules import *from PyQt5.QtGui import *from PyQt5.QtCore import *from PyQt5.QtWidgets import *'''定义俄罗斯方块游戏类'''class TetrisGame(QMainWindow):    def __init__(self, parent=None):        super(TetrisGame, self).__init__(parent)        # 是否暂停ing        self.is_paused = False        # 是否开始ing        self.is_started = False        self.initUI()    '''界面初始化'''    def initUI(self):        # icon        self.setWindowIcon(QIcon(os.path.join(os.getcwd(), 'resources/icon.jpg')))        # 块大小        self.grid_size = 22        # 游戏帧率        self.fps = 200        self.timer = QBasicTimer()        # 焦点        self.setFocusPolicy(Qt.StrongFocus)        # 水平布局        layout_horizontal = QHBoxLayout()        self.inner_board = InnerBoard()        self.external_board = ExternalBoard(selfself.grid_size, self.inner_board)        layout_horizontal.addWidget(self.external_board)        self.side_panel = SidePanel(selfself.grid_size, self.inner_board)        layout_horizontal.addWidget(self.side_panel)        self.status_bar = self.statusBar()        self.external_board.score_signal[str].connect(self.status_bar.showMessage)        self.start()        self.center()        self.setWindowTitle('Tetris —— 九歌')        self.show()        self.setFixedSize(self.external_board.width() + self.side_panel.width(), self.side_panel.height() + self.status_bar.height())    '''游戏界面移动到屏幕中间'''    def center(self):        screen = QDesktopWidget().screenGeometry()        size = self.geometry()        self.move((screen.width() - size.width()) // 2, (screen.height() - size.height()) // 2)    '''更新界面'''    def updateWindow(self):        self.external_board.updateData()        self.side_panel.updateData()        self.update()    '''开始'''    def start(self):        if self.is_started:            return        self.is_started = True        self.inner_board.createNewTetris()        self.timer.start(self.fps, self)    '''暂停/不暂停'''    def pause(self):        if not self.is_started:            return        self.is_paused = not self.is_paused        if self.is_paused:            self.timer.stop()            self.external_board.score_signal.emit('Paused')        else:            self.timer.start(self.fps, self)        self.updateWindow()    '''计时器事件'''    def timerEvent(self, event):        if event.timerId() == self.timer.timerId():            removed_lines = self.inner_board.moveDown()            self.external_board.score += removed_lines            self.updateWindow()        else:            super(TetrisGame, self).timerEvent(event)    '''按键事件'''    def keyPressEvent(self, event):        if not self.is_started or self.inner_board.current_tetris == tetrisShape().shape_empty:            super(TetrisGame, self).keyPressEvent(event)            return        key = event.key()        # P键暂停        if key == Qt.Key_P:            self.pause()            return        if self.is_paused:            return        # 向左        elif key == Qt.Key_Left:            self.inner_board.moveLeft()        # 向右        elif key == Qt.Key_Right:            self.inner_board.moveRight()        # 旋转        elif key == Qt.Key_Up:            self.inner_board.rotateAnticlockwise()        # 快速坠落        elif key == Qt.Key_Space:            self.external_board.score += self.inner_board.dropDown()        else:            super(TetrisGame, self).keyPressEvent(event)        self.updateWindow()'''run'''if __name__ == '__main__':    app = QApplication([])    tetris = TetrisGame()    sys.exit(app.exec_())

9、贪吃蛇

源码分享:
import cfgimport sysimport pygamefrom modules import *'''主函数'''def main(cfg):    # 游戏初始化    pygame.init()    screen = pygame.display.set_mode(cfg.SCREENSIZE)    pygame.display.set_caption('Greedy Snake —— 九歌')    clock = pygame.time.Clock()    # 播放背景音乐    pygame.mixer.music.load(cfg.BGMPATH)    pygame.mixer.music.play(-1)    # 游戏主循环    snake = Snake(cfg)    apple = Apple(cfg, snake.coords)    score = 0    while True:        screen.fill(cfg.BLACK)        # --按键检测        for event in pygame.event.get():            if event.type == pygame.QUIT:                pygame.quit()                sys.exit()            elif event.type == pygame.KEYDOWN:                if event.key in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]:                    snake.setDirection({pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'}[event.key])        # --更新贪吃蛇和食物        if snake.update(apple):            apple = Apple(cfg, snake.coords)            score += 1        # --判断游戏是否结束        if snake.isgameover: break        # --显示游戏里必要的元素        drawGameGrid(cfg, screen)        snake.draw(screen)        apple.draw(screen)        showScore(cfg, score, screen)        # --屏幕更新        pygame.display.update()        clock.tick(cfg.FPS)    return endInterface(screen, cfg)'''run'''if __name__ == '__main__':    while True:        if not main(cfg):            break

10、24点小游戏

源码分享:
import osimport sysimport pygamefrom cfg import *from modules import *from fractions import Fraction'''检查控件是否被点击'''def checkClicked(group, mouse_pos, group_type='NUMBER'):    selected = []    # 数字卡片/运算符卡片    if group_type == GROUPTYPES[0or group_type == GROUPTYPES[1]:        max_selected = 2 if group_type == GROUPTYPES[0else 1        num_selected = 0        for each in group:            num_selected += int(each.is_selected)        for each in group:            if each.rect.collidepoint(mouse_pos):                if each.is_selected:                    each.is_selected = not each.is_selected                    num_selected -= 1                    each.select_order = None                else:                    if num_selected < max_selected:                        each.is_selected = not each.is_selected                        num_selected += 1                        each.select_order = str(num_selected)            if each.is_selected:                selected.append(each.attribute)    # 按钮卡片    elif group_type == GROUPTYPES[2]:        for each in group:            if each.rect.collidepoint(mouse_pos):                each.is_selected = True                selected.append(each.attribute)    # 抛出异常    else:        raise ValueError('checkClicked.group_type unsupport %s, expect %s, %s or %s...' % (group_type, *GROUPTYPES))    return selected'''获取数字精灵组'''def getNumberSpritesGroup(numbers):    number_sprites_group = pygame.sprite.Group()    for idx, number in enumerate(numbers):        args = (*NUMBERCARD_POSITIONS[idx], str(number), NUMBERFONT, NUMBERFONT_COLORS, NUMBERCARD_COLORS, str(number))        number_sprites_group.add(Card(*args))    return number_sprites_group'''获取运算符精灵组'''def getOperatorSpritesGroup(operators):    operator_sprites_group = pygame.sprite.Group()    for idx, operator in enumerate(operators):        args = (*OPERATORCARD_POSITIONS[idx], str(operator), OPERATORFONT, OPREATORFONT_COLORS, OPERATORCARD_COLORS, str(operator))        operator_sprites_group.add(Card(*args))    return operator_sprites_group'''获取按钮精灵组'''def getButtonSpritesGroup(buttons):    button_sprites_group = pygame.sprite.Group()    for idx, button in enumerate(buttons):        args = (*BUTTONCARD_POSITIONS[idx], str(button), BUTTONFONT, BUTTONFONT_COLORS, BUTTONCARD_COLORS, str(button))        button_sprites_group.add(Button(*args))    return button_sprites_group'''计算'''def calculate(number1, number2, operator):    operator_map = {'+''+''-''-''×''*''÷''/'}    try:        result = str(eval(number1+operator_map[operator]+number2))        return result if '.' not in result else str(Fraction(number1+operator_map[operator]+number2))    except:        return None'''在屏幕上显示信息'''def showInfo(text, screen):    rect = pygame.Rect(200180400200)    pygame.draw.rect(screen, PAPAYAWHIP, rect)    font = pygame.font.Font(FONTPATH, 40)    text_render = font.render(text, True, BLACK)    font_size = font.size(text)    screen.blit(text_render, (rect.x+(rect.width-font_size[0])/2, rect.y+(rect.height-font_size[1])/2))'''主函数'''def main():    # 初始化, 导入必要的游戏素材    pygame.init()    pygame.mixer.init()    screen = pygame.display.set_mode(SCREENSIZE)    pygame.display.set_caption('24 point —— 九歌')    win_sound = pygame.mixer.Sound(AUDIOWINPATH)    lose_sound = pygame.mixer.Sound(AUDIOLOSEPATH)    warn_sound = pygame.mixer.Sound(AUDIOWARNPATH)    pygame.mixer.music.load(BGMPATH)    pygame.mixer.music.play(-10.0)    # 24点游戏生成器    game24_gen = game24Generator()    game24_gen.generate()    # 精灵组    # --数字    number_sprites_group = getNumberSpritesGroup(game24_gen.numbers_now)    # --运算符    operator_sprites_group = getOperatorSpritesGroup(OPREATORS)    # --按钮    button_sprites_group = getButtonSpritesGroup(BUTTONS)    # 游戏主循环    clock = pygame.time.Clock()    selected_numbers = []    selected_operators = []    selected_buttons = []    is_win = False    while True:        for event in pygame.event.get():            if event.type == pygame.QUIT:                pygame.quit()                sys.exit(-1)            elif event.type == pygame.MOUSEBUTTONUP:                mouse_pos = pygame.mouse.get_pos()                selected_numbers = checkClicked(number_sprites_group, mouse_pos, 'NUMBER')                selected_operators = checkClicked(operator_sprites_group, mouse_pos, 'OPREATOR')                selected_buttons = checkClicked(button_sprites_group, mouse_pos, 'BUTTON')        screen.fill(AZURE)        # 更新数字        if len(selected_numbers) == 2 and len(selected_operators) == 1:            noselected_numbers = []            for each in number_sprites_group:                if each.is_selected:                    if each.select_order == '1':                        selected_number1 = each.attribute                    elif each.select_order == '2':                        selected_number2 = each.attribute                    else:                        raise ValueError('Unknow select_order %s, expect 1 or 2...' % each.select_order)                else:                    noselected_numbers.append(each.attribute)                each.is_selected = False            for each in operator_sprites_group:                each.is_selected = False            result = calculate(selected_number1, selected_number2, *selected_operators)            if result is not None:                game24_gen.numbers_now = noselected_numbers + [result]                is_win = game24_gen.check()                if is_win:                    win_sound.play()                if not is_win and len(game24_gen.numbers_now) == 1:                    lose_sound.play()            else:                warn_sound.play()            selected_numbers = []            selected_operators = []            number_sprites_group = getNumberSpritesGroup(game24_gen.numbers_now)        # 精灵都画到screen上        for each in number_sprites_group:            each.draw(screen, pygame.mouse.get_pos())        for each in operator_sprites_group:            each.draw(screen, pygame.mouse.get_pos())        for each in button_sprites_group:            if selected_buttons and selected_buttons[0in ['RESET''NEXT']:                is_win = False            if selected_buttons and each.attribute == selected_buttons[0]:                each.is_selected = False                number_sprites_group = each.do(game24_gen, getNumberSpritesGroup, number_sprites_group, button_sprites_group)                selected_buttons = []            each.draw(screen, pygame.mouse.get_pos())        # 游戏胜利        if is_win:            showInfo('Congratulations', screen)        # 游戏失败        if not is_win and len(game24_gen.numbers_now) == 1:            showInfo('Game Over', screen)        pygame.display.flip()        clock.tick(30)'''run'''if __name__ == '__main__':    main()
如果你现在还是不会Python也没关系,下面我会给大家免费分享一份Python全套学习资料, 包含视频、源码、课件,希望能帮到那些不满现状,想提升自己却又没有方向的朋友

尾语 💝

感谢你观看我的文章呐~本次航班到这里就结束啦 🛬

希望本篇文章有对你带来帮助 🎉,有学习到一点知识~

源获取:
1、点赞+推荐 
2、后台回复:学习或/直接关注公众号点击下方的【资料领取】自助免费领取!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 12:20:35 HTTP/2.0 GET : https://f.mffb.com.cn/a/497185.html
  2. 运行时间 : 0.408865s [ 吞吐率:2.45req/s ] 内存消耗:5,566.23kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=b1e642bc252177eca05b1d32b2671a56
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000587s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000761s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000332s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.021229s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000657s ]
  6. SELECT * FROM `set` [ RunTime:0.011369s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000732s ]
  8. SELECT * FROM `article` WHERE `id` = 497185 LIMIT 1 [ RunTime:0.016048s ]
  9. UPDATE `article` SET `lasttime` = 1783052436 WHERE `id` = 497185 [ RunTime:0.003943s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.002168s ]
  11. SELECT * FROM `article` WHERE `id` < 497185 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.024899s ]
  12. SELECT * FROM `article` WHERE `id` > 497185 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.019448s ]
  13. SELECT * FROM `article` WHERE `id` < 497185 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.008240s ]
  14. SELECT * FROM `article` WHERE `id` < 497185 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.134816s ]
  15. SELECT * FROM `article` WHERE `id` < 497185 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.094974s ]
0.410487s