-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (52 loc) · 2.1 KB
/
main.py
File metadata and controls
68 lines (52 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pygame, sys
import random
class Runner():
__customes = ("turtle", "fish", "prawn", "moray", "octopus")
def __init__(self, x=0, y=0):
ixCustome =random.randint(0,4)
self.custome =pygame.image.load("images/{}.png".format(__self.customes[ixCustome]))
self.position = [x,y]
self.name = ""
def avanzar (self):
self.position [0] += random.randint (1,6)
class Game():
runners= []
__posY= (160, 200, 240, 280)
__names= ("Speedy", "Lucera", "Alonso", "Torcuata")
__startLine=-5
__finishLine =620
def __init__(self):
self.__screen = pygame.display.set_mode((640, 480))
self.__background = pygame.image.load("images/background.png")
pygame.display.set_caption ("Carrera de bichos")
for i in range (4):
theRunner = Runner (self.__startLine,self.__posY[i])
theRunner.name = self.__names[i]
self.runners.append(theRunner)
def competir (self):
gameOver =False
#comprobamos eventos
while not gameOver:
for event in pygame.event.get():
if event.type== pygame.QUIT:
gameOver =True
#actualizamos codigo
for activeRunner in self.runners:
active.Runner.avanzar()
if activeRunner.position[0] >= self.__finishLine:
print ("{} ha ganado".format(activeRunner. name))
# Refrescamos la pantalla
self.__screen.blit(self.__background, (0,0))
for runner in self.__runners:
self.__screen.blit(runner.costume, runner.position)
pygame.dispay.flip()
#En el momento que tenemos un ganador cerramos programa
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT():
pygame.quit()
sys.exit
if __name__== "__main__":
game = Game()
pygame.font.init()
game.competir()