tinyarcade 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tinyarcade/__init__.py +3 -0
- tinyarcade/game_colour_memorizing.py +495 -0
- tinyarcade/game_hangman.py +333 -0
- tinyarcade/game_mastermind.py +354 -0
- tinyarcade/game_num_guess.py +152 -0
- tinyarcade/game_rock_paper_scissors.py +273 -0
- tinyarcade/game_tictactoe.py +428 -0
- tinyarcade/menu.py +81 -0
- tinyarcade-0.1.0.dist-info/METADATA +349 -0
- tinyarcade-0.1.0.dist-info/RECORD +13 -0
- tinyarcade-0.1.0.dist-info/WHEEL +4 -0
- tinyarcade-0.1.0.dist-info/entry_points.txt +2 -0
- tinyarcade-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
def clr():
|
|
5
|
+
os.system("cls" if os.name == "nt" else "clear")
|
|
6
|
+
|
|
7
|
+
# ANSI colours
|
|
8
|
+
GREEN = "\033[92m"
|
|
9
|
+
RED = "\033[91m"
|
|
10
|
+
YELLOW = "\033[93m"
|
|
11
|
+
CYAN = "\033[96m"
|
|
12
|
+
RESET = "\033[0m"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def generate_range():
|
|
16
|
+
return 1, 1000
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_guess(min_num, max_num):
|
|
20
|
+
user_input = input(
|
|
21
|
+
f"\nšÆ Enter your guess ({min_num}-{max_num}) "
|
|
22
|
+
f"or [q] to quit: "
|
|
23
|
+
).strip().lower()
|
|
24
|
+
|
|
25
|
+
if user_input == "q":
|
|
26
|
+
return "quit", None
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
guess = int(user_input)
|
|
30
|
+
except ValueError:
|
|
31
|
+
return None, (
|
|
32
|
+
user_input,
|
|
33
|
+
"ā Invalid input! Please enter a whole number."
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if guess < min_num or guess > max_num:
|
|
37
|
+
return None, (
|
|
38
|
+
str(guess),
|
|
39
|
+
f"ā Invalid range! Please stay between "
|
|
40
|
+
f"{min_num} and {max_num}."
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return guess, None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def update_range(guess, target_number, min_num, max_num):
|
|
47
|
+
if guess < target_number:
|
|
48
|
+
print(f"{CYAN}š Too low! The number is higher than {guess}.{RESET}")
|
|
49
|
+
return guess + 1, max_num
|
|
50
|
+
|
|
51
|
+
if guess > target_number:
|
|
52
|
+
print(f"{YELLOW}š Too high! The number is lower than {guess}.{RESET}")
|
|
53
|
+
return min_num, guess - 1
|
|
54
|
+
|
|
55
|
+
return min_num, max_num
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def show_result(guess, target_number, attempts):
|
|
59
|
+
print("š® GUESS RESULT")
|
|
60
|
+
print(f"šÆ Your guess : {guess}")
|
|
61
|
+
|
|
62
|
+
if guess == target_number:
|
|
63
|
+
print(f"𤫠Secret number: {target_number}")
|
|
64
|
+
else:
|
|
65
|
+
print("𤫠Secret number: ???")
|
|
66
|
+
|
|
67
|
+
print("-" * 30)
|
|
68
|
+
|
|
69
|
+
if guess == target_number:
|
|
70
|
+
print(
|
|
71
|
+
f"{GREEN}š Congratulations! You found the number "
|
|
72
|
+
f"in {attempts} attempt(s)!{RESET}"
|
|
73
|
+
)
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def ask_play_again():
|
|
80
|
+
while True:
|
|
81
|
+
print("\nWhat would you like to do?")
|
|
82
|
+
print("[1] Play Number Guess again")
|
|
83
|
+
print("[2] Return to Menu")
|
|
84
|
+
|
|
85
|
+
choice = input("\nChoose an option: ").strip()
|
|
86
|
+
|
|
87
|
+
if choice == "1":
|
|
88
|
+
return True
|
|
89
|
+
|
|
90
|
+
if choice == "2":
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
print("ā Invalid choice. Please enter 1 or 2.")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def play():
|
|
97
|
+
while True:
|
|
98
|
+
clr()
|
|
99
|
+
|
|
100
|
+
min_num, max_num = generate_range()
|
|
101
|
+
target_number = random.randint(min_num, max_num)
|
|
102
|
+
attempts = 0
|
|
103
|
+
|
|
104
|
+
print("š¢ === NUMBER GUESSING GAME === š¢")
|
|
105
|
+
print(
|
|
106
|
+
f"I'm thinking of a number between "
|
|
107
|
+
f"{min_num} and {max_num}."
|
|
108
|
+
)
|
|
109
|
+
print("š Guess the secret number!")
|
|
110
|
+
|
|
111
|
+
while True:
|
|
112
|
+
guess, error = get_guess(min_num, max_num)
|
|
113
|
+
|
|
114
|
+
if guess == "quit":
|
|
115
|
+
print("\nšŖ Returning to TinyArcade menu...")
|
|
116
|
+
return
|
|
117
|
+
|
|
118
|
+
if error:
|
|
119
|
+
entered_value, error_msg = error
|
|
120
|
+
|
|
121
|
+
clr()
|
|
122
|
+
|
|
123
|
+
print("š® GUESS RESULT")
|
|
124
|
+
print(f"šÆ Your guess : {entered_value}")
|
|
125
|
+
print("𤫠Secret number: ???")
|
|
126
|
+
print("-" * 30)
|
|
127
|
+
print(f"{RED}{error_msg}{RESET}")
|
|
128
|
+
|
|
129
|
+
continue
|
|
130
|
+
|
|
131
|
+
attempts += 1
|
|
132
|
+
|
|
133
|
+
clr()
|
|
134
|
+
|
|
135
|
+
won = show_result(guess, target_number, attempts)
|
|
136
|
+
|
|
137
|
+
if won:
|
|
138
|
+
break
|
|
139
|
+
|
|
140
|
+
min_num, max_num = update_range(
|
|
141
|
+
guess,
|
|
142
|
+
target_number,
|
|
143
|
+
min_num,
|
|
144
|
+
max_num,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if not ask_play_again():
|
|
148
|
+
break
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
play()
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import time
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
def clear_screen():
|
|
6
|
+
os.system("cls" if os.name == "nt" else "clear")
|
|
7
|
+
|
|
8
|
+
CHOICES = ["rock", "paper", "scissors"]
|
|
9
|
+
|
|
10
|
+
CHOICE_EMOJI = {
|
|
11
|
+
"rock": "ā Rock",
|
|
12
|
+
"paper": "ā Paper",
|
|
13
|
+
"scissors": "āļø Scissors",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
WINNING_MOVES = {
|
|
17
|
+
"rock": "scissors",
|
|
18
|
+
"paper": "rock",
|
|
19
|
+
"scissors": "paper",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
DIFFICULTIES = {
|
|
23
|
+
"1": ("Easy", 1),
|
|
24
|
+
"2": ("Normal", 3),
|
|
25
|
+
"3": ("Hard", 3),
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# ANSI colours
|
|
29
|
+
GREEN = "\033[92m"
|
|
30
|
+
RED = "\033[91m"
|
|
31
|
+
YELLOW = "\033[93m"
|
|
32
|
+
CYAN = "\033[96m"
|
|
33
|
+
RESET = "\033[0m"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def choose_difficulty():
|
|
37
|
+
while True:
|
|
38
|
+
clear_screen()
|
|
39
|
+
print("š® === ROCK, PAPER, SCISSORS === š®")
|
|
40
|
+
print("Choose your difficulty:")
|
|
41
|
+
|
|
42
|
+
print("\n[1] š¢ Easy - Win 1 round")
|
|
43
|
+
print("[2] š” Normal - First to 3 points")
|
|
44
|
+
print("[3] š“ Hard - Win 3 rounds in a row")
|
|
45
|
+
print("[q] šŖ Return to TinyArcade menu")
|
|
46
|
+
|
|
47
|
+
choice = input("\nšÆ Choose a difficulty: ").strip().lower()
|
|
48
|
+
|
|
49
|
+
if choice == "q":
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
if choice in DIFFICULTIES:
|
|
53
|
+
return DIFFICULTIES[choice]
|
|
54
|
+
|
|
55
|
+
print("ā Invalid choice. Please enter 1, 2, 3, or q.")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_computer_choice():
|
|
59
|
+
return random.choice(CHOICES)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get_player_choice():
|
|
63
|
+
while True:
|
|
64
|
+
print("Choose your move:")
|
|
65
|
+
print("[1] ā Rock")
|
|
66
|
+
print("[2] ā Paper")
|
|
67
|
+
print("[3] āļø Scissors")
|
|
68
|
+
print("[q] šŖ Quit and return to Menu")
|
|
69
|
+
|
|
70
|
+
choice = input("Enter 1, 2, 3, or q: ").strip().lower()
|
|
71
|
+
|
|
72
|
+
if choice == "q":
|
|
73
|
+
return "quit"
|
|
74
|
+
|
|
75
|
+
if choice == "1":
|
|
76
|
+
return "rock"
|
|
77
|
+
|
|
78
|
+
if choice == "2":
|
|
79
|
+
return "paper"
|
|
80
|
+
|
|
81
|
+
if choice == "3":
|
|
82
|
+
return "scissors"
|
|
83
|
+
|
|
84
|
+
clear_screen()
|
|
85
|
+
print("ā Invalid choice. Please enter 1, 2, 3, or q.")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def decide_winner(player_choice, computer_choice):
|
|
89
|
+
if player_choice == computer_choice:
|
|
90
|
+
return "tie"
|
|
91
|
+
|
|
92
|
+
if WINNING_MOVES[player_choice] == computer_choice:
|
|
93
|
+
return "player"
|
|
94
|
+
|
|
95
|
+
return "computer"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def show_scoreboard(player_score, computer_score, difficulty_name):
|
|
99
|
+
print(f"\nš SCOREBOARD - {difficulty_name.upper()}")
|
|
100
|
+
|
|
101
|
+
if difficulty_name == "Hard":
|
|
102
|
+
player_display = "š©" * player_score + "ā¬" * (3 - player_score)
|
|
103
|
+
computer_display = "š„" * computer_score + "ā¬" * (3 - computer_score)
|
|
104
|
+
|
|
105
|
+
print("š§ You :", player_display)
|
|
106
|
+
print("š¤ Computer :", computer_display)
|
|
107
|
+
|
|
108
|
+
else:
|
|
109
|
+
player_display = "š©" * player_score + "ā¬" * (3 - player_score)
|
|
110
|
+
computer_display = "š„" * computer_score + "ā¬" * (3 - computer_score)
|
|
111
|
+
|
|
112
|
+
print("š§ You :", player_display)
|
|
113
|
+
print("š¤ Computer :", computer_display)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def show_round_result(player_choice, computer_choice, result):
|
|
117
|
+
print("š® ROUND RESULT")
|
|
118
|
+
print(f"š§ You chose: {CHOICE_EMOJI[player_choice]}")
|
|
119
|
+
print(f"š¤ Computer chose: {CHOICE_EMOJI[computer_choice]}")
|
|
120
|
+
print("-" * 30)
|
|
121
|
+
|
|
122
|
+
if result == "player":
|
|
123
|
+
print(f"{GREEN}š You win this round!{RESET}")
|
|
124
|
+
elif result == "computer":
|
|
125
|
+
print(f"{RED}š¤ Computer wins this round!{RESET}")
|
|
126
|
+
else:
|
|
127
|
+
print(f"{YELLOW}š¤ It's a tie!{RESET}")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def play_match(difficulty_name, target_score):
|
|
131
|
+
player_score = 0
|
|
132
|
+
computer_score = 0
|
|
133
|
+
|
|
134
|
+
print(f"š® === ROCK, PAPER, SCISSORS: {difficulty_name.upper()} === š®")
|
|
135
|
+
|
|
136
|
+
if difficulty_name == "Easy":
|
|
137
|
+
print("š Win 1 round against the computer!")
|
|
138
|
+
|
|
139
|
+
elif difficulty_name == "Normal":
|
|
140
|
+
print("š First to 3 points wins!")
|
|
141
|
+
|
|
142
|
+
else:
|
|
143
|
+
print("š Win 3 rounds in a row!")
|
|
144
|
+
print("ā ļø A tie or loss resets both winning streaks.")
|
|
145
|
+
|
|
146
|
+
while True:
|
|
147
|
+
player_choice = get_player_choice()
|
|
148
|
+
|
|
149
|
+
if player_choice == "quit":
|
|
150
|
+
print("\nšŖ Returning to Menu...")
|
|
151
|
+
return "quit"
|
|
152
|
+
|
|
153
|
+
clear_screen()
|
|
154
|
+
|
|
155
|
+
computer_choice = get_computer_choice()
|
|
156
|
+
|
|
157
|
+
print("\nā ā āļø")
|
|
158
|
+
print("Revealing choices...")
|
|
159
|
+
time.sleep(1)
|
|
160
|
+
|
|
161
|
+
clear_screen()
|
|
162
|
+
|
|
163
|
+
result = decide_winner(player_choice, computer_choice)
|
|
164
|
+
|
|
165
|
+
show_round_result(player_choice, computer_choice, result)
|
|
166
|
+
|
|
167
|
+
if difficulty_name == "Hard":
|
|
168
|
+
|
|
169
|
+
if result == "player":
|
|
170
|
+
player_score += 1
|
|
171
|
+
computer_score = 0
|
|
172
|
+
|
|
173
|
+
elif result == "computer":
|
|
174
|
+
computer_score += 1
|
|
175
|
+
player_score = 0
|
|
176
|
+
|
|
177
|
+
else:
|
|
178
|
+
player_score = 0
|
|
179
|
+
computer_score = 0
|
|
180
|
+
else:
|
|
181
|
+
|
|
182
|
+
if result == "player":
|
|
183
|
+
player_score += 1
|
|
184
|
+
|
|
185
|
+
elif result == "computer":
|
|
186
|
+
computer_score += 1
|
|
187
|
+
|
|
188
|
+
show_scoreboard(
|
|
189
|
+
player_score,
|
|
190
|
+
computer_score,
|
|
191
|
+
difficulty_name,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# Easy: player needs only one win
|
|
195
|
+
if difficulty_name == "Easy" and player_score >= 1:
|
|
196
|
+
print(f"\n{GREEN}š CONGRATULATIONS! You won the Easy match!{RESET}")
|
|
197
|
+
|
|
198
|
+
input("\nPress ENTER to continue...")
|
|
199
|
+
clear_screen()
|
|
200
|
+
|
|
201
|
+
return "player"
|
|
202
|
+
|
|
203
|
+
# Normal: first to 3 points
|
|
204
|
+
if difficulty_name == "Normal":
|
|
205
|
+
if player_score >= 3:
|
|
206
|
+
print(f"\n{GREEN}š CONGRATULATIONS! You won the match!{RESET}")
|
|
207
|
+
input("\nPress ENTER to continue...")
|
|
208
|
+
clear_screen()
|
|
209
|
+
return "player"
|
|
210
|
+
|
|
211
|
+
if computer_score >= 3:
|
|
212
|
+
print(f"\n{RED}š¤ The computer won the match. Try again!{RESET}")
|
|
213
|
+
input("\nPress ENTER to continue...")
|
|
214
|
+
clear_screen()
|
|
215
|
+
return "computer"
|
|
216
|
+
|
|
217
|
+
# Hard: three consecutive wins by either player or computer
|
|
218
|
+
if difficulty_name == "Hard":
|
|
219
|
+
if player_score >= 3:
|
|
220
|
+
print(f"\n{GREEN}š AMAZING! You won 3 rounds in a row!{RESET}")
|
|
221
|
+
input("\nPress ENTER to continue...")
|
|
222
|
+
clear_screen()
|
|
223
|
+
return "player"
|
|
224
|
+
|
|
225
|
+
if computer_score >= 3:
|
|
226
|
+
print(f"\n{RED}š¤ The computer won 3 rounds in a row. Try again!{RESET}")
|
|
227
|
+
input("\nPress ENTER to continue...")
|
|
228
|
+
clear_screen()
|
|
229
|
+
return "computer"
|
|
230
|
+
|
|
231
|
+
input("\nPress ENTER for the next round...")
|
|
232
|
+
clear_screen()
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def ask_play_again():
|
|
236
|
+
while True:
|
|
237
|
+
print("What would you like to do?")
|
|
238
|
+
print("[1] Play Rock, Paper, Scissors again")
|
|
239
|
+
print("[2] Return to Menu")
|
|
240
|
+
|
|
241
|
+
choice = input("\nChoose an option: ").strip()
|
|
242
|
+
|
|
243
|
+
if choice == "1":
|
|
244
|
+
return True
|
|
245
|
+
|
|
246
|
+
if choice == "2":
|
|
247
|
+
return False
|
|
248
|
+
|
|
249
|
+
print("ā Invalid choice. Please enter 1 or 2.")
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def play():
|
|
253
|
+
while True:
|
|
254
|
+
difficulty = choose_difficulty()
|
|
255
|
+
|
|
256
|
+
if difficulty is None:
|
|
257
|
+
break
|
|
258
|
+
|
|
259
|
+
difficulty_name, target_score = difficulty
|
|
260
|
+
|
|
261
|
+
clear_screen()
|
|
262
|
+
|
|
263
|
+
result = play_match(difficulty_name, target_score)
|
|
264
|
+
|
|
265
|
+
if result == "quit":
|
|
266
|
+
break
|
|
267
|
+
|
|
268
|
+
if not ask_play_again():
|
|
269
|
+
break
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
if __name__ == "__main__":
|
|
273
|
+
play()
|