Repository navigation
Expand file tree
/
Copy pathgame.py
More file actions
129 lines (100 loc) · 4.65 KB
/
Copy pathgame.py
File metadata and controls
129 lines (100 loc) · 4.65 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
import ascii_art
print(ascii_art.logo)
from random import randint
from utils import calculate_score
print(f"{ascii_art.start}")
print("Welcome to the Number Guessing Game! I am Mr. Computer, I see you want to win me 🙂 \nI have made my choice Let's see if you will win me.")
print("\n")
player_lives = 0
# The computer chose a random number between 1 - 100
computer_num = randint(0, 0)
lowest_num = 1
highest_num =100
former_guesses = []
max_attempt = 0
difficulty_multiplier = 0
continue_game = True
while continue_game:
try:
difficulty_level = int(input("Select difficulty level: [1] Easy [2] Medium [3] Hard \n"))
if difficulty_level != 1 and difficulty_level != 2 and difficulty_level != 3:
print("Difficulty level not valid, enter either '1', '2' or '3'")
continue
except ValueError:
print("Difficulty level not valid, enter either '1', '2' or '3'")
continue
if difficulty_level == 1:
difficulty_multiplier = 100
max_attempt =10
player_lives = 10
print(f"You are on difficulty level Easy, you have {player_lives} lives and {max_attempt} maximum attempts.")
# The computer chose a random number between 1 - 50
computer_num = randint(1, 50)
lowest_num = 1
highest_num = 50
elif difficulty_level == 2:
difficulty_multiplier = 150
max_attempt = 7
player_lives = 7
print(f"You are on difficulty level Medium, you have {player_lives} lives and {max_attempt} maximum attempts.")
# The computer chose a random number between 1 - 100
computer_num = randint(1, 100)
lowest_num = 1
highest_num = 100
elif difficulty_level == 3:
difficulty_multiplier = 250
max_attempt = 5
player_lives = 5
print(f"You are on difficulty level Hard, you have {player_lives} lives and {max_attempt} maximum attempts.")
# The computer chose a random number between 1 - 200
computer_num = randint(1, 200)
lowest_num = 1
highest_num = 200
while player_lives > 0:
try:
player_guess = int(input(f"Guess the number computer chose (btn {lowest_num} - {highest_num}): \n"))
except ValueError:
print("Not a valid number")
continue
if player_guess < lowest_num or player_guess > highest_num:
print(f"Enter a number between {lowest_num} and {highest_num}")
continue
if player_guess == computer_num:
former_guesses.append(player_guess)
attempts_used = len(former_guesses)
score = calculate_score(max_attempt, attempts_used, difficulty_multiplier)
print(f"The computer guess was {computer_num} and your guess {player_guess} was accurate!")
print(f"Hurray!, your guess was correct!, you deserve a 🏆")
print("You should laugh so much at Mr.Computer 🤣🤣🤣...")
print(f"you made a total of {len(former_guesses)}/{max_attempt} attempts")
print(f"Your score is: {score} points.")
former_guesses = []
break
elif player_guess < computer_num:
player_lives -= 1
lowest_num = player_guess + 1
former_guesses.append(player_guess)
print(f"Wrong guess, your guess is lower than the number. you have {player_lives} lives left")
print(f"you have earlier made the following gueses {former_guesses}")
print(f"Hint: The number should be between {lowest_num} and {highest_num}")
elif player_guess > computer_num:
player_lives -= 1
highest_num = player_guess - 1
former_guesses.append(player_guess)
print(f"Wrong guess, your guess is higher than the number. you have {player_lives} lives left")
print(f"you have earlier made the following gueses {former_guesses}")
print(f"Hint: The number should be between {lowest_num} and {highest_num}")
if player_lives == 0:
print(f"The correct answer is: {computer_num}")
print(f"you made a total of {len(former_guesses)}/{max_attempt} attempts")
print("Sorry you have no live left, game over ")
former_guesses = []
print(f"{ascii_art.you_loss}")
new_game = input("Would you like to play again? if yes enter 'yes' and if no enter 'no': ").lower()
print("\n")
if new_game == "yes":
print(f"{ascii_art.playagain}")
else:
continue_game = False
print("Thank you for playing our Number-Guessing Game 🙂, GoodBye")
print(f"{ascii_art.game_over}")