From 4e6b6ded7c33b3a3e51ea4cad3fd1d8d67b61c20 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 4 Dec 2019 13:39:16 -0500 Subject: [PATCH] Added play_random function. --- libstormgames.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libstormgames.py b/libstormgames.py index fc6d4ab..fc4359c 100755 --- a/libstormgames.py +++ b/libstormgames.py @@ -11,6 +11,7 @@ from xdg import BaseDirectory import pygame import pyperclip import random +import re import requests import speechd import subprocess @@ -73,6 +74,13 @@ def initialize_gui(gameTitle): time.sleep(soundData['game-intro'].get_length()) return soundData +def play_random(soundName): +key = [] +for i in sounds.keys(): + if re.match("^" + soundName + ".*", i): + key.append(i) +psounds[random.choice(key)].play() + def instructions(): # Read in the instructions file try: