|
|
|
|
1 |
Software
use: Microsoft Visual Studio 2010 Professional |
|
2 |
The Microsoft Visual Basic 2010 member of the
Microsoft Visual Studio 2010 Professional |
|
|
|
|
FaceGame_10 application ..., describe how to use Microsoft Visual Basic 2010 to create game
application
The
Classes used in this application
System.Console, System.Drawing, System.Resources, ImageList, Label, MainMenu,
Panel,
PictureBox, Timer,
ToolBar
- Name
-
FaceGame_10
-
Game Software.
- Developed with
Microsoft Visual Basic 2010.
-
Functions ...
-
Arrange boxes using the mouse
- Demo
Game
|
- Requirements:
Microsoft Visual Studio 2010 Professionnal.
If you want to run it:
- Remove the
read-only attribute of all files in
the folder -
C:\VBN_FGame_10
- Run the
Microsoft Visual Studio 2010 Professional.
- From
File menu, choose Open
then choose
Project/Solution, the
Open Project dialog box
appears, select the FaceGame_10 project file -Type:
Microsoft Visual Studio Solution
(C:\FaceGame_10\FaceGame_10.sln)
and then click Open.
- From
Debug menu, choose and click
Start Debugging.
|
Project - FaceGame_10 and those items
|
|
|
2-
Create new Visual Basic 2010 project - FaceGame_10 |
|
a. |
Create new Visual Basic 2010 project -
FaceGame_10, The steps to create
...
|
Run
Microsoft Visual Studio 2010 Professional. On the
File menu , click New, and then click Project
.... The New Project dialog box appears.
- In the installed
Templates pane, select the Visual Basic
- and then Select
Windows Forms Application icon.
A message appears: Type: Visual Basic.
A project for creating an application with a Windows user
interface.
- In
the Name box, type
FaceGame_10
- In
the Location box, type
C:\
- Click
OK.
The
Windows Application create all
necessary files and opens the Visual Basic 2010 project -
FaceGame_10. System Create Automaticaly Empty Form
- Form1.vb.The codes file, created
...
Public
Class
Form1
Private
Sub
Form1_Load(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
MyBase.Load
End
Sub
End
Class |
Rename
the created Form -
Form1.vb
- On the
View menu , click
Solution Explorer
- In
Solution Explorer, expand
the FaceGame_10 project node and select
Form1.vb
- In
Properties windows, Type
the new File Name =
FaceGame.vb
| |
|
|
|
3-
Create Visual Basic Form, FaceGame.vb |
|
a-
the Form Design |
The View
design.. |
 |
From the Toolbox\windows Form
addthe following controls
One ImageList control, thirty
eight Label controls
, one MainMenu
controls, twele Panel
controls,
tree PictureBox
controls, one ToolBar
controls and four Timer
controls.
The
Functions ...
Arrange boxes using the
mouse
|
|
|
b-
the Form Code, To Continue Click --->
The Codes .. |
|
Note
- random numbers order
:
in Visual Basic 2010, the random number
generator used
1- Rnd()
function - returns a value less than 1, but
greater than or equal to zero.
2- Dim vrnd as
Integer
3- vrnd = Int(9 * Rnd()) + 1
|
|
c-
After running, the following designs display by order |
|
|
|
|
 |
After running, the
following designs display by
order |
|
|
|
|
|
4-
Create Visual Basic Form, DemoForm.vb |
|
a. |
DemoForm design
This
Form displays when you select the Zoom button
( zoom+ ) from PictureForm.vb
The
Form design.
The View
design.
From
the Toolbox\windows Form addthe
following controls
One
button control, forty six Label
controls, teen Panel
controls, one PictureBox control and two
Panel
controls.
The
Functions
... Show
how this Game work
.
|
|
|
b. |
DemoForm,
the Godes |
|
|
|
|
Imports
System.Console
Public
Class
DemoForm
Inherits
System.Windows.Forms.Form
Dim vtime
As
New
System.DateTime
Dim StartDemo_Date
As
DateTime
Dim Demo_Move_Flag
As
Boolean
Dim
Demo_Interval_Flag
As
Boolean
Dim begin_demo
As
Boolean
Dim vinterval_demo
As
Long
Dim Vcount
As
Integer = 0
Dim DemoCounter1
As
Integer
Private
Sub
DemoForm_Load(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
MyBase.Load
xPanel1.SetBounds((512), (208), 96, 96)
xPanel2.SetBounds((320), (112), 96, 96)
xPanel3.SetBounds((320), (208), 96, 96)
xPanel4.SetBounds((416), (208), 96, 96)
xPanel5.SetBounds((512), (16), 96, 96)
xPanel6.SetBounds((416), (16), 96, 96)
xPanel7.SetBounds((416), (112), 96, 96)
xPanel8.SetBounds((512), (112), 96, 96)
xPanel9.SetBounds((320), (16), 96, 96)
PPicture.Height = 290
PPicture.Width = 290
Me.PictureBox1.Top =
(Me.PPicture.Height
- Me.PictureBox1.Height)
/ 2
Me.PictureBox1.Left
= (Me.PPicture.Width
- Me.PictureBox1.Width)
/ 2
PPicture.SetBounds(16, 368, 290, 290)
Me.Timerclock.Enabled
=
True
begin_demo =
True
End
Sub
Private
Sub
btnclose_Click(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
btnclose.Click
Me.Close()
FFaceGameNet.New_Game()
End
Sub
Private
Sub
Demo_Timer_Tick(ByVal
Sender
As
System.Object,
ByVal eventArgs
As
System.EventArgs)
Handles
Demo_Timer.Tick
TheDemo()
If Demo_Move_Flag
Then
DemoCounter1 = DemoCounter1 + 1
demoSub()
If DemoCounter1 = 11
Then
Beep()
Beep()
Beep()
Demo_Move_Flag =
False
Demo_Interval_Flag =
False
ElseIf DemoCounter1
>= 0
And
DemoCounter1 <= 9
Then
Beep()
End
If
End
If
End
Sub
Private
Sub
demoSub()
If DemoCounter1 = 1
Then
xPanel8.SetBounds((8), (112), 96, 96)
ElseIf DemoCounter1
= 2
Then
xPanel1.SetBounds((8), (16), 96, 96)
ElseIf DemoCounter1
= 3
Then
xPanel2.SetBounds((104), (112), 96, 96)
ElseIf DemoCounter1
= 4
Then
xPanel3.SetBounds((104), (16), 96, 96)
ElseIf DemoCounter1
= 5
Then
xPanel4.SetBounds((8), (208), 96, 96)
ElseIf DemoCounter1
= 6
Then
xPanel5.SetBounds((200), (16), 96, 96)
ElseIf DemoCounter1
= 7
Then
xPanel9.SetBounds((104), (208), 96, 96)
ElseIf DemoCounter1
= 8
Then
xPanel6.SetBounds((200), (208), 96, 96)
ElseIf DemoCounter1
= 9
Then
xPanel7.SetBounds((200), (112), 96, 96)
ElseIf DemoCounter1
= 10
Then
PPicture.SetBounds(320, 16, 288, 288)
Demo_Char_MultiColor()
End
If
End
Sub
Private
Sub
Demo_Char_MultiColor()
lb13.ForeColor =
Color.Green
lb14.ForeColor =
Color.Green
lb21.ForeColor =
Color.Red
lb22.ForeColor =
Color.Red
lb23.ForeColor =
Color.Red
lb24.ForeColor =
Color.Red
lb32.ForeColor =
Color.Green
lb33.ForeColor =
Color.Red
lb34.ForeColor =
Color.Green
lb41.ForeColor =
Color.Green
lb44.ForeColor =
Color.Green
lb52.ForeColor =
Color.Green
lb53.ForeColor =
Color.Green
lb61.ForeColor =
Color.Green
lb62.ForeColor =
Color.Green
lb71.ForeColor =
Color.Green
lb72.ForeColor =
Color.Red
lb73.ForeColor =
Color.Green
lb81.ForeColor =
Color.Green
lb83.ForeColor =
Color.Green
lb84.ForeColor =
Color.Red
lb91.ForeColor =
Color.Red
lb92.ForeColor =
Color.Green
lb94.ForeColor =
Color.Green
End
Sub
Private
Sub
Timerclock_Tick(ByVal
eventSender
As
System.Object,
ByVal eventArgs
As
System.EventArgs)
Handles
Timerclock.Tick
'
Clock
Me.Ltime1.Text =
Date.Now.ToLongTimeString.ToString
'
Timer Interval
If
Demo_Interval_Flag
Then
vinterval_demo = DateDiff( DateInterval.Second,
StartDemo_Date,
Date.Now)
LIntervalDemo.Text = Str(vinterval_demo) &
" Sec"
End
If
End
Sub
Private
Sub
TheDemo()
Vcount = Vcount + 1
If Vcount = 1
Then
LDemo.ForeColor =
Color.Red
ElseIf Vcount = 2
Then
LDemo.ForeColor =
Color.Navy
ElseIf Vcount = 3
Then
LDemo.ForeColor =
Color.Salmon
If begin_demo
Then
Demo_Move_Flag =
True
StartDemo_Date =
Date.Now
LTImer.Visible =
True
LIntervalDemo.Visible =
True
Demo_Interval_Flag =
True
begin_demo =
False
End
If
ElseIf Vcount = 4
Then
LDemo.ForeColor =
Color.Green
ElseIf Vcount = 5
Then
LDemo.ForeColor =
Color.Brown
Vcount = 0
End
If
End
Sub
Private
Sub
DemoForm_Closed(ByVal
sender
As
Object,
ByVal
e As
System.EventArgs)
Handles
MyBase.Closed
FFaceGameNet.New_Game()
End
Sub
End
Class | |
|
|
|
|
|
|
|
5-
Create Visual Basic Form, AboutForm.vb |
|
|
a- AboutForm, Design
This
Form displays, when you
select the Toolbar Button About from
FaceGameNet.vb.
This Form includes the
following controls:
Tree PictureBox control, seven
Label controls, one
Button control
and one Timer
control.
Click
the Button Done, the
current Form unload
b- AboutForm, The Codes ...
Public
Class
AboutForm
Inherits
System.Windows.Forms.Form
Dim IcoNmbr
As
Integer
Private
Sub
AboutForm_Load(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
MyBase.Load
IcoNmbr = 0
Me.Timer1.Enabled =
True
End
Sub
Private
Sub
btnDone_Click(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles
btndone.Click
'
To close the current form
Me.Close()
FFaceGameNet.New_Game()
End
Sub
Private
Sub
Timer1_Tick(ByVal
sender
As
System.Object,
ByVal e
As
System.EventArgs)
Handles Timer1.Tick
If IcoNmbr = 0
Then
Me.picico.Image =
Me.picicoOrg0.Image()
IcoNmbr = 1
Else
Me.picico.Image =
Me.picicoOrg1.Image()
IcoNmbr = 0
End
If
End
Sub
Private
Sub
AboutForm_Closed(ByVal
sender
As
Object,
ByVal
e As
System.EventArgs)
Handles
MyBase.Closed
FFaceGameNet.New_Game()
End
Sub
End
Class |
|
|
|
|
6-
Create Module - Module1.vb |
|
|
1-
Module -
Module1.vb |
|
On the Project
menu , click Add New Item ..., The
Add New Project - FaceGame_10 dialog box appears :.In this
Add New Item - FaceGame_10 dialog box:
Select
Module icon.
A message appears: Type: Common Items.
A file for storing groups of functions
In the Name
box, type Module1.vb
Click Add
The
Module1.vb code stores
information about all public variables
used in this application.
2- Module,
The codes ...
Module
Module1
Public
FFaceGameNet
As
New
FaceGame
Public
Sub
Main()
'
Starts this application
FFaceGameNet =
New
FaceGame
Application.Run(FFaceGameNet)
End
Sub
End
Module |
|
b- |
Set new Startup object - Sub Main
|
|
- On the
Project menu ,
click FaceGame_10 Properties
..., the FaceGame_10 Property Pages
dialog box appears
- In the
Startup form combo
box, choose and
select FaceGame
- In the
Icon combo
box, choose and
select
pic\Face.ico
|
|
|
|
|