我正在做一个关于鸡的小游戏,我遇到了一些我找不到解决方案的问题.问题是我的文本后面有一个小矩形,如下所示:The number of coins and a rectangle behind it. 我还发现错误来自于读取文本文件,代码是:
import pygame
from pygame import *
pygame.init()
surface = pygame.display.set_mode((800,600))
pg = pygame
coins = 0
eggs = 0
time_left = 12
chickens = 0
grain = 0
with open('stats.txt', 'r') as f:
a = f.readlines()
coins = a[0]
eggs = a[1]
time_left = a[2]
chickens = a[3]
grain = a[4]
font = pg.font.Font("freesansbold.ttf", 28)
text = font.render(coins,False,(255,255,255))
run = True
while run:
surface.fill(0)
for event in pg.event.get():
if event.type == pg.QUIT:
run = False
surface.blit(text,(20,-2))
pg.display.update()
文本文件为:
0
0
12.0
0
0
我不认为我可以改变我从文件中获取信息的方式,但如果你知道一种方法并且有效,你可以让我知道.