Hey guys, I've been working on a project recently. It's pretty simple and a few friends helped me out with it, but I wanna try to improve it a little bit. I'm trying to add a sound file whenever a player wins/loses. Being brand new to Pygame, I'm not completely familiar on how to use it. So far I have as follows:

import random
import pygame
import pygame.mixer
pygame.init()
pygame.mixer.init()

sound = pygame.mixer.Sound('hey.wav')

sound.play()

MAXBLOCKS=100
MINBLOCKS=0

userBlocks=50

dealCount=0

print "The goal of the game is to achieve, or go over, 100 points."
print "The computer will automatically choose a value of 1 through 10."
print "The tower's height is based upon the value of each card drawn."
print "Even valued cards add blocks, while odd valued blocks remove blocks."
print "Card values are listed as follows:"
print " Card value    -    Block Height"
print "______________________________\n"
print "    1,2        -     +/- 05"
print "    3,4        -     +/- 10"
print "    5,6        -     +/- 15"
print "    7,8        -     +/- 20"
print "    9,10       -     +/- 25\n"

print "You start with", userBlocks, "blocks.\n"
print "Test your luck!"
dummy = raw_input("Hit enter to attain your cards...\n")

print "\n\n"

while(userBlocks<MAXBLOCKS and userBlocks>MINBLOCKS):


    card = random.randrange(1,10)
    print "Your card for this deal is:", card

    blockValue=0;
    if ( card==1 or card==2):
        blockValue=5
    elif (card==3 or card==4):
        blockValue=10
    elif (card==5 or card==6):
        blockValue=15
    elif (card==7 or card==8):
        blockValue=20
    else:
        blockValue=25

    print blockValue, "points have been",

    if(card%2==0): 
        print "added to",
        userBlocks+=blockValue
    else:
        print "subtracted from",
        userBlocks-=blockValue
    print "your tower."

    if(userBlocks>MINBLOCKS and userBlocks<MAXBLOCKS):
        print "You now have", userBlocks, "blocks in your tower!\n"

    dealCount+=1

print "You lost after", dealCount, "deals!"

if userBlocks <= MINBLOCKS:
    print "You lost all of your blocks!  You lost."
else:
    print "You won! Your tower is", userBlocks, "high!"

Whenever I try to run it, no sound is played whatsoever. I saved the Python file to a folder on my desktop, and put the sound file in the folder with it. As seen here. Any ideas?

Thanks!

Just in case you have a bum sound file. Does this work ...

'''pg_sound_wav.py
play a wave sound file with pygame
'''

import pygame
pygame.mixer.init()

sound = pygame.mixer.Sound('hey.wav')
# play the actual sound
sound.play()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.