恩格尔方格是著名的锻炼注意力的游戏,今天,我就用python写一个恩格尔方格游戏。
先看下效果:


这个游戏是用python的pygame这个第三方模块编写的,可以用pip安装。
pip install pygame
代码也不长,也就差不多100行,现在上代码:
import pygame
import random
import time
pygame.init()
screen = pygame.display.set_mode([400,450])
pygame.display.set_caption("恩格尔方格")
keep_going = True
WHITE = (255,255,255)
BLUE = (0,0,255)
RED = (255,0,0)
font1 = pygame.font.Font("宋体.ttc", 50)
font2 = pygame.font.Font("宋体.ttc", 25)
number_list = list(range(1, 26))
random.shuffle(number_list)
t = time.time()
and_time = 0
number = 0
times = 0
fraction = 0
a = 1
def word(text, font, color, x, y):
font_rect = font.render(text, True, color)
screen.blit(font_rect, (x, y))
def line():
x

本文介绍了如何使用Python的pygame模块编写一个恩格尔方格游戏。通过展示游戏效果,作者分享了大约100行代码实现这个游戏,并提示注意字体文件的获取方式。
最低0.47元/天 解锁文章

2891

被折叠的 条评论
为什么被折叠?



