|
2 | 2 | import random |
3 | 3 | import time |
4 | 4 | import sys |
5 | | -sys.setExecutionLimit(600000) # let this take up to 10 minutes |
| 5 | +#sys.setExecutionLimit(600000) # let this take up to 10 minutes |
6 | 6 |
|
7 | 7 | # PASTE YOUR WOFPlayer CLASS (from part A) HERE |
8 | 8 | class WOFPlayer: |
@@ -106,20 +106,26 @@ def getNumberBetween(prompt, min, max): |
106 | 106 | # { "type": "bankrupt", "text": "Bankrupt", "prize": false }, |
107 | 107 | # { "type": "loseturn", "text": "Lose a turn", "prize": false } |
108 | 108 | def spinWheel(): |
109 | | - with open("wheel.json", 'r') as f: |
110 | | - wheel = json.loads(f.read()) |
| 109 | + try: |
| 110 | + with open("wheel.json", 'r') as f: |
| 111 | + wheel = json.loads(f.read()) |
| 112 | + return random.choice(wheel) |
| 113 | + except: |
| 114 | + wheel = [{ "type": "cash", "text": "$950", "value": 950, "prize": "A trip to Ann Arbor!" }, { "type": "bankrupt", "text": "Bankrupt", "prize": False }, { "type": "loseturn", "text": "Lose a turn", "prize": False }] |
111 | 115 | return random.choice(wheel) |
112 | 116 |
|
113 | 117 | # Returns a category & phrase (as a tuple) to guess |
114 | 118 | # Example: |
115 | 119 | # ("Artist & Song", "Whitney Houston's I Will Always Love You") |
116 | 120 | def getRandomCategoryAndPhrase(): |
117 | | - with open("phrases.json", 'r') as f: |
118 | | - phrases = json.loads(f.read()) |
| 121 | + try: |
| 122 | + with open("phrases.json", 'r') as f: |
| 123 | + phrases = json.loads(f.read()) |
119 | 124 |
|
120 | | - category = random.choice(list(phrases.keys())) |
121 | | - phrase = random.choice(phrases[category]) |
122 | | - return (category, phrase.upper()) |
| 125 | + category = random.choice(list(phrases.keys())) |
| 126 | + phrase = random.choice(phrases[category]) |
| 127 | + return (category, phrase.upper()) |
| 128 | + except: return ("Artist & Song", "Whitney Houston's I Will Always Love You") |
123 | 129 |
|
124 | 130 | # Given a phrase and a list of guessed letters, returns an obscured version |
125 | 131 | # Example: |
@@ -148,16 +154,16 @@ def showBoard(category, obscuredPhrase, guessed): |
148 | 154 | print('='*15) |
149 | 155 | print('') |
150 | 156 |
|
151 | | -num_human = getNumberBetween('How many human players?', 0, 10) |
| 157 | +num_human = getNumberBetween('How many human players? ', 0, 10) |
152 | 158 |
|
153 | 159 | # Create the human player instances |
154 | | -human_players = [WOFHumanPlayer(input('Enter the name for human player #{}'.format(i+1))) for i in range(num_human)] |
| 160 | +human_players = [WOFHumanPlayer(input('Enter the name for human player #{} '.format(i+1))) for i in range(num_human)] |
155 | 161 |
|
156 | | -num_computer = getNumberBetween('How many computer players?', 0, 10) |
| 162 | +num_computer = getNumberBetween('How many computer players? ', 0, 10) |
157 | 163 |
|
158 | 164 | # If there are computer players, ask how difficult they should be |
159 | 165 | if num_computer >= 1: |
160 | | - difficulty = getNumberBetween('What difficulty for the computers? (1-10)', 1, 10) |
| 166 | + difficulty = getNumberBetween('What difficulty for the computers? (1-10) ', 1, 10) |
161 | 167 |
|
162 | 168 | # Create the computer player instances |
163 | 169 | computer_players = [WOFComputerPlayer('Computer {}'.format(i+1), difficulty) for i in range(num_computer)] |
|
0 commit comments