SHOW:
|
|
- or go back to the newest paste.
1 | - | #hello world |
1 | + | from random import randint #This allows a random integer to be generated |
2 | - | #hello world |
2 | + | menuChoice = 1 #This sets the default value for 'menuChoice' to one |
3 | amountOfColumns = 8 #This sets the default amount of columns in the grid to 8 | |
4 | - | #hello world |
4 | + | amountOfRows = 8 #This sets the default amount of rows in the grid to 8 |
5 | amountOfBandits = 5 #This sets the default amount of bandits to 5 | |
6 | amountOfTreasureChests = 10 #This sets the default amount of treasure chests to 10 | |
7 | - | #hello world |
7 | + | score = 0 #This sets the default value of the score to 0 |
8 | #These values create a space where the user can input the values for most of the variables | |
9 | ||
10 | - | #hello world |
10 | + | #Task 1: Main Menu (User Need 1) |
11 | - | #hello world |
11 | + | def menu(): #This declares a new function |
12 | - | #print("hello world") |
12 | + | global amountOfColumns #This allows this variable to be called outside of this function |
13 | - | print("hello world") |
13 | + | global amountOfRows #This allows this variable to be called outside of this function |
14 | - | def awesomeFunction(): |
14 | + | global amountOfBandits #This allows this variable to be called outside of this function |
15 | - | a = "h" |
15 | + | global amountOfTreasureChests #This allows this variable to be called outside of this function |
16 | - | if a == "h": |
16 | + | print("\nWelcome to the AQA Treasure hunt game.\nShown below are the 3 options that you can select from:\nOption 1: Play the treasure hunt game\nOption 2: Custom rules\nOption 3: Quit") |
17 | - | print("hi") |
17 | + | #This outputs a welcome message and menu instructions for the user; the linebreaker \n outputs a new line for the user |
18 | - | print("this is great") |
18 | + | |
19 | #Allowing the user to choose an option (User Need 2) | |
20 | - | if a == "f": |
20 | + | while True: #This creates a while loop |
21 | - | print("oreo") |
21 | + | try: |
22 | - | print("thor") |
22 | + | menuChoice = int(input("\nPlease type in the assigned number of the option of your choice: ")) |
23 | - | if a == "f": |
23 | + | #This creates a user-inputted variable which must have an integer data type |
24 | - | print("HI") |
24 | + | except ValueError: #If an integer is not inputted... |
25 | - | elif bob == bob or bob == bob: |
25 | + | print("Your option was not a whole number. Please type in your option as a whole number") |
26 | - | print("hello") |
26 | + | #This outputs an error message to the user which indicates them what they need to input |
27 | - | print("thing") |
27 | + | continue #This continues the while loop so the user has to re-input the value |
28 | - | elif h == b: |
28 | + | if menuChoice < 1: #Condition set by selection for the variable value |
29 | - | print("hi") |
29 | + | print("Sorry, your typed in option cannot be below '1'.") |
30 | - | print("test") |
30 | + | #If the option is less than 1, then this error message is displayed |
31 | - | else: |
31 | + | continue #This continues the while loop so the user has to re-input the value |
32 | - | print("bob") |
32 | + | elif menuChoice > 3: #This sets another condition where the inputted option is greater than 4 |
33 | print("Sorry, your typed in option cannot be above '3'.") | |
34 | - | print("hi") |
34 | + | #If the option is greater than 4, then this error message is outputted |
35 | - | print("hello world") |
35 | + | continue #This continues the while loop so the user has to re-input the value |
36 | - | print("end") |
36 | + | #And the loop is continued so that the option has to be re-entered |
37 | else: #If the conditions are not met... | |
38 | break #...Then the loop is broken and the option value is stored | |
39 | if menuChoice == 1: #Selection and the comparison operator == creates a condition for this variable | |
40 | banditsInTheGrid(programmerGrid) #This calls and runs the function declared here | |
41 | treasureChestsInTheGrid(programmerGrid) #This calls and runs the function declared here | |
42 | movingUpOrDown(programmerGrid,userGrid) #This calls and runs the function declared here | |
43 | elif menuChoice == 2: #Condition set so that when the variable equals 2... | |
44 | ||
45 | #Allowing the user to set custom dimensions and numbers of bandits + chests (User Need 10) | |
46 | while True: #This sets up an iterative while loop | |
47 | try: | |
48 | amountOfColumns = int(input("\nPlease type in how many columns you want in your grid: ")) | |
49 | #This creates a user-inputted variable for the number of columns in the grid which must have an integer data type | |
50 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
51 | print("Your answer is not a whole number.\nPlease re-enter the value.") | |
52 | #This outputs a personalised error message to the user which indicates them what they need to input | |
53 | continue #This continues the while loop so the user has to re-input the value | |
54 | if amountOfColumns < 1: #Condition set by selection and comparison operators for the variable value | |
55 | print("You cannot have less than 1 column in the grid.\nPlease re-enter the value.") | |
56 | #This outputs a personalised error message to the user which indicates them what they need to input | |
57 | continue #This continues the while loop so the user has to re-input the value | |
58 | else: #If the variable value is appropriate to be stored... | |
59 | while True: #This sets up an iterative while loop | |
60 | try: | |
61 | amountOfRows = int(input("\nPlease type in how many rows you want in your grid: ")) | |
62 | #This creates a user-inputted variable for the number of rows in the grid which must have an integer data type | |
63 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
64 | print("Your answer is not a whole number.\nPlease re-enter the value.") | |
65 | #This outputs a personalised error message to the user which indicates them what they need to input | |
66 | continue #This continues the while loop so the user has to re-input the value | |
67 | if amountOfRows < 1:#Condition set by selection and comparison operators for the variable value | |
68 | print("You cannot have less than 1 row in the grid.\nPlease re-enter the value.") | |
69 | #This outputs a personalised error message to the user which indicates them what they need to input | |
70 | continue #This continues the while loop so the user has to re-input the value | |
71 | else: #If the variable value is appropriate to be stored... | |
72 | while True: #This sets up an iterative while loop | |
73 | try: | |
74 | amountOfBandits = int(input("\nPlease type in how many bandits you want in your treasure hunt game: ")) | |
75 | #This creates a user-inputted variable for the number of bandits in the game which must have an integer data type | |
76 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
77 | print("Your answer is not a whole number.\nPlease re-enter the value.") | |
78 | #This outputs a personalised error message to the user which indicates them what they need to input | |
79 | continue #This continues the while loop so the user has to re-input the value | |
80 | if amountOfBandits < 0: #Condition set by selection and comparison operators for the variable value | |
81 | print("You cannot have a negative amount of bandits.\nPlease re-enter the value.") | |
82 | #This outputs a personalised error message to the user which indicates them what they need to input | |
83 | continue #This continues the while loop so the user has to re-input the value | |
84 | else: #If the variable value is appropriate to be stored... | |
85 | while True: #This sets up an iterative while loop | |
86 | try: | |
87 | amountOfTreasureChests = int(input("\nPlease type in how many treasure chests you want in your treasure hunt game: ")) | |
88 | #This creates a user-inputted variable for the number of treasure chests in the game which must have an integer data type | |
89 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
90 | print("Your answer is not a whole number.\nPlease re-enter the value.") | |
91 | ||
92 | continue #This continues the while loop so the user has to re-input the value | |
93 | if amountOfTreasureChests < 4: #Condition set by selection and comparison operators for the variable value | |
94 | print("You cannot have less than 4 treasure chests.\nPlease re-enter the value.") | |
95 | continue #This continues the while loop so the user has to re-input the value | |
96 | else: #If the variable value is appropriate to be stored... | |
97 | menu() #This calls and runs the 'menu' function, returning the user back to the main menu | |
98 | elif menuChoice == 3: #Selection and comparison operators used to set a condition | |
99 | while True: #This sets up a while loop | |
100 | try: | |
101 | exitProgramChoice = str(input("Are you sure that you want to quit the program? Type in 'y' for yes or 'n' for no: ")) | |
102 | #This variable is the choice that the user inputs for if they want to close the program or not | |
103 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
104 | print("Sorry, your typed in option is not a letter. Please re-enter your option.") | |
105 | #If the user doesn't input a string, then this error message is outputted | |
106 | continue #And the loop is continued so that the choice has to be re-entered | |
107 | if exitProgramChoice == 'y': #This sets a condition where the inputted choice is equal to 'y' (yes) | |
108 | quit() #This built-in function means that the program is terminated | |
109 | elif exitProgramChoice == 'n': #This sets a condition where the inputted choice is equal to 'n' (no) | |
110 | menu() #The 'menu' function is called where the user is returned back to the main menu | |
111 | else: #If the conditions have not been met... | |
112 | print("Your option was neither 'y' or 'n'. Please re-enter your option with either the letter 'y' for yes or 'n' for no.") | |
113 | #...Then this error message is displayed | |
114 | continue #And the loop continues so that the choice has to be re-entered | |
115 | ||
116 | #Creating a grid (User Need 3) | |
117 | programmerGrid = [[0 for x in range(amountOfColumns)] for y in range(amountOfRows)] #This 2D array sets the dimensions of the grid for the programmer | |
118 | userGrid = [[0 for x in range(amountOfColumns)] for y in range(amountOfRows)] #This 2D array sets the dimensions of the grid for the user | |
119 | ||
120 | #Setting up bandits (User Need 3) | |
121 | def banditsInTheGrid(programmerGrid): #This starts a new function with passing parameters | |
122 | banditsCounter = 0 #This defines a new local variable which the initial value of zero | |
123 | while banditsCounter < amountOfBandits: #This creates an iterative while loop for the local variable/counter | |
124 | YCoordinate = randint(0,(amountOfRows)-1) #This randomnly selects and indexes a column to assign a bandit | |
125 | XCoordinate = randint(0,(amountOfColumns)-1) #This randomnly selects and indexes a row to assign a bandit | |
126 | if programmerGrid[YCoordinate][XCoordinate] == 0: #Selection used to set a condition for the random index generated previously | |
127 | programmerGrid[YCoordinate][XCoordinate] = "B" #This assigns the random index in the array the character 'B' (for bandit) | |
128 | banditsCounter = banditsCounter + 1 #This increases the value of the counter by one | |
129 | ||
130 | #Setting up treasure chests (User Need 3) | |
131 | def treasureChestsInTheGrid(programmerGrid): #This creates a new function with passing parameters | |
132 | treasureChestsCounter = 0 #This creates a new local variable/counter | |
133 | while treasureChestsCounter < amountOfTreasureChests: #This sets up an iterative while loop for the local variable/counter | |
134 | YCoordinate = randint(0,(amountOfRows)-1) #This randomnly selects and indexes a column to assign a bandit | |
135 | XCoordinate = randint(0,(amountOfColumns)-1) #This randomnly selects and indexes a row to assign a bandit | |
136 | if programmerGrid[YCoordinate][XCoordinate] == 0: #Selection used to set a condition for the random index generated previously | |
137 | programmerGrid[YCoordinate][XCoordinate] = "TC" #This assigns the random index in the array the character 'TC' (for treasure chest) | |
138 | treasureChestsCounter = treasureChestsCounter + 1 #This increases the value of the counter by one | |
139 | userGrid[(amountOfRows)-1][0] = "P" #This creates and indexes a starting position for the player in the bottom left corner of the grid | |
140 | for row in userGrid: #For each row in the user grid... | |
141 | print(row) #The rows are outputted to the user; this outputs the user version of the grid | |
142 | ||
143 | #Letting the user move up and down (User Need 4) | |
144 | def movingUpOrDown(programmerGrid,userGrid): #This defines a new function | |
145 | global score #This allows this variable to be called outside of this function | |
146 | r = (amountOfColumns)-1 #This variable locates which column the user is in after each move | |
147 | c = 0 #This variable locates which column the user is in after each move | |
148 | while True: #This sets up an iterative while loop | |
149 | #This replaces the previous player position with a blank space (0) after the player has moved | |
150 | try: | |
151 | upOrDown = str(input("Do you want to move up or down?\nType in 'u' for up or 'd' for down: ")) | |
152 | #This variable indicates if the user wants to move up or down, and it must have a string data type | |
153 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
154 | print("Your answer was not a letter. Please re-enter your answer as either 'u' or 'd'") | |
155 | #This outputs an error message which is personalised | |
156 | continue #This continues the while loop so the user has to re-input the value | |
157 | if upOrDown.lower() =='u' or upOrDown.lower() =='d': #Condition set by selection and boolean operators for the variable value | |
158 | while True:#This sets up an iterative while loop | |
159 | try: | |
160 | movingUpOrDown = int(input("How many squares do you want to move up/down: ")) | |
161 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
162 | print("Your answer was not a whole number. Please re-enter your answer as a whole number") | |
163 | #This outputs an error message which is personalised | |
164 | continue #This continues the while loop so the user has to re-input the value | |
165 | if movingUpOrDown >= 0 and movingUpOrDown < amountOfRows and upOrDown.lower() =='u': | |
166 | if r-(movingUpOrDown) >= 0: | |
167 | userGrid[r][c] = 0 | |
168 | #Condition set by selection and boolean operators for the variable value | |
169 | userGrid[r-(movingUpOrDown)][c] = "P" #Array indexing used to mark the new player position on the grid | |
170 | r = r - movingUpOrDown #This changes the value of the variable 'c' | |
171 | for row in userGrid: #For each row in the user grid... | |
172 | print(row) #The rows are outputted to the user with the new player position displayed | |
173 | ||
174 | #Calculating the player's score (User Need 5) | |
175 | trackPlayerPosition = programmerGrid[r][c] #This variable tracks each move the player makes by indexing the array of the grid | |
176 | if trackPlayerPosition =="TC": #Condition set by selection for the variable value | |
177 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
178 | print("You have landed on a treasure chest. Your score is now", score) | |
179 | #Concatenation and the command 'print' is used here to output the player's new score to the user as well as the fact they landed on a treasure chest | |
180 | programmerGrid[r][c] = "tc" #This declares that this spot in the grid is now the 2nd visit of the treasure chest | |
181 | elif trackPlayerPosition =="tc": #If this position in the grid is the 2nd treasure chest visit then... | |
182 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
183 | print("You have landed on a treasure chest. Your score is now", score) | |
184 | #Concatenation and the command 'print' is used here to output the player's new score to the user as well as the fact they landed on a treasure chest | |
185 | programmerGrid[r][c] = "B" #This declares that this spot in the grid is now the 3rd treasure chest visit | |
186 | elif trackPlayerPosition =="B": #If the player visits the treasure chest a 3rd time then ... | |
187 | score = 0 #The player's score resets to 0 as the treasure chest is now a bandit | |
188 | print("You have landed on a bandit. Your score is now", score) | |
189 | ##Concatenation and the command 'print' is used here to output the player's new score to the user as well as the fact they landed on a bandit | |
190 | programmerGrid[r][c] = 0 #This sets the space visited by the user by a neutral/empty block (0) | |
191 | rightOrLeftMovement(userGrid,programmerGrid,r,c) | |
192 | else: | |
193 | print("Your answer is out of bounds. Please re-enter the value") | |
194 | elif movingUpOrDown >= 0 and movingUpOrDown < amountOfRows and upOrDown =='d': | |
195 | if r+(movingUpOrDown) <= (amountOfRows)-1: | |
196 | userGrid[r][c] = 0 | |
197 | #Condition set by selection and boolean operators for the variable value | |
198 | userGrid[r+(movingUpOrDown)][c] = "P" #Array indexing used to mark the new player position on the grid | |
199 | r = r + movingUpOrDown #This changes the value of the variable 'c' | |
200 | for row in userGrid: #For each row in the user grid... | |
201 | print(row) #The rows are outputted to the user with the new player position displayed | |
202 | trackPlayerPosition = programmerGrid[r][c] #This variable tracks each move the player makes by indexing the array of the grid | |
203 | if trackPlayerPosition =="TC": #Condition set by selection for the variable value | |
204 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
205 | print("You have landed on a treasure chest. Your score is now", score) | |
206 | #Concatenation and the command 'print' is used here to output the player's new score to the user as well as the fact they landed on a treasure chest | |
207 | programmerGrid[r][c] = "tc" #This declares that this spot in the grid is now the 2nd visit of the treasure chest | |
208 | elif trackPlayerPosition =="tc": #If this position in the grid is the 2nd treasure chest visit then... | |
209 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
210 | print("You have landed on a treasure chest. Your score is now", score) | |
211 | #Concatenation and the command 'print' is used here to output the player's new score to the user as well as the fact they landed on a treasure chest | |
212 | programmerGrid[r][c] = "B" #This declares that this spot in the grid is now the 3rd treasure chest visit | |
213 | elif trackPlayerPosition =="B": #If the player visits the treasure chest a 3rd time then ... | |
214 | score = 0 #The player's score resets to 0 as the treasure chest is now a bandit | |
215 | print("You have landed on a bandit. Your score is now", score) | |
216 | #Concatenation and the command 'print' is used here to output the player's new score to the user as well as the fact they landed on a bandit | |
217 | programmerGrid[r][c] = 0 #This sets the space visited by the user by a neutral/empty block (0) after they have visited a bandit | |
218 | rightOrLeftMovement(userGrid,programmerGrid,r,c) #This calls and executes this function, allowing the user to move right or left in the grid | |
219 | else: | |
220 | print("Your answer is out of bounds. Please re-enter the value") | |
221 | else: #If none of the conditions have been met... | |
222 | print("Your answer was not a number between 0 and",(amountOfRows)-1,". Please re-enter your answer as a number between 1 and",(amountOfRows)-1) | |
223 | #Concatenation is used here to output an error message which is personalised | |
224 | continue #This continues the while loop so the user has to re-input the value | |
225 | elif upOrDown !='u' or upOrDown !='d': #Selection, boolean operators and comparison operators used to set a unique condition | |
226 | print("Your answer was neither the lowercase 'u' or the lowercase 'd'. Please re-enter your answer") | |
227 | #This outputs an error message which is personalised | |
228 | continue #This continues the while loop so the user has to re-input the value | |
229 | ||
230 | #Letting the user move left and right (User Need 4) | |
231 | def rightOrLeftMovement(userGrid,programmerGrid,r,c): #This defines a new function | |
232 | userGrid[r][c] = 0 | |
233 | global score #This allows this variable to be called outside of this function | |
234 | while True: #This sets up an iterative while loop | |
235 | try: | |
236 | rightOrLeft = str(input("Do you want to move right or left?\nType in 'r' for right or 'l' for left: ")) | |
237 | #This creates a user-inputted variable which must have a string data type | |
238 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
239 | print("Your answer was not a letter. Please re-enter your answer as either 'r' or 'l'") | |
240 | #This outputs an error message which is personalised | |
241 | continue #This continues the loop so that the user has to re-input the value of the variable | |
242 | if rightOrLeft =='r' or rightOrLeft =='l': #Boolean operators and selection used to set a condition | |
243 | try: | |
244 | movingRightOrLeft = int(input("How many squares do you want to move right/left: ")) | |
245 | #This creates a user-inputted variable which must have an integer data type | |
246 | except ValueError: #The error and exception checking sets a condition where the input is not the desired data type | |
247 | print("Your answer was not a whole number. Please re-enter your answer as a whole number") | |
248 | #This outputs an error message which is personalised | |
249 | continue #This continues the loop so that the user has to re-input the value of the variable | |
250 | if movingRightOrLeft >= 0 and movingRightOrLeft < amountOfColumns and rightOrLeft =='r': | |
251 | if c-(movingRightOrLeft) <= amountOfColumns: | |
252 | userGrid[r][c] = 0 | |
253 | #Selection and boolean operators used to set a condition here | |
254 | userGrid[r][c+(movingRightOrLeft)] = "P" #This assigns a new player position according to the movement | |
255 | c = c+(movingRightOrLeft) #This variable has been assigned a new value here | |
256 | for row in userGrid: #Iterative for loop used here to access each row in the user version of the grid | |
257 | print(row) #Each row in the user grid is outputted to the user by the command 'print' | |
258 | ||
259 | #Calculating the player's score (User Need 5) | |
260 | trackPlayerPosition = programmerGrid[r][c] #This variable tracks the player position in the grid | |
261 | if trackPlayerPosition =="TC": #Selection used to see what the user lands on in the grid | |
262 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
263 | #Outputting the new score to the user (User Need 7) | |
264 | print("You have landed on a treasure chest. Your score is now", score) | |
265 | #This outputs the new score to the user whenever they land on a treasure chest | |
266 | programmerGrid[r][c] = "tc" #This declares that this spot in the grid is now the 2nd visit of the treasure chest | |
267 | elif trackPlayerPosition =="tc": #If this position in the grid is the 2nd treasure chest visit then... | |
268 | score = score + 10 #The score is increased by the constant 10 | |
269 | #Outputting the new score to the user (User Need 7) | |
270 | print("You have landed on a treasure chest. Your score is now", score) | |
271 | #This outputs the new score to the user whenever they land on a treasure chest | |
272 | programmerGrid[r][c] = "B" #This declares that this spot in the grid is now the 3rd treasure chest visit | |
273 | #Replacing a treasure chest with a bandit after the 3rd visit (User Need 6) | |
274 | elif trackPlayerPosition =="B": #If the player visits the treasure chest a 3rd time then ... | |
275 | score = 0 #The player's score resets to 0 as the treasure chest is now a bandit | |
276 | #Outputting the new score to the user (User Need 7) | |
277 | print("You have landed on a bandit. Your score is now", score) | |
278 | #This outputs to the user that they have now landed on a bandit, and then outputs their new score | |
279 | programmerGrid[r][c] = 0 #This sets the space visited by the user by a neutral/empty block (0) | |
280 | movingUpOrDown(programmerGrid,userGrid) #This calls the function, allowing the user to move up or down again in the grid | |
281 | else: | |
282 | print("Your answer is out of bounds. Please re-enter the value") | |
283 | elif movingRightOrLeft >= 0 and movingRightOrLeft < amountOfColumns and rightOrLeft =='l': | |
284 | if (movingRightOrLeft)-c >= amountOfColumns | |
285 | userGrid[r][c] = 0 | |
286 | #Selection, boolean operators and comparison operators used to set a unique condition | |
287 | userGrid[r][c-(movingRightOrLeft)] = "P" #This assigns the new player position in the grid where the player has chosen to move | |
288 | c = c-(movingRightOrLeft) #This updates what column the user is in the grid | |
289 | for row in userGrid: #For loop used to access each row in the user version of the grid | |
290 | print(row) #Each row of the grid is printed to the user with the new player position shown | |
291 | trackPlayerPosition = programmerGrid[r][c] #This variable tracks the player's position in the grid | |
292 | if trackPlayerPosition =="TC": #If the player lands on a treasure chest then... | |
293 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
294 | print("You have landed on a treasure chest. Your score is now", score) | |
295 | #This outputs the new score to the user whenever they land on a treasure chest | |
296 | programmerGrid[r][c] = "tc" #This declares that this spot in the grid is now the 2nd visit of the treasure chest | |
297 | elif trackPlayerPosition =="tc": #Selection used to set a condition for this position in the grid | |
298 | score = score + 10 #This increases the players score to 10 by adding the constant 10 to it | |
299 | print("You have landed on a treasure chest. Your score is now", score) | |
300 | #This outputs the new score to the user whenever they land on a treasure chest | |
301 | programmerGrid[r][c] = "B" #This declares that this spot in the grid is now the 3rd treasure chest visit | |
302 | elif trackPlayerPosition =="B": #If the player visits the treasure chest a 3rd time then ... | |
303 | score = 0 #The player's score resets to 0 as the treasure chest is now a bandit | |
304 | print("You have landed on a bandit. Your score is now", score) | |
305 | #This outputs to the user that they have now landed on a bandit, and then outputs their new score | |
306 | programmerGrid[r][c] = 0 #This sets the space visited by the user by a neutral/empty block (0) | |
307 | movingUpOrDown(programmerGrid,userGrid) #This calls the function, allowing the user to move up or down again in the grid | |
308 | else: | |
309 | print("Your answer is out of bounds. Please re-enter the value") | |
310 | else: #If none of the other conditions have been met then... | |
311 | print("Your answer was not a number between 0 and",(amountOfColumns)-1,". Please re-enter your answer as a number between 1 and",(amountOfColumns)-1) | |
312 | #If the value is not between 0 and the amount of columns, then this error message is outputted to the user... | |
313 | continue #...And the user has to re-input the value of the variable again because of the loop | |
314 | else: #If none of the other conditions have been met then... | |
315 | print("Your answer was neither the lowercase 'r' or the lowercase 'l'. Please re-enter your answer") | |
316 | #If the input is not a lowercase 'r' or 'l', then this error message is displayed to the user | |
317 | continue #...And the user has to re-input the value of the variable again because of the loop | |
318 | ||
319 | #Notifying if the user has won and lost and their score and total moves made (User Need 8) | |
320 | ||
321 | if score >= 100: #Selection and comparison operators used to set a condition | |
322 | print("Congratulations, you have gained 100 gold coins!\nYou have won the treasure hunt game.") | |
323 | #This outputs a congratulations message to the user indicating that they have won the game | |
324 | ||
325 | #Returning the user back to the main menu (User Need 9) | |
326 | menu() #This calls and runs the 'menu' function (returns the user back to the menu) | |
327 | ||
328 | elif score < 100 and programmerGrid[:]!= "TC" and programmerGrid[:]!= "tc": | |
329 | #Selection, comparison operators and boolean operators used to set a condition here | |
330 | print("Sorry, you have visited all the treasure chests 3 times and not gained 100 gold coins.\nYou have lost the treasure hunt game as your score was only", score,".") | |
331 | #This outputs a consolation message to the user indicating that they have lost the game | |
332 | ||
333 | #Returning the user back to the main menu (User Need 9) | |
334 | menu() #This calls and runs the 'menu' function (returns the user back to the menu) | |
335 | ||
336 | ||
337 | menu() #This calls and runs the 'menu' function |