-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (64 loc) · 2.45 KB
/
Copy pathmain.py
File metadata and controls
79 lines (64 loc) · 2.45 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
"""Main code for the Solitaire game"""
import pygame
import game_objects
pygame.init()
pygame.display.set_caption("Bootleg Solitaire")
icon = pygame.image.load("icon.png")
pygame.display.set_icon(icon)
my_font = pygame.font.Font(None, 36)
screen = pygame.display.set_mode((1200, 720))
game_board = game_objects.Board(screen)
cursor = game_objects.Cursor(game_board)
clock = pygame.time.Clock()
win_screen_rect = pygame.rect.Rect(screen.get_width() / 3, screen.get_height()/3, screen.get_width() / 3, screen.get_height()/3)
win_text = my_font.render("You are the Master of Solitaire™", True, "white")
new_text = my_font.render("Push Enter to begin anew...", True, "black")
esc_text = my_font.render("ESC: Quit", True, "black")
arrow_text = my_font.render("Arrows: Move", True, "black")
space_text = my_font.render("Space: Select", True, "black")
new_game_text = my_font.render("Enter: New Game", True, "black")
won = False
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if not won:
match (event.key):
case pygame.K_RIGHT:
cursor.move_right()
case pygame.K_LEFT:
cursor.move_left()
case pygame.K_UP:
cursor.move_up()
case pygame.K_DOWN:
cursor.move_down()
case pygame.K_SPACE:
cursor.interact()
if won:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
pass
if event.key == pygame.K_ESCAPE:
running = False
if event.key == pygame.K_RETURN:
game_board.new_game()
game_board.refresh_all()
game_board.draw_board()
cursor.draw_cursor()
if game_board.check_win():
won = True
else:
won = False
if won:
pygame.draw.rect(screen, "red", win_screen_rect)
screen.blit(win_text, (win_screen_rect.x + 10, win_screen_rect.centery - 40))
screen.blit(new_text, (win_screen_rect.x + 40, win_screen_rect.centery + 20))
screen.blit(esc_text, (1,1))
screen.blit(arrow_text, (1, 30))
screen.blit(space_text, (1, 59))
screen.blit(new_game_text, (1, 88))
pygame.display.flip()
clock.tick(60)
pygame.quit()