-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
57 lines (44 loc) · 1.39 KB
/
main.py
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
import pygame
import sys
from puzzle import Puzzle
if __name__ == '__main__':
w = 600
h = 600
pygame.init()
pygame.display.set_caption("Course Project 3: Interactive Puzzle")
#need a loop in case the user hits the back button
outer_loop = 1
while outer_loop:
screen = pygame.display.set_mode((w, h))
screen.fill((255, 255, 255))
running = 1
rect1 = pygame.Rect(0, 0, 600, 300)
rect2 = pygame.Rect(0, 300, 600, 300)
font = pygame.font.Font(None, 30)
pygame.display.set_icon(pygame.image.load('objects/tile.bmp'))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
outer_loop = 0
if event.type == pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
if rect1.collidepoint(pos):
puzzle = Puzzle(screen)
outer_loop = puzzle.play()
running = 0
break
elif rect2.collidepoint(pos):
puzzle = Puzzle(screen)
outer_loop = puzzle.user_create_puzzle()
running = 0
break
#draw rectangles
pygame.draw.rect(screen, (0, 0, 0), rect1, 1)
pygame.draw.rect(screen, (0, 0, 0), rect2, 1)
#render text
text1 = font.render("Solve a puzzle", True, (0, 0, 0))
text2 = font.render("Create your own puzzle", True, (0, 0, 0))
screen.blit(text1, (w/2-75, h/4))
screen.blit(text2, (w/2-125, 3*h/4))
pygame.display.flip()