好的,所以我试着做一个类似于ludo的游戏,用玩偶游戏。当我在windows上运行它时,player (蓝点)不会比第一行移动得更远,但是如果我在linux中运行它,效果会很好。它根据球员的位置绘制圆圈,但如果位置高于或等于7,则不打印。
这是游戏的代码(很抱歉编码错误,谢谢!):
import random
import pygame
pygame.init()
black = ( 0, 0, 0)
white = ( 255, 255, 255)
blue = ( 0, 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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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, white, (cellsize*6, cellsize, cellsize, cellsize), 3)
for x in range(1, 8):
for y in range(1, 7):
pygame.draw.line(screen, white, ( x*cellsize, cellsize), ( x*cellsize, cellsize*6))
pygame.draw.line(screen, white, ( 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, blue, ((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, blue, ((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, blue, ((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, blue, ((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发布于 2021-04-20 20:24:10
您必须处理应用程序循环中的事件。分别见pygame.event.get() pygame.event.pump()
对于游戏中的每一个帧,您都需要对事件队列进行某种类型的调用。这确保了您的程序可以与操作系统的其他部分进行内部交互。
while x != 30 or pos >= 32:
clock.tick(10)
pygame.event.pump()
# [...]https://stackoverflow.com/questions/67185840
复制相似问题