cannot play sound for my console hangman game

  • Thread starter Thread starter Marvin Hunkin
  • Start date Start date
M

Marvin Hunkin

Guest
hi. using the jaws for windows screen reader from Freedom Scientific – High-quality video magnifiers, braille displays, screen magnification software, and #1 screen reader, JAWS., and non visual desktop access from NV Access. using windows 10 on a assus vivo laptop. using windows 10 64 bit home 1903. and also using visual studio 2019 latest update. now rebuidling a vb console game, but when i build, and then set the output to copy always, says it cannot find the file. but do have the .wav file, was originally a .ogg file, but used audacity to export and convert and the .wav file does play. so does any one know how i can fix this and get a excepted exception, and will paste below. and the file is named correctly. so where do i find the .wav extra .wav..wa, and do have the text sound set to .wav. is that the issue. will paste the error messages and my code below. can any one help. thanks. Hangman
Welcome To Hangman!
This game is to be played by blind and visually impaired pla


Unhandled Exception: System.IO.FileNotFoundException: Could
lease\Resources\Locutus.wav.wav'.
at System.IO.__Error.WinIOError(Int32 errorCode, String m
at System.IO.FileStream.Init(String path, FileMode mode,
e share, Int32 bufferSize, FileOptions options, SECURITY_ATT
n useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode,
at HangMan.Module1.PlaySound(String Sound) in C:\Users\Ow
at HangMan.Module1.Main() in C:\Users\Owner\Desktop\HangM
Press any key to continue . . .















Imports System.Media
Imports System.IO
Imports System.Speech.Synthesis
Imports System.Windows.Forms

' Program: Hangman
' Author: Marvin Hunkin
' Version: 1.1
' Date: Tuesday December 25, 2012
' Description: Playing a Hangman game. You enter a letter to use a list of words loaded into memory. You then guess a six letter word, and use 13 guesses. At the end of 13 guesses, you get a message saying you either won or loss, and what the word was, and a number to exit the game being 1. Added a couple of cool sound audio effects.

Module Module1

' Declare class level variables

Dim WordMask As String = "------"
Dim WordArray() As String
Dim Talker As New SpeechSynthesizer
Dim Player As New SoundPlayer

Sub Main()

' Create a new wordlist file path

Dim wordlistPath = Path.Combine("Resources", "wordlist.txt")

' Populate the word array variable with the contents of the file path

WordArray = File.ReadAllLines(wordlistPath)

' Show the window maximized and show the name of the application in the title bar

Console.WindowWidth = 60
Console.Title = "Hangman"
Dim NewUri As Uri = Nothing
Dim Result As Boolean = Uri.TryCreate(Directory.GetParent(Directory.GetCurrentDirectory).Parent.ToString + "\en-sc", UriKind.Absolute, NewUri)
If Result Then
Talker.AddLexicon(NewUri, SynthesisMediaType.Ssml)
Talker.SelectVoice(0)
End If

' Welcome message

Console.WriteLine("Welcome To Hangman!")
SpeakLines("Welcome To Hangman!")
Console.WriteLine("This game is to be played by blind and visually impaired players.")
SpeakLines("This game is to be played by blind and visually impaired players.")
Console.WriteLine()

' Declare local variables

Dim ContinuePlayingGames As Boolean = True

' While loop to play the game

While ContinuePlayingGames
PlaySound("Locutus.wav")
Dim RandomIndex As Integer = GetRandom(0, (WordArray.Length - 1))
Dim PickedWord As String = WordArray(RandomIndex)
PlayAGame(PickedWord)
Dim QuitRequested As String
Console.WriteLine("Enter 1 to quit playing or Press Enter to play again")
Console.WriteLine()
SpeakLines("Enter 1 to quit playing or Press Enter to play again")
QuitRequested = Console.ReadLine()
If QuitRequested = "1" Then
PlaySound("discon.wav")
Console.WriteLine("Goodbye")
SpeakLines("Goodbye")
Exit While
Else
Console.Clear()
End If
End While
Dim CloseRequested As String
Console.WriteLine("Hit any key to close console.")
Console.WriteLine()
SpeakLines("Hit any key to close console.")
CloseRequested = Console.ReadLine()
End Sub

' Function to get the mask for the game

Private Function RenderMask(ByVal Str As String) As String

' Declare local variables

Dim temp As String = ""
For Each Letter As Char In Str
If Letter = "-" Then
temp += "dash"
Else
temp += "the letter " & Letter
End If
temp += ", "
Next
Return temp
End Function

' Function to speak lines in the Microsoft Samantha voice

Private Sub SpeakLines(ByVal Str As String)

End Sub

' Sub to play sounds for the game

Private Sub PlaySound(ByVal Sound As String)

' Get the sounds and stream it to the game

Player.Stream = File.OpenRead(Path.Combine("Resources", Sound + ".wav"))
Player.PlaySync()
Player.Stream.Dispose()
End Sub

' Play A Game Sub starts here

Private Sub PlayAGame(ByVal PassedWord As String)

' Declare local variables

Dim EnteredLetter As String = ""
Dim MatchedLetterCount As Integer = 0

' For loop to guess 1 to 13 moves

Dim GuessCount As Integer = 0
Dim TempMask As String = ""
For GuessCount = 1 To 13
Console.WriteLine(WordMask)
SpeakLines("So far you have " & RenderMask(WordMask))
Console.WriteLine("Guess Number - " + GuessCount.ToString + ", Enter A Letter")
Console.WriteLine()
SpeakLines("Guess Number - " + GuessCount.ToString + ", Enter A Letter")
EnteredLetter = Console.ReadLine()
SpeakLines("You entered the letter " & EnteredLetter)
PlaySound("LaserBeamHit.wav")
If EnteredLetter <> "2"(0) Then
TempMask = WordMask
MatchedLetterCount = CheckEnteredLetter(PassedWord, EnteredLetter, MatchedLetterCount)
If TempMask <> WordMask Then
GuessCount -= 1
End If
If MatchedLetterCount = 6 Then
PlaySound("BugleReveille.wav")
Console.WriteLine("You Win!")
SpeakLines("You Win!")
Console.WriteLine("The word was " & WordMask)
SpeakLines("The word was " & WordMask)
WordMask = "------"
Exit For
End If
Else
ShowMessage()
GuessCount -= 1
End If
Next GuessCount
Console.WriteLine("Sorry, you used up all 13 guesses, you lose!")
SpeakLines("Sorry, you used up all 13 guesses, you lose!")
Console.WriteLine("The word was " & PassedWord)
SpeakLines("The word was " & PassedWord)
WordMask = "------"
End Sub

' Sub to show the message in the game

Private Sub ShowMessage()

' Declare local variables

Dim Title As String = "Program: Hangman."
Dim MessageString As String = " Author : Marvin Hunkin." + vbNewLine + "Version: 1.1." + vbNewLine + "Date: Tuesday December 25, 2012." + vbNewLine + "Description: Playing a Hangman game." + vbNewLine + "You enter a letter to use a list of words loaded into memory." + vbNewLine + "You then guess a six letter word, and use 13 guesses." + vbNewLine + "At the end of 13 guesses, you get a message saying you either won or loss," + vbNewLine + " and what the word was, and a number to exit the game being 1." + vbNewLine + "Added a couple of cool sound audio effects." + vbNewLine + "Press Enter to Continue."

Talker.Speak(Title)
Talker.SpeakAsync(MessageString)

' Show Messages for this sub

MessageBox.Show(MessageString, Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
Talker.SpeakAsyncCancelAll()
End Sub

' Function to check the letter for the game

Private Function CheckEnteredLetter(ByVal PassedWord As String, ByVal PassedLetter As String, ByVal PassedMatchedLetterCount As Integer) As Integer

' for loop to check that you entered up to 6 letters

For ndx As Integer = 0 To 5
If PassedWord(ndx) = PassedLetter Then
PassedMatchedLetterCount += 1
Mid(WordMask, ndx + 1) = PassedLetter
End If
Next ndx
Return PassedMatchedLetterCount
End Function

' Public function to get the random number selected for the game

Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer

' Declare variables

Dim Generator As System.Random = New System.Random()

' Return Generator random value for the game

Return Generator.Next(Min, Max)
End Function
End Module

http://startrekcafe.stevesdomain.net Yahoo! Groups

Continue reading...
 
Back
Top