Skip to content

Commit

Permalink
Merge pull request #1173 from lipinsks/master
Browse files Browse the repository at this point in the history
Added spinning animation to roulette.py for visual enhancement
  • Loading branch information
pnhofmann committed Apr 22, 2024
2 parents 32fa36d + 03b5884 commit c718b13
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions installer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ FlightRadarAPI
github3.py
wonderwords
pyenchant
halo
35 changes: 35 additions & 0 deletions jarviscli/plugins/roulette.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from plugin import plugin

from halo import Halo

import time

reds = [1, 3, 5, 7, 9, 12, 14, 16, 18,
19, 21, 23, 25, 27, 30, 32, 34, 36]

Expand All @@ -17,6 +21,27 @@ def roulette(jarvis, s):
start_game(jarvis, cash)


# this function adds "spinning animation" before presenting result
# animation consists of numbers available on roulette board in respective colors
# for 0 and 00 its green, and for others its alternating between red and grey (black wouldn't be visible in terminal)
def spinning_animation(duration):
frames = [
"\033[92m00\033[0m"
] + [
f'\033[92m{i}\033[0m' if i == 0 or i == "00" else (
f'\033[90m{i}\033[0m' if i % 2 == 0 else f'\033[91m{i}\033[0m'
) for i in random.sample(range(37), 37)
]

spinner = Halo(
text='Spinning...\n',
spinner={'interval': 700, 'frames': frames}
)
spinner.start()
time.sleep(duration)
spinner.stop()


def start_game(jarvis, cash):
print("")
jarvis.say("~> Your start balance is $100", Fore.YELLOW)
Expand Down Expand Up @@ -81,6 +106,8 @@ def first_choice(jarvis, cash):
result = random.randint(0, 36)
cash -= bet

spinning_animation(5)

print("")
jarvis.say("Result: " + str(result), Fore.YELLOW)

Expand Down Expand Up @@ -115,6 +142,8 @@ def second_choice(jarvis, cash):
result = random.randint(0, 36)
cash -= bet

spinning_animation(5)

print("")
jarvis.say("Result: " + str(result), Fore.YELLOW)

Expand Down Expand Up @@ -153,6 +182,8 @@ def third_choice(jarvis, cash):
result = random.randint(0, 36)
cash -= bet

spinning_animation(5)

print("")
jarvis.say("Result: " + str(result), Fore.YELLOW)

Expand Down Expand Up @@ -190,6 +221,8 @@ def fourth_choice(jarvis, cash):
result = random.randint(0, 36)
cash -= bet

spinning_animation(5)

print("")
jarvis.say("Result: " + str(result), Fore.YELLOW)

Expand Down Expand Up @@ -237,6 +270,8 @@ def fifth_choice(jarvis, cash):
result = random.randint(0, 36)
cash -= bet

spinning_animation(5)

print("")
jarvis.say("Result: " + str(result), Fore.YELLOW)

Expand Down

0 comments on commit c718b13

Please sign in to comment.