コードは現在更新されており、完了したと感じるまでに 2 つの問題しか残っていません。
プレイヤーが壁にぶつかると、ヒットごとにカウンターが 2 ライフ減少します。
ゲームが開始されると、プレイヤーが壁にぶつかったときにのみ鳴るはずの音(beep.wav)がゲームを開始するたびに鳴り、ゲーム全体で再生されるはずの音(onestop.wav)が再生されませんまったく。
public partial class Form1 : Form
{
// This SoundPlayer plays a song when the game begins.
System.Media.SoundPlayer onestop = new System.Media.SoundPlayer(@"C:\Users\kC\Favorites\Desktop\Kev stuff\Projects\MazeGame\onestop.wav");
// This SoundPlayer plays a sound whenever the player hits a wall.
System.Media.SoundPlayer beepSound = new System.Media.SoundPlayer(@"C:\Users\kC\Favorites\Desktop\Kev stuff\Projects\MazeGame\beep.wav");
// This SoundPlayer plays a sound when the player finishes the game.
System.Media.SoundPlayer clapSound = new System.Media.SoundPlayer(@"C:\Users\kC\Favorites\Desktop\Kev stuff\Projects\MazeGame\winningApplause.wav");
public Form1()
{
InitializeComponent();
timer1.Interval = (1000) * (1);
timer1.Enabled = true;
timer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
begin();
}
private void begin()
{
onestop.Play();
livesTextBox.Text = lives.ToString();
Point startingPoint = panel1.Location;
startingPoint.Offset(10, 10);
Cursor.Position = PointToScreen(startingPoint);
}
int lives = 5;
private void MoveToStart()
{
if ( lives > 0)
{
lives--;
}
if (lives == 0)
{
MessageBox.Show("You Lose!!");
Close();
}
else if (lives < 0)
{
MessageBox.Show("You Lose!!");
Close();
}
}
private void wall_MouseEnter(object sender, EventArgs e)
{
// When the mouse pointer hits a wall or enters the panel,
// call the MoveToStart() method.
beepSound.Play();
MoveToStart();
lives--;
livesTextBox.Text = lives.ToString();
}
private void finishLabel_MouseEnter(object sender, EventArgs e)
{
// Play a sound, show a congratulatory MessageBox, then close the form.
clapSound.Play();
MessageBox.Show("Congratulations! You've beaten the maze!");
Close();
}
int gameElapsed = 0;
private void timer1_Tick(object sender, EventArgs e)
{
gameElapsed++;
textBox1.Text = "" + gameElapsed.ToString();
}
}