I am following this toturial.
Click Here
In the try other feature section:
*Set it up so that the game only plays a sound when the mouse pointer hits a wall, but doesn't play a sound when the program starts. *
I figured moving hitWallSoundPlayer.Play();
from private void MoveToStart()
to private void wall_MouseEnter(object sender, EventArgs e)
would be the solution, however, the sound is still played as soon as the program starts.
Is it because the pointer is is not at the correct postion when the program starts?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Maze
{
public partial class Form1 : Form
{
// This SoundPlayer plays a sound whenever the player hits a wall.
System.Media.SoundPlayer hitWallSoundPlayer = new System.Media.SoundPlayer(@"C:\Windows\Media\ir_begin.wav");
// This SoundPlayer plays a sound when the player finishes the game.
System.Media.SoundPlayer finishSoundPlayer = new System.Media.SoundPlayer(@"C:\Windows\Media\tada.wav");
public Form1()
{
InitializeComponent();
MoveToStart();
}
/// <summary>
/// Move the pointer to a point 10 pixels down and to the right
/// of the starting point in the upper-left corner of the maze.
/// </summary>
private void MoveToStart()
{
//hitWallSoundPlayer.Play();
Point startingPoint = panel1.Location;
startingPoint.Offset(10, 10);
Cursor.Position = PointToScreen(startingPoint);
}
private void finishLabel_MouseEnter(object sender, EventArgs e)
{
finishSoundPlayer.Play();
// Show a congratulatory MessageBox, then close the form.
MessageBox.Show("Congratulations!!!");
Close();
//MoveToStart();
}
private void wall_MouseEnter(object sender, EventArgs e)
{
hitWallSoundPlayer.Play();
MoveToStart();
}
}
}