如何解决python/pygame 在 windows 中的问题,但在 linux 中运行良好
好吧,所以我正在尝试使用 pygame 制作像 ludo 这样的游戏。当我在 Windows 上运行它时,播放器(蓝点)不会比第一行移动得更远,但是如果我在 linux 中运行它可以正常工作。 它根据玩家的位置绘制圆圈,但如果位置大于或等于 7,则不会打印。
import random
import pygame
pygame.init()
black = ( 0,0)
white = ( 255,255,255)
blue = ( 0,255)
#cambia esta variable para cambiar la posicion de inicio
pos = 0
screenw = 600
screenh = 750
screen = pygame.display.set_mode((screenw,screenh))
cellsize = 75
tablero = ([0,0])
preg = (['tema: texto','S.O.','Edit texto','redes','edit imagen sonido y video','Edit hojas CÁLCULO','comodin para tema imagen','Infografía','Mapa conceptual','línea del tiempo','Captura de pantalla','Editar imagen','comodin para tema sonido','podcast PRESENTANDOSE','soundtrack (youtube .mp3)','Descargar de Ivoox','Editor sonido u editor online de extras','Descarga de soundsnap','comodin para tema video','VIDEO (youtube mp3)','Screen video & Desktop','Screen brower Tab','Webcam recording presentandose','Editar video u editor online','comodin para tema paginas web','Full screen captura','Editor webpage / editor online','cuaderno digital','HTML webpage','Firma en correo','has llegado al final!'])
dado = 0
tablero[pos] = 1
#draw the board
def tabla():
pygame.draw.rect(screen,white,(cellsize,cellsize*6,cellsize,cellsize),3)
pygame.draw.rect(screen,(cellsize*6,3)
for x in range(1,8):
for y in range(1,7):
pygame.draw.line(screen,( x*cellsize,cellsize*6))
pygame.draw.line(screen,( cellsize,y*cellsize),( cellsize*7,y*cellsize))
pygame.display.update()
x = 0
clock = pygame.time.Clock()
#main loop
while x != 30 or pos >= 32:
clock.tick(10)
#draw the board
tabla()
#throw a dice
print("presione enter para lanzar dado")
input()
dado = random.randint(1,6)
print("dado",dado)
screen.fill(black)
tabla()
#remove the player and update the position
tablero[pos] = 0
preg[pos] = ' '
pos += dado
if pos >= 32:
pos = 32
tablero[pos] = 1
print("enhorabuena,has ganado!! Puedes pedir tu punto extra de la evaluacion a Monica")
#update the position
tablero[pos] = 1
print(tablero)
print(pos)
#this part isn't finished
if pos == 4:
for p in range(1,7):
if preg[p] == ' ':
screen.fill(black)
tabla()
print("elige una pregunta del bloque anterior antes de continuar")
pos += 7
#draw the circle that simbolices the player depending on the position
#this is where I get the problem
if pos >= pos and pos < 7:
screen.fill(black)
tabla()
pygame.draw.circle(screen,blue,((cellsize*pos) + (cellsize/2),(cellsize*5 + (cellsize/2))),cellsize/3)
elif pos >= 7 and pos < 13:
screen.fill(black)
tabla()
pygame.draw.circle(screen,((cellsize*(pos-6)) + (cellsize/2),(cellsize*4 + (cellsize/2))),cellsize/3)
elif pos >= 13 and pos < 19:
screen.fill(black)
tabla()
pygame.draw.circle(screen,((cellsize*(pos-12)) + (cellsize/2),(cellsize*3 + (cellsize/2))),cellsize/3)
elif pos >= 19 and pos < 25:
screen.fill(black)
tabla()
pygame.draw.circle(screen,((cellsize*(pos-18)) + (cellsize/2),(cellsize*2 + (cellsize/2))),cellsize/3)
elif pos >= 25 and pos < 32:
screen.fill(black)
tabla()
pygame.draw.circle(screen,((cellsize*(pos-24)) + (cellsize/2),(cellsize + (cellsize/2))),cellsize/3)
#print a question from a list depending on the player's position
print("preg:",preg[pos - 1])
#add 1 to the loop
x += 1
解决方法
您必须处理应用程序循环中的事件。分别见pygame.event.get()
pygame.event.pump()
:
对于游戏的每一帧,您都需要对事件队列进行某种调用。这可确保您的程序可以在内部与操作系统的其余部分进行交互。
while x != 30 or pos >= 32:
clock.tick(10)
pygame.event.pump()
# [...]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。