1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
|
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 startSoundPlayer = new System.Media.SoundPlayer(@"C:\Windows\Media\chord.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");
int time, i=1;
public Form1()
{
InitializeComponent();
MoveToStart();
}
private void finishLabel_MouseEnter(object sender, EventArgs e)
{
// Play a sound, show a congratulatory MessageBox, then close the form.
finishSoundPlayer.Play();
MessageBox.Show("Herzlichen Glückwunsch!");
Close();
}
/// <summary>
/// Play a sound, then move the mouse 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()
{
startSoundPlayer.Play();
Point startingPoint = panel1.Location;
startingPoint.Offset(10, 10);
Cursor.Position = PointToScreen(startingPoint);
}
private void wall_MouseEnter(object sender, EventArgs e)
{
// When the mouse pointer hits a wall or enters the panel,
// call the MoveToStart() method.
MoveToStart();
}
private void startTimer(object sender, EventArgs e)
{
if (i == 1)
{
time = 1;
timeLabel.Text = "0 Sekunden";
timer1.Start();
i++;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
timeLabel.Text = time + " Sekunden";
time++;
}
}
}
|