import pygame, pygame.image
from pygame.locals import *

import random

import options


gSoundsDict={}

gSoundsDirectory={"twist":["data/sounds/snap_1.wav"],
                  "plonk":["data/sounds/plonk_1.wav",
                           "data/sounds/plonk_2.wav",
                           "data/sounds/plonk_3.wav",
                           "data/sounds/plonk_4.wav",
                           "data/sounds/plonk_5.wav"],
                  "clonk":["data/sounds/clonk_1.wav"],
                  "cheer":["data/sounds/cheer_1.ogg",
                           "data/sounds/cheer_2.ogg",
                           "data/sounds/cheer_3.ogg",
                           "data/sounds/cheer_4.ogg",
                           "data/sounds/cheer_5.ogg"],
                  "buzzer":["data/sounds/buzzer_1.wav"],
                  }

def play(tag):
    if not pygame.mixer:
        return
    
    if not options.g_sounds:
        return
    
    if tag not in gSoundsDict:
        names=gSoundsDirectory[tag]
        newList=[pygame.mixer.Sound(n) for n in names]
        gSoundsDict[tag]=newList

    s=random.choice(gSoundsDict[tag][:])
    try:
        s.play()
    except pygame.error:
        print "error playing",tag,s

            
    
