-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGuessGame.py
172 lines (147 loc) · 3.78 KB
/
GuessGame.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
# Simple Guess game with PyAutoGUI
# With Score
# GitHub: https://github.com/Kourva/GuessGame
import pyautogui
import random
# Easy mode
def game_easy():
guess = random.randint(1,10)
step = 1
ask = pyautogui.prompt(
text='Guess the number between 1 and 10 :)',
title='Guess Game (Easy)',
)
while ask != str(guess):
pre = ask
if int(ask) > guess:
ask = pyautogui.prompt(
text=f'Enter a number smaller than {pre}',
title='Guess Game (Easy)',
)
elif int(ask) < guess:
ask = pyautogui.prompt(
text=f'Enter a number bigger than {pre}',
title='Guess Game (Easy)',
)
step += 1
check = pyautogui.confirm(
text=f'You found the number in {step} steps',
title='Guess Game (Easy)',
buttons=['Again', 'Exit']
)
with open("Scores/easy", "r") as data1:
best = data1.readlines()[0]
if step < int(best):
with open("Scores/easy", "w") as data2:
data2.write(str(step))
if check == "Again":
game_easy()
else:
pyautogui.alert(
text="Bye Bye",
title='Guess Game'
)
# Menium mode
def game_medium():
guess = random.randint(1,10)
step = 1
ask = pyautogui.prompt(
text='Guess the number between 1 and 50 :)',
title='Guess Game (Medium)',
)
while ask != str(guess):
pre = ask
if int(ask) > guess:
ask = pyautogui.prompt(
text=f'Enter a number smaller than {pre}',
title='Guess Game (Medium)',
)
elif int(ask) < guess:
ask = pyautogui.prompt(
text=f'Enter a number bigger than {pre}',
title='Guess Game (Meduim)',
)
step += 1
check = pyautogui.confirm(
text=f'You found the number in {step} steps',
title='Guess Game (Medium)',
buttons=['Again', 'Exit']
)
with open("Scores/medium", "r") as data1:
best = data1.readlines()[0]
if step < int(best):
with open("Scores/medium", "w") as data2:
data2.write(str(step))
if check == "Again":
game_easy()
else:
pyautogui.alert(
text="Bye Bye",
title='Guess Game'
)
# Hard mode
def game_hard():
guess = random.randint(1,100)
step = 1
ask = pyautogui.prompt(
text='Guess the number between 1 and 100 :)',
title='Guess Game (Hard)',
)
while ask != str(guess):
pre = ask
if int(ask) > guess:
ask = pyautogui.prompt(
text=f'Enter a number smaller than {pre}',
title='Guess Game (Hard)',
)
elif int(ask) < guess:
ask = pyautogui.prompt(
text=f'Enter a number bigger than {pre}',
title='Guess Game (Hard)',
)
step += 1
check = pyautogui.confirm(
text=f'You found the number in {step} Steps',
title='Guess Game (Hard)',
buttons=['Again','Exit']
)
with open("Scores/hard", "r") as data1:
best = data1.readlines()[0]
if step < int(best):
with open("Scores/hard", "w") as data2:
data2.write(str(step))
if check == "Again":
game_hard()
else:
pyautogui.alert(text="Bye Bye", title='Guess Game')
# Mode Choose
mode = pyautogui.confirm(
text = "Please select game mode\nEase: 1 to 10\nMedium: 1 to 50\nHard: 1 to 100",
title = "Guess Game",
buttons = ['Easy','Medium','Hard','Score']
)
if mode == "Easy":
game_easy()
elif mode == "Medium":
game_medium()
elif mode == "Hard":
game_hard()
else:
# Score Easy
with open('Scores/easy') as data:
lines = data.readlines()
easy_score = lines[0]
# Score Medium
with open('Scores/medium') as data:
lines = data.readlines()
medium_score = lines[0]
# Score Hard
with open('Scores/hard') as data:
lines = data.readlines()
hard_score = lines[0]
pyautogui.confirm(
title = "Guess Game (Score)",
text = f"easy{easy_score.rjust(10)}\nMedium{medium_score.rjust(10)}\nHard{hard_score.rjust(10)}",
buttons = ["OK"]
)