代码现在更新,只剩下两个问题,直到我很高兴我已经完成了它。
当玩家撞到墙时,计数器会以每次击中 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();
}
}