Skip to content

Commit

Permalink
added double jeopardy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zachtalmadge committed Nov 7, 2023
1 parent d218dc4 commit bd4e428
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rich.console import Console
from rich.console import Theme
from rich.table import Table
import random
import ipdb

custom_theme = Theme({
Expand Down Expand Up @@ -74,21 +75,25 @@ def play_game(player):
make_table()
select_category(player)

def add_points(selected_question, player):
player.score += selected_question.point_value
def add_points(selected_question, player, doubleJeopardy):
if doubleJeopardy:
player.score += selected_question.point_value * 2
else:
player.score += selected_question.point_value

player.update()

def end_game(player):
global question_count
console.print(f"Congratulations! Your score is {player.score}!")
question_count = 0

def check_answer(selected_question, answer, player):
def check_answer(selected_question, answer, player, doubleJeopardy):
global question_count

if selected_question.answer == answer:
console.print("Great job!", style="subhead")
add_points(selected_question, player)
add_points(selected_question, player, doubleJeopardy)
else:
console.print(f"Sorry, the answer was {selected_question.answer}", style="subhead")
selected_question.point_value = ""
Expand Down Expand Up @@ -136,10 +141,19 @@ def select_question(category, points, player):
if question.point_value == points), None)

if selected_question:

# randomly decide if question will be a double jeopardy
doubleJeopardy = False

# 8% chance that double jeopardy will be be invoked
if random.randint(1, 100) <= 8:
console.print('DOUBLE JEOPARDY!!!', style="subhead")
doubleJeopardy = True

console.print(selected_question.question_text, style="subhead")
user_answer = input("What is... ")

check_answer(selected_question, user_answer, player)
check_answer(selected_question, user_answer, player, doubleJeopardy)

else:
console.print("No question found")
Expand Down
3 changes: 3 additions & 0 deletions lib/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ def seed_jeopardy_board():
if __name__ == "__main__":
drop_tables()
print("Tables dropped!")

create_tables()
print("Tables created!")

seed_jeopardy_board()
print("Seed data complete!")

print("banana")
# ipdb.set_trace()

0 comments on commit bd4e428

Please sign in to comment.