Yay ! ^^
Today your gonna learn how to make a Maze Game
Let's start!
==============================================
Chapters..
I : Introduction to maze
II : Making it in VB
III : Debugging it ...
==============================================
Chapter I
WHAT IS MAZE?
Maze is a network of paths and hedges designed as a puzzle through which one has to find a way.
SCREEN SHOTS ?
Here is an example of a Maze game :
That's all for Chapter I
===============================================
Chapter II
(Longest Chapter)
Open VB....
Make a new project and name it to Maze Game
FORM 1 Properties :
Title : Maze Game
Size : 650, 650
MaximizeBox : False
FormBorderStyle : Fixed3D
Now you have a form that's a fixed size, which the user can't maximize.
Next, you want to create a playing field, where you build the maze. You use a Panel control for that. A panel is a type of container control that lets you lay out a group of controls. Unlike some of the other containers (like the TableLayoutPanel container and the FlowLayoutPanel container), a panel doesn't rearrange the controls that it contains. That gives you the freedom to position the controls wherever you want, but unlike the TableLayoutPanel or FlowLayoutPanel, a panel isn't helpful when the user resizes the window.
Go to the Containers group in the Toolbox and double-click Panel to add a panel to your form. When your panel is selected, you should see a move handle icon in its upper-left corner, which appears as follows.
Move Handle :
[IMG]http://i.msdn.microsof*****m/dynimg/IC279821.gif[/IMG]
Drag the panel until it's a small distance away from the upper-left corner of the form. As you drag it, you should notice a useful feature of the IDE: As soon as the panel is a certain distance from the top or the left edge of the form, it snaps into place, and a blue spacer line appears between the edge of the panel and the edge of the form. You can use this to easily align your panel so that its edges are all exactly the same distance from the edge of the form. As soon as you see the top and left blue spacer lines, release the mouse button to drop the panel in place.
Because you want the user to see the edge of the maze, you need to give it a visible border. Select the panel and set its BorderStyle property to Fixed3D.
In Windows Forms Designer, go to the Common Controls group in the Toolbox and double-click Label to make the IDE add a label to your form.
Label 1 Properties :
Change the Text property so that it's empty by selecting the text label1 and deleting it.
AutoSize : False
BackColor : Any color you want ..
Now you can be creative when building your maze. Copy your label by selecting it, and from the Edit menu, select Copy (or press Ctrl+C). Then, paste it several times. From the Edit menu, select Paste (or press Ctrl+V). This should provide horizontal maze walls. Take one of the walls and drag it so that it's tall and narrow. Copy and paste it a few times to provide vertical walls.
Drag the labels around your panel and create your maze. Don't make the passages too narrow, or your game will be too difficult to play. Leave extra space in the upper-left corner, because that's where the player starts the maze.After you lay out your maze, go to the Common Controls group in the Toolbox and double-click Label once again. Use the (Name) line in the Properties window to name it finishLabel, and change its Text property to Finish.
Drag your new Finish label to the end of the maze. That's the target that the user needs to hit.
Select the finishLabel control, and then click the Event icon at the top of the Properties window, which is shaped like a lightning bolt. When you click it, instead of showing the control's properties, it shows the control's events. You can return to the list of properties by clicking the Property icon. For now, keep the Properties window as is, so it's showing all of the events for the finishLabel control. Scroll down to the MouseEnter event.
Double-click the word MouseEnter. After you do, the IDE automatically adds an event handler method to your form and shows it to you in the code editor.
You want the program to open a message box that shows "Congratulations," and then you want the program to close. To do that, add lines of code (with a comment), as follows.
Code:
' Show a congatulatory Messagebox, then close the form.
MessageBox.Show("Congratulations")
Close()
You should see the finishLabel_MouseEnter() method that you added. Just below that method, add a new MoveToStart() method.
Code:
Private Sub MoveToStart()
Dim startingPoint = Panel1.Location
startingPoint.Offset(10, 10)
Cursor.Position = PointToScreen(startingPoint)
End Sub
There's a special type of comment that you can add above any method, and the IDE can help you add it. Put your cursor on the line above the new method. In Visual C#, add three slash marks (///). In Visual Basic, add three single quotation marks ('''). The IDE automatically fills in the following text.
Code:
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Private Sub MoveToStart()
Dim startingPoint = Panel1.Location
startingPoint.Offset(10, 10)
Cursor.Position = PointToScreen(startingPoint)
End Sub
On the line between the two summary tags, fill in the following comment. (After you press ENTER, the IDE automatically adds a new line with either three slash marks (///) or three single quotation marks ('''), depending on your programming language, so you can continue your comment.)
Code:
''' <summary>
''' Move the pointer to a point 10 pixels down and to the right
''' of the starting point in the upper-left corner of the maze.
''' </summary>
For Visual Basic, add this method in your form's code. Before the finishLabel_MouseEnter method, start typing the following code.
When you press the ENTER key to move to the next line, IntelliSense should make the following code appear to complete the method.
Code:
Public Sub New()
' This call is required by Windows Forms Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
This is a special method called the constructor. It gets executed once, when your form is created. Right now, all it does is call a method called InitializeComponent(). You will add a line to it to call the new MoveToStart() method that you just wrote. Before you continue, consider what to add to your program to get it to call the MoveToStart() method immediately after it calls the InitializeComponent() method.
Add a call to the MoveToStart() method immediately after it calls the InitializeComponent() method. Your form code should look like the following.
Code:
Public Class Form1
Public Sub New()
' This call is required by Windows Forms Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
MoveToStart()
End Sub
Private Sub finishLabel_MouseEnter() Handles finishLabel.MouseEnter
' Show a congratulatory MessageBox, then close the form.
MessageBox.Show("Congratulations!")
Close()
End Sub
''' <summary>
''' 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>
''' <remarks></remarks>
Private Sub MoveToStart()
Dim startingPoint = Panel1.Location
startingPoint.Offset(10, 10)
Cursor.Position = PointToScreen(startingPoint)
End Sub
End Class
Go to Windows Forms Designer and click any of your newly added walls.
Go to the Properties window and click the Event icon to display the events for that wall. Scroll down to the MouseEnter event. Instead of double-clicking it, type the text wall_MouseEnter, and then press ENTER.
After you press ENTER, the IDE adds a new event handler for you and connects it to that wall's MouseEnter event. The newly added code should appear in your code editor as follows. In Visual Basic, the specific label may not be Label8, as shown in the code.
Code:
Private Sub wall_MouseEnter() Handles Label8.MouseEnter
End Sub
Next, add a call to your MoveToStart() method, along with a comment explaining the method. Start by going to your method and adding the statement MoveToStart().
Press TAB to direct IntelliSense to complete the method name. If you're writing Visual C# code, remember to add the semicolon (

at the end of the statement. Then add a comment above the statement. Your code should look like the following. In Visual Basic, the specific label may not be Label8, as shown in the code.
Code:
Private Sub wall_MouseEnter() Handles Label8.MouseEnter
' When the mouse pointer hits a wall or enters the panel,
' call the MoveToStart() method.
MoveToStart()
End Sub
Go to Windows Forms Designer, and from the Edit menu, click Select All.
Hold down the CTRL key, and then click the Finish label to clear the selection. This should leave all of the walls and the panel selected.
Now go to the event table on the Properties window. Scroll down to the MouseEnter event and click the edit box next to it. You should see a drop-down arrow. If you click the arrow, you see a list of all of the event handlers in your program that you can choose for this event.
Select wall_MouseEnter. (If you select the wrong event handler or accidentally add a new one, you can select all of the walls and the panel again, and then choose the right method.)
Now your maze game should be more fun. Try saving it and running it. If your pointer hits a wall or if you move your pointer out of the maze and back in again, the program should automatically reposition the pointer at the starting point of the maze.
===============================================
Chapter III
Debug your newly maze game now ^^
The Debug button is the one that looks like a PLAY button ...
===============================================
Well... That's all for today !
Hope it helped in making a Maze Game ^^