-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
81 lines (71 loc) · 2.62 KB
/
game.py
File metadata and controls
81 lines (71 loc) · 2.62 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
69
70
71
72
73
74
75
76
77
78
79
80
81
from random import randrange
import sys, pygame
pygame.init()
clock = pygame.time.Clock()
pygame.display.set_caption("Blazing Fingers")
black = 0,0,0
red = 255,0,0
blue = 0,0,225
white = 255,255,255
size = width, height = 500, 500
screen = pygame.display.set_mode(size)
screen.fill(black)
font = pygame.font.Font(None, 36)
fps = 60
score = 0
randomNum = randrange(1,100)
redRect = 0
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
screen.fill((black))
pygame.draw.rect(screen, blue, (225,75,50,50))
pygame.draw.rect(screen, blue, (225,150,50,50))
pygame.draw.rect(screen, blue, (125,150,50,50))
pygame.draw.rect(screen, blue, (325,150,50,50))
if randomNum >=0 and randomNum < 25:
pygame.draw.rect(screen, red, (225,75,50,50))
redRect = 1
if randomNum >= 25 and randomNum < 50:
pygame.draw.rect(screen, red, (225,150,50,50))
redRect = 2
if randomNum >= 50 and randomNum < 75:
pygame.draw.rect(screen, red, (125,150,50,50))
redRect = 3
if randomNum >= 75 and randomNum < 100:
pygame.draw.rect(screen, red, (325,150,50,50))
redRect = 4
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
if redRect == 1:
randomNum = randrange(1,100)
pygame.draw.rect(screen, white, (225,75,50,50))
score += 1
else:
sys.exit()
if event.key == pygame.K_s:
if redRect == 2:
randomNum = randrange(1,100)
pygame.draw.rect(screen, white, (225,150,50,50))
score += 1
else:
sys.exit()
if event.key == pygame.K_a:
if redRect == 3:
randomNum = randrange(1,100)
pygame.draw.rect(screen, white, (125,150,50,50))
score += 1
else:
sys.exit()
if event.key == pygame.K_d:
if redRect == 4:
randomNum = randrange(1,100)
pygame.draw.rect(screen, white, (325,150,50,50))
score += 1
else:
sys.exit()
showScore = font.render("Score: " + str(score), 1, (255, 255, 255))
screen.blit(showScore, (100,100))
pygame.display.flip()
clock.tick(fps)