-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasic_Textual_Game.py
More file actions
133 lines (95 loc) · 2.97 KB
/
Copy pathBasic_Textual_Game.py
File metadata and controls
133 lines (95 loc) · 2.97 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
## A simple textual game ##
import random
def dice():
# Variables
print('You have chosen game number 1')
count = 0
count_limit = 5
no_more_guesses = True
faces = random.randint(1, 20)
# Main loop
while count < count_limit and no_more_guesses:
guess = int(input('Try to guess the number of a d20. You have 5 tries. >> '))
if guess != faces:
print('Sorry, wrong number.')
count += 1
else:
no_more_guesses = False
if no_more_guesses:
print('Sorry, you are unlucky.')
else:
print('Bravo! You win the game')
def rock_paper_scissors():
print('You have chosen game number 2')
print("""Enter your choise:
1 - Rock
2 - Paper
3 - Scissors
""")
# Variables
count = 0
count_limiter = 5
# Main loop
while count < count_limiter:
your_move = int(input('Enter your choise >> '))
computer_choice = random.randint(1, 3)
if your_move == 1 and computer_choice == 1:
print(f'Draw!')
count += 1
elif your_move == 1 and computer_choice == 2:
print('You lose')
count += 1
elif your_move == 1 and computer_choice == 3:
print('You win!')
count += 1
elif your_move == 2 and computer_choice == 1:
print('You win')
count += 1
elif your_move == 2 and computer_choice == 2:
print('Draw!')
count += 1
elif your_move == 2 and computer_choice == 3:
print('You lose')
count += 1
elif your_move == 3 and computer_choice == 1:
print('You lose')
count += 1
elif your_move == 3 and computer_choice == 2:
print('You win')
count += 1
elif your_move == 3 and computer_choice == 3:
print('Draw!')
count += 1
print('Nice play')
def random_number_generator():
print('You have chosen game number 3')
random_number = random.randint(1, 100)
count = 0
count_limiter = 5
# Main loop
while count < count_limiter:
print('Try to guess a number between 1 and 100')
your_number = int(input('>> '))
if your_number < random_number:
print('Number too small')
count += 1
elif your_number > random_number:
print('Number too large')
count += 1
elif your_number == random_number:
print('Bravo! You win the game')
break
print('You are unlucky. Nice try though')
print("""
WELCOME TO THIS SIMPLE GAME. PLEASE CHOOSE AN OPTION:
1 - DICE
2 - ROCK, PAPER, SCISSORS
3 - GUESS THE NUMBER
""")
game = int(input('Please enter the number of the game you want to play to >> '))
if game == 1:
dice()
elif game == 2:
rock_paper_scissors()
elif game == 3:
random_number_generator()