【发布时间】:2021-01-29 01:24:17
【问题描述】:
所以我想在我的 pygame 中使用 for 循环制作一个游戏地图,但显然我这样做的方式不起作用。代码如下,如果你能看一下就好了!
Pygame
import pygame
import sys
import random
import subprocess
# _______initiate Game______________ #
class Game:
pygame.init()
width = 800
height = 800
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Maze Game")
pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
white = [255, 255, 255]
black = [0, 0, 0]
lblue = [159, 210, 255]
background = input(
"What color background would you like? (White, Black, or Light Blue): ")
if background == "White":
screen.fill(white)
pygame.display.flip()
elif background == "Black":
screen.fill(black)
pygame.display.update()
elif background == "Light Blue":
screen.fill(lblue)
pygame.display.update()
else:
screen.fill(black)
pygame.display.update()
for "." in "map1.txt":
pygame.image.load("winter.Wall.png")
# ___________________TO RUN___________________________ #
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
command = "python JakeGame.py"
subprocess.call(command)
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_ESCAPE:
pygame.quit()
# _______________________________________________ #
pygame.quit()
这是地图 txt 文件和我遇到的错误
...1...........................................
...11111111111111..............................
1111............11111111111111.................
1............................111...............
111............................................
1..............................................
111111111111111111111111111....................
..................1............................
1111111111111111111............................
..................1............................
..................11111111.....................
..........111111111......111111111.............
.................................1.............
所以基本上,我要做的是将所有这些时间段转换为加载名为 winterWall.png 的图像。
我得到的错误是“无法分配文字”谢谢你们的帮助:p
【问题讨论】:
-
您有完整的错误文本吗?即堆栈跟踪?
-
对于“。”在“map1.txt”中:^ SyntaxError: cannot assign to literal
-
你对那行有什么期望?
-
所有要替换为图片的句点