Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.py
More file actions
Latest commit
147 lines (116 loc) · 3.64 KB
/
Copy pathindex.py
File metadata and controls
147 lines (116 loc) · 3.64 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
importpygame
frompygame.localsimport*
importrandom
pygame.init()
# Colours
WHITE= (255,255,255)
BLACK= (0,0,0)
ORANGE= (220,100,0)
BROWN= (180,80,50)
YELLOW= (240,200,20)
RED= (200,10,10)
BLUE= (10,200,10)
GREEN= (10,10,200)
GREY= (50,50,50)
SKYBLUE= (125,220,240)
colors= ["white", "black", "orange", "brown", "yellow", "red", "blue", "green"]
color_map= { "white" : WHITE,
"black" : BLACK,
"orange" : ORANGE,
"brown" : BROWN,
"yellow" : YELLOW,
"red" : RED,
"blue" : BLUE,
"green" : GREEN }
# Global Variables
disp_width=550
disp_height=700
hidden_code= []
# GameDisplay
gameDisplay=pygame.display.set_mode((disp_width, disp_height))
pygame.display.set_caption('Mastermind')
clock=pygame.time.Clock()
defdrawPeg(x,y):
pygame.draw.circle(gameDisplay, BLACK, (x,y), 24)
pygame.draw.circle(gameDisplay, WHITE, (x,y), 21)
pygame.draw.circle(gameDisplay, BLACK, (x,y), 8)
defdrawPegs():
y=575
foriinrange(10):
x=150
font=pygame.font.SysFont ("arial", 30)
putText(str(i+1), (x-110,y-50,100,100), font, BLACK)
forjinrange(4):
drawPeg(x,y)
x+=50
y-=50
defdrawColorBar():
pygame.draw.rect(gameDisplay, BLACK, (448,118,54,464))
pygame.draw.rect(gameDisplay, WHITE, (450,120,50,460))
x,y=475,175
foriinrange(8):
pygame.draw.circle(gameDisplay, BLACK, (x,y), 17)
pygame.draw.circle(gameDisplay, color_map[colors[i]], (x,y), 15)
y+=50
defdrawCheckbox(x,y):
pygame.draw.rect(gameDisplay, BLACK, (x,y+7,44,36), 2)
pygame.draw.circle(gameDisplay, BLACK, (x+15,y+7+13), 5)
pygame.draw.circle(gameDisplay, BLACK, (x+15,y+7+26), 5)
pygame.draw.circle(gameDisplay, BLACK, (x+30,y+7+13), 5)
pygame.draw.circle(gameDisplay, BLACK, (x+30,y+7+26), 5)
defdrawCheckboxes():
x,y=350,550
foriinrange(10):
drawCheckbox(x,y)
y-=50
defputText(text,rect,font,color):
rect=pygame.Rect(rect)
textSurf=font.render(text, True, color)
textRect=textSurf.get_rect()
textRect.center= (rect.centerx,rect.centery)
gameDisplay.blit(textSurf, textRect)
defplaceHiddenCode():
x,y=165,50
forcolorinhidden_code:
pygame.draw.circle(gameDisplay, BLACK, (x,y), 17)
pygame.draw.circle(gameDisplay, color_map[color], (x,y), 15)
x+=40
defhideCode():
pygame.draw.rect(gameDisplay, GREY, (125,30,200,50))
font=pygame.font.SysFont ("comicsansms", 30)
putText("MASTERMIND", (125,30,200,50), font, WHITE)
defdrawCheckButton():
pygame.draw.rect(gameDisplay, BLACK, (149,624,152,52))
pygame.draw.rect(gameDisplay, SKYBLUE, (150,625,150,50))
font=pygame.font.SysFont ("comicsansms", 40)
putText("CHECK", (150,625,150,50), font, BLACK)
defunhideCode():
pass
# Main Gameloop
defmainloop():
cur_guess=1
exit=False
whilenotexit:
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
exit=True
gameDisplay.fill(WHITE)
drawPegs()
drawColorBar()
drawCheckboxes()
placeHiddenCode()
hideCode()
drawCheckButton()
font=pygame.font.SysFont ("comicsansms", 35)
putText(">", (0,574-cur_guess*50,100,100), font, BLACK)
pygame.display.update()
clock.tick(10)
pygame.quit()
quit()
# main
defmain():
globalhidden_code
hidden_code=random.sample (colors, 4)
mainloop()
if__name__=="__main__":
main()