Tutorial 2: Create a Maze
In this tutorial, you build a maze game, where the user has to move the mouse pointer from the start to the finish without touching any of the walls. You learn how to:
Lay out a form using a Panel container.
Build a maze using Label controls.
Write code to show a message box.
Set up event handlers for mouse events.
Play sounds in your program.
Organize your code using classes.
Here's how the maze will work: The mouse pointer starts at the upper-left corner of the maze. The user navigates through the maze, being careful not to touch any of the walls with the pointer. If the pointer touches one of the walls, it automatically jumps back to the start. But if the pointer reaches the Finish label at the end of the maze, a "Congratulations" message box opens, and the game ends.
When you finish, your program will look like the following picture.
In this tutorial, both Visual C# and Visual Basic are covered, so focus on information specific to the programming language that you're using.
Begin by creating the project and adding a Panel container.
Build a maze by adding numerous Label controls to your form.
Make the maze game end by making the Finish label work.
Write your own method to restart the maze game.
Add an event handler to send the user's mouse pointer back to the start if the pointer touches a wall.
Begin to add sound to the maze game.
Call each SoundPlayer's Play() method to play your sound at the appropriate time.
Run your program and test it. Try other features, such as changing sounds and colors.