So here I have my code to connect 3 game. In order for me to proceed to finish coding the rest of the game, I need your help fixing the loop that determines what player goes first. When the loop randomly selects the player, it blits it's token however it keeps bliting both of the players tokens which means that the random function keeps running. How do I fix it so it runs once. Thanks!
import pygame, sys, random
from pygame.locals import*
#FPS
FPS =7
fpsClock = pygame.time.Clock()
#Display
DISPLAYSURF=pygame.display.set_mode((850, 725), 0, 32)
pygame.display.set_caption('Connect 3~Emoji Edition')
#Colors
WHITE=(255, 255, 255)
#Players
Player1='P1'
Player2='P2'
#Images
#Keyboard
Board=pygame.image.load('Keyboard.png')
Boardx=45
Boardy=200
#Token1
Token1=pygame.image.load('PoopEMJ.png')
Token1=pygame.transform.scale(Token1, (90, 90))
Token1x=375
Token1y=215
#Token2
Token2=pygame.image.load('LaughingEMJ.png')
Token2=pygame.transform.scale(Token2, (90, 90))
Token2x=375
Token2y=215
while True:
DISPLAYSURF.fill(WHITE)
DISPLAYSURF.blit(Board,(Boardx, Boardy))
#Randomly selects players *HELP*
Turn='Player'
if random.randint(0, 1) == 0:
Turn = Player1
DISPLAYSURF.blit(Token1,(Token1x, Token1y))
else:
Turn = Player2
DISPLAYSURF.blit(Token2,(Token2x, Token2y))
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
Aucun commentaire:
Enregistrer un commentaire