import pgzrun#导入游戏库
import random#导入随机库
TILE_SIZE=50#小方块的大小,5050
WIDTH=10TILE_SIZE#设置窗口宽度为500
HEIGHT=10TILE_SIZE#设置窗口高度为500
stars=[]#二维数组,初始为空列表,用于存储小方块编号
for i in range(10):#对行遍历
row=[]#存储一行的数据,初始为空列表
for j in range(10):#对列遍历
x=random.randint(1,6)#取1-6的随机数
row.append(x)#把数据添加到行列表row中
stars.append(row)#再把行列表row添加到二维数组stars中
Tiles=[]#二维数组,初始为空列表,存放所有小方块图片信息
for i in range(10):
for j in range(10):
tile=Actor('star'+str(stars[i][j]))#小方块图片初始化
tile.left=jTILE_SIZE#小方块图片最左边的X坐标
tile.top=iTILE_SIZE#小方块图片最顶部的Y坐标
Tiles.append(tile)#将当前小方块加入列表中
def draw():#绘制模块,每帧重复执行
screen.clear()#每帧清除屏幕,便于重新绘制
for tile in Tiles:
tile.draw()#绘制所有的小方块
#以下绘制出所有的小方块的编号
for i in range(10):
for j in range(10):
screen.draw.text(str(stars[i][j]),(jTILE_SIZE,i*TILE_SIZE),fontsize=35,color='while')
pgzrun.go()#开始执行游戏
C:\Users\86170\AppData\Local\Programs\Python\Python310\python.exe C:/python代码/小方块.py
pygame 2.1.2 (SDL 2.0.18, Python 3.10.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\python代码\小方块.py", line 28, in
pgzrun.go()#开始执行游戏
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzrun.py", line 31, in go
run_mod(mod)
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\runner.py", line 113, in run_mod
PGZeroGame(mod).run()
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\game.py", line 217, in run
self.mainloop()
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\game.py", line 256, in mainloop
draw()
File "C:\python代码\小方块.py", line 27, in draw
screen.draw.text(str(stars[i][j]),(jTILE_SIZE,iTILE_SIZE),fontsize=35,color='while')
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\screen.py", line 61, in text
ptext.draw(*args, surf=self._surf, **kwargs)
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\ptext.py", line 439, in draw
tsurf = getsurf(text, fontname, fontsize, sysfontname, bold, italic, underline, width, widthem,
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\ptext.py", line 336, in getsurf
lsurfs = [font.render(text, antialias, color).convert_alpha()
File "C:\Users\86170\AppData\Local\Programs\Python\Python310\lib\site-packages\pgzero\ptext.py", line 336, in
lsurfs = [font.render(text, antialias, color).convert_alpha()
ValueError: invalid color argument
进程已结束,退出代码1