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.

Game that you create in this tutorial

Game that you create in this tutorial

link to videoFor a video version of this topic, see Tutorial: Create a Maze in Visual Basic or How Do I: Create a Maze in C#?.

Note

In this tutorial, both Visual C# and Visual Basic are covered, so focus on information specific to the programming language that you're using.

Title

Description

Step 1: Create a Project and Add a Panel to Your Form

Begin by creating the project and adding a Panel container.

Step 2: Build Your Maze Using Labels

Build a maze by adding numerous Label controls to your form.

Step 3: End the Game

Make the maze game end by making the Finish label work.

Step 4: Add a Method to Restart the Game

Write your own method to restart the maze game.

Step 5: Add a MouseEnter Event Handler for Each Wall

Add an event handler to send the user's mouse pointer back to the start if the pointer touches a wall.

Step 6: Add a SoundPlayer

Begin to add sound to the maze game.

Step 7: Add Code to Your Form to Play Sounds

Call each SoundPlayer's Play() method to play your sound at the appropriate time.

Step 8: Run Your Program and Try Other Features

Run your program and test it. Try other features, such as changing sounds and colors.