forked from fredericomcorda/python-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminigame.py
More file actions
101 lines (79 loc) · 3.76 KB
/
minigame.py
File metadata and controls
101 lines (79 loc) · 3.76 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
# -*- coding: utf-8 -*-
"""minigame.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1pjDXsO2kdW5wgNSCb03wFTOztJnbQs8Q
"""
# code for minigame in the python project
# The minigame will consist in a lock for the door in the Escape Room.
# The game will have 3/4 doors and to advance you gotta answer a question.
# If the answer is correct the door will then unluck.
# The minigame function simply will provide the user with a random question from a dictionary and the user will have to answer.
# the dict is divided with the number of the question, the question and then the answer
import random
import sys
import time
def print_slow(string, speed=0.01): # added
"""This function will write a terminal message in a slow way so that
the user can keep track of what is happening"""
for letter in string:
sys.stdout.write(letter)
sys.stdout.flush()
time.sleep(speed)
def minigame():
print('\x1b[0m')
dict_minigame = {
"1": ["What's tuna's favorite Valorant agent", "Viper"],
"2": ["What is Harry Potter's patronous?", "Stag"],
"3": ["What's the name of the lamp that serves as the mascot for Pixar?", "Luxo Jr"],
"4": ["In the Marvel universe, who is Wanda Maximoff?", "Scarlet Witch"],
"5": ["Who was Ash Ketchun's first pokemon?", "Pikachu"],
"6": ["After Haley Quinn and The Joker break up, who does Harley starts dating?", "Poison Ivy"],
"7": ["What's Darth's Vader real name?", "Anakin Skywalker"],
"8": ["Vertigo's was an imprint of which comic editor?", "DC comics"],
"9": ["What is the name of the game released in 2022 that got popular because allows the user to play as a cat?", "Stray"],
"10": ["What is the name of the team that won the Valorant Champions in 2022?", "LOUD"],
"11": ["Homelander from The Boys is a reference to what super hero?", "Superman"],
"12": ["Maya Hawke aka Robin from Stranger Things is the daughter of which actress?", "Uma Thurman"],
"13": ["What's tuna's favorite color?", "Yellow"],
}
# import of random class to use the method that generates a random integer given a range
tries = 0
while tries < 3:
question_number = random.randint(1, 13)
# variable that will receive a random number
print_slow(
"\nThis object has a key! but I need to answer a question to get it....\n")
question = dict_minigame[str(question_number)][0]
answer = dict_minigame[str(question_number)][1]
# given the random number, u gotta turn it into a string to access the dict that corresponds to the question with the given number and answer
print_slow(f'{question}\n')
user_answer = input("")
# checks if the users anser matches the answer for the question
# lower method was used so the answer is not case sensitive
# method returns if the user got the answer right or wrong
if user_answer.lower() == answer.lower():
return True
else:
if tries < 3:
return False
def check_name(user):
print('\x1b[0m')
print("You typed:\n", user, "\nIs that the correct name?\n",
"Type 1 - For YES and 2 - For NO")
check = input("")
if check == "1" or check.upper() == "YES":
return True
else:
return False
# function that changes the user's name
# def change_user(user):
# new_user = input("Type your name again: ")
# return new_user
#user = new_user
# return user
# create a list to store the names of the users that played the game
list_user = []
# function that stores the names of the users in a list
def create_user(user):
list_user.append(user.lower())