|
24 | 24 | (draw_window_grid_and_refresh, |
25 | 25 | draw_window_question_prompts_and_refresh, |
26 | 26 | init_colors, draw_splash, draw_daily_double_splash, |
| 27 | + draw_final_jeopardy_splash, |
| 28 | + FINAL_STATE_BEGIN, FINAL_STATE_CATEGORY, FINAL_STATE_QUESTION, |
| 29 | + FINAL_STATE_GO_AROUND, FINAL_STATE_GO_AROUND_ANSWER, |
| 30 | + FINAL_STATE_ALL_SCORES |
27 | 31 | ) |
28 | 32 | from game_audio import build_audio_engine |
29 | 33 | from question_states import * |
@@ -82,16 +86,21 @@ def edit_scores(screen, scores): |
82 | 86 | event = screen.getch() |
83 | 87 | if event in score_codes: |
84 | 88 | code = int(chr(event)) |
85 | | - curses.echo() |
86 | | - while True: |
87 | | - try: |
88 | | - scores[code] += int( screen.getstr(height-1, 2) ) |
89 | | - except ValueError: pass |
90 | | - else: |
91 | | - curses.noecho() |
92 | | - break |
| 89 | + scores[code] += edit_score_prompt(screen, code) |
93 | 90 | break |
94 | 91 |
|
| 92 | +def edit_score_prompt(screen, code): |
| 93 | + height, width = screen.getmaxyx() |
| 94 | + |
| 95 | + curses.echo() |
| 96 | + while True: |
| 97 | + try: |
| 98 | + score_change = int( screen.getstr(height-1, 2) ) |
| 99 | + except ValueError: pass |
| 100 | + else: |
| 101 | + curses.noecho() |
| 102 | + return score_change |
| 103 | + |
95 | 104 | def pick_dd_player(screen, player_names): |
96 | 105 | height, width = screen.getmaxyx() |
97 | 106 |
|
@@ -126,13 +135,80 @@ def input_dd_player_wager(screen, min_wager, max_wager): |
126 | 135 | curses.noecho() |
127 | 136 | return how_much |
128 | 137 |
|
| 138 | +def do_final_jeopardy(screen, player_names, scores): |
| 139 | + draw_final_jeopardy_splash( |
| 140 | + screen, "Final Jeopardy!", FINAL_STATE_BEGIN, |
| 141 | + player_names, scores) |
| 142 | + run_until_space(screen) |
| 143 | + draw_final_jeopardy_splash( |
| 144 | + screen, config.get("core", "final_category"), FINAL_STATE_CATEGORY, |
| 145 | + player_names, scores ) |
| 146 | + run_until_space(screen) |
| 147 | + |
| 148 | + question = \ |
| 149 | + open(config.get("core", "final_question_file")).readline().strip() |
| 150 | + answer = open(config.get("core", "final_answer_file")).readline().strip() |
| 151 | + |
| 152 | + draw_final_jeopardy_splash( |
| 153 | + screen, |
| 154 | + question, |
| 155 | + FINAL_STATE_QUESTION, |
| 156 | + player_names, scores ) |
| 157 | + run_until_space(screen) |
| 158 | + |
| 159 | + state = FINAL_STATE_GO_AROUND |
| 160 | + q_or_a = question |
| 161 | + for score, player_code, player_name in sorted(zip( |
| 162 | + tuple(scores), # make a copy of scores as we're changing in place |
| 163 | + tuple( range(len(player_names)) ), |
| 164 | + player_names, |
| 165 | + ) ): |
| 166 | + if score > 0: |
| 167 | + draw_final_jeopardy_splash( |
| 168 | + screen, |
| 169 | + q_or_a, |
| 170 | + state, |
| 171 | + (player_name,), (score,) ) |
| 172 | + delta = -1 |
| 173 | + while not (0<= delta <= score): |
| 174 | + delta = edit_score_prompt(screen, player_code) |
| 175 | + scores[player_code] += delta |
| 176 | + if delta > 0: |
| 177 | + state = FINAL_STATE_GO_AROUND_ANSWER |
| 178 | + q_or_a = answer |
| 179 | + draw_final_jeopardy_splash( |
| 180 | + screen, |
| 181 | + q_or_a, |
| 182 | + state, |
| 183 | + player_names, scores ) |
| 184 | + run_until_space(screen) |
| 185 | + |
| 186 | + winning_score = max(scores) |
| 187 | + winners = [ player_name |
| 188 | + for score, player_name in zip(scores, player_names) |
| 189 | + if score == winning_score ] |
| 190 | + |
| 191 | + draw_final_jeopardy_splash( |
| 192 | + screen, "The winner is "+ ", ".join(winners) + "!", |
| 193 | + FINAL_STATE_ALL_SCORES, |
| 194 | + player_names, scores ) |
| 195 | + run_until_space(screen) |
| 196 | + |
| 197 | + draw_final_jeopardy_splash( |
| 198 | + screen, "Thanks for playing. Happy Hacking!", |
| 199 | + FINAL_STATE_ALL_SCORES, |
| 200 | + player_names, scores ) |
| 201 | + run_until_space(screen) |
129 | 202 |
|
130 | 203 | def run_questions_menu(screen, questions, answered_questions, player_names, |
131 | 204 | scores, daily_doubles, answer_server): |
| 205 | + number_of_rows = len(questions[0]["questions"]) |
| 206 | + total_avail_questions = len(questions) * number_of_rows |
| 207 | + |
132 | 208 | selected_question = [0, 100] |
133 | 209 |
|
134 | 210 | # initialize selected question bounds |
135 | | - max_question = int(len(questions[0]["questions"]) * 100) |
| 211 | + max_question = number_of_rows * 100 |
136 | 212 | max_category = len(questions) - 1 |
137 | 213 |
|
138 | 214 | draw_window_grid_and_refresh( |
@@ -192,6 +268,12 @@ def run_questions_menu(screen, questions, answered_questions, player_names, |
192 | 268 | save_database(answered_questions, player_names, |
193 | 269 | scores, daily_doubles) |
194 | 270 |
|
| 271 | + if ( len(answered_questions) >= total_avail_questions): |
| 272 | + # should never answer more questions then we have... |
| 273 | + assert( len(answered_questions) == total_avail_questions) |
| 274 | + do_final_jeopardy(screen, player_names, scores) |
| 275 | + break |
| 276 | + |
195 | 277 | elif event == ord("e"): |
196 | 278 | edit_scores(screen, scores) |
197 | 279 | save_database(answered_questions, player_names, |
|
0 commit comments