Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- pygame.init()
- background_colour = (255,255,255)
- (width, height) = (640, 480)
- screen = pygame.display.set_mode((width, height))
- pygame.display.set_caption('The BGR Game')
- screen.fill(background_colour)
- pygame.display.flip()
- running = True
- # COLORS
- BLUE = (0,0,255)
- LIGHT_BLUE = (65,105,225)
- GREEN = (0,255,0)
- LIGHT_GREEN = (0,204,102)
- RED = (255,0,0)
- LIGHT_RED = (228,113,122)
- BLACK = (0,0,0)
- WHITE = (255,255,255)
- CENTER_WINDOW_H = 480/2
- total_good = 0
- total_bad = 0
- font1 = pygame.font.Font('tahoma.ttf', 32)
- start_text = font1.render('Press [SPACE] to start', True, BLACK, WHITE)
- good_text = font1.render("Good Answers: ", True, BLACK, WHITE)
- bad_text = font1.render("Bad Answers: ", True, BLACK, WHITE)
- start_text_rect = start_text.get_rect()
- good_text_rect = start_text.get_rect()
- bad_text_rect = start_text.get_rect()
- start_text_rect.center = (640 // 2, 350)
- good_text_rect.center = (640 // 2, 50)
- bad_text_rect.center = (640 // 2, 100)
- click = False
- press_space = False
- timeA = 0
- timeB = 0
- counter = 0
- stage = 1
- limit = 0
- good_clicks = 0
- num_click = 0
- random_num = 0
- list1 = [1]
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_SPACE or event.key == pygame.K_UP:
- if stage == 1:
- print("PRESS START!")
- stage = 2
- if event.type == pygame.MOUSEBUTTONUP:
- if stage == 3:
- if x > 640 / 4 - 25 and x < 640 / 4 + 25 and y > CENTER_WINDOW_H - 25 and y < CENTER_WINDOW_H + 25:
- if list1[num_click] == 1:
- print("GOOD")
- total_good += 1
- else:
- print("BAD")
- total_bad += 1
- num_click += 1
- if x > (640 / 4) * 2 - 25 and x < (640 / 4) * 2 + 25 and y > CENTER_WINDOW_H - 25 and y < CENTER_WINDOW_H + 25:
- if list1[num_click] == 2:
- print("GOOD")
- total_good += 1
- else:
- print("BAD")
- total_bad += 1
- num_click += 1
- if x > (640 / 4) * 3 - 25 and x < (640 / 4) * 3 + 25 and y > CENTER_WINDOW_H - 25 and y < CENTER_WINDOW_H + 25:
- if list1[num_click] == 3:
- print("GOOD")
- total_good += 1
- else:
- print("BAD")
- total_bad += 1
- num_click += 1
- if num_click == limit:
- num_click = 0
- click = False
- stage = 1
- # GET MOUSE POSITION
- x, y = pygame.mouse.get_pos()
- # print(x, y)
- # TIMER
- timeA = pygame.time.get_ticks()
- # print(timeA)
- # BACKGROUND
- pygame.draw.rect(screen, WHITE, pygame.Rect(0, 0, 640, 480))
- if stage == 2:
- if timeA - timeB < 1000:
- pygame.draw.rect(screen, LIGHT_BLUE, pygame.Rect(640 / 4 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, LIGHT_GREEN, pygame.Rect((640/4) * 2 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, LIGHT_RED, pygame.Rect((640 / 4) * 3 - 25, CENTER_WINDOW_H - 25, 50, 50))
- if timeA - timeB > 999 and timeA - timeB < 2000:
- if list1[counter] == 1:
- pygame.draw.rect(screen, BLUE, pygame.Rect(640 / 4 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, LIGHT_GREEN, pygame.Rect((640 / 4) * 2 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, LIGHT_RED, pygame.Rect((640 / 4) * 3 - 25, CENTER_WINDOW_H - 25, 50, 50))
- if list1[counter] == 2:
- pygame.draw.rect(screen, LIGHT_BLUE, pygame.Rect(640 / 4 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, GREEN, pygame.Rect((640/4) * 2 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, LIGHT_RED, pygame.Rect((640 / 4) * 3 - 25, CENTER_WINDOW_H - 25, 50, 50))
- if list1[counter] == 3:
- pygame.draw.rect(screen, LIGHT_BLUE, pygame.Rect(640 / 4 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, LIGHT_GREEN, pygame.Rect((640 / 4) * 2 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.draw.rect(screen, RED, pygame.Rect((640 / 4) * 3 - 25, CENTER_WINDOW_H - 25, 50, 50))
- if timeA - timeB > 1999:
- counter += 1
- if counter == limit:
- random_num = random.randint(1, 3)
- list1.append(random_num)
- timeB = timeA
- # print(counter)
- if counter > limit:
- print(list1)
- stage = 3
- click = True
- counter = 0
- limit += 1
- # UPDATE AND PRINT GOOD ANSWERS
- good_text = font1.render("Good Answers: " + str(total_good), True, BLACK, GREEN)
- screen.blit(good_text, good_text_rect)
- # UPDATE AND PRINT BAD ANSWERS
- bad_text = font1.render("Bad Answers: " + str(total_bad), True, BLACK, RED)
- screen.blit(bad_text, bad_text_rect)
- if stage == 1:
- screen.blit(start_text, start_text_rect)
- timeB = timeA
- # PLAYER'S TURN
- if stage == 1 or stage == 3:
- if x > 640/4 - 25 and x < 640/4 + 25 and y > CENTER_WINDOW_H-25 and y < CENTER_WINDOW_H + 25 and click == True:
- pygame.draw.rect(screen, BLUE, pygame.Rect(640/4 - 25, CENTER_WINDOW_H-25, 50, 50))
- else:
- pygame.draw.rect(screen, LIGHT_BLUE, pygame.Rect(640 / 4 - 25, CENTER_WINDOW_H - 25, 50, 50))
- if x > (640/4)*2 - 25 and x < (640/4)*2 + 25 and y > CENTER_WINDOW_H - 25 and y < CENTER_WINDOW_H + 25 and click == True:
- pygame.draw.rect(screen, GREEN, pygame.Rect((640/4) * 2 - 25, CENTER_WINDOW_H-25, 50, 50))
- else:
- pygame.draw.rect(screen, LIGHT_GREEN, pygame.Rect((640 / 4) * 2 - 25, CENTER_WINDOW_H - 25, 50, 50))
- if x > (640/4)*3 - 25 and x < (640/4)*3 + 25 and y > CENTER_WINDOW_H - 25 and y < CENTER_WINDOW_H + 25 and click == True:
- pygame.draw.rect(screen, RED, pygame.Rect((640/4) * 3 - 25, CENTER_WINDOW_H-25, 50, 50))
- else:
- pygame.draw.rect(screen, LIGHT_RED, pygame.Rect((640 / 4) * 3 - 25, CENTER_WINDOW_H - 25, 50, 50))
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement