Hello guys, Welcome to the first version of Catch me ( Visual Basic Game read Introduction )
Ok, Let's Start Open Visual Studio 2012 and Open new project
In One of the 2 Button make it's Text property to Quit and the another make it Start
In Quit Button Click Event Paste this Code
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
--Application.Exit()
- End Sub
In Timer1 Tick Event paste this code
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If stopper = 59 Then
Timer1.Enabled = False
Button1.Visible = True
Button2.Visible = True
Label1.Visible = True
PictureBox1.Visible = False
Label1.Text = "Your Result =" & result & " ,Do You want to play again ?"
Else
Dim x As Integer
Dim y As Integer
x = CInt(Rnd() * 800 - 0)
y = CInt(Rnd() * 600 - 0)
PictureBox1.Location = New Point(x, y)
End If
stopper += 1
Label2.Text = "Time: " & 60 - stopper & "s"
End Sub
This Code is the most important part in the game 1st we have an if statement that will check if stopper (our variable we define him early) = 59 (I decreased one from it because it start from 0 not 1 ) if yes the timer will stop and all controls will appear and picture will disappear else we define 2 variable x,y (location of the image) by using Rnd() function click in it to read about it and at the end of the code we increase the stopper by 1 and Decrease Label2 by 1 "Because my interval = 1000 Milliseconds (1 seconds)"
In PictureBox1 click event paste this
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
result += 1
End Sub
in this Code, We will increase result with 1 if the Player press in it
That All, Wait for me in Catch Me Version 2.0.0 comment below if you want any help I will answer you as soon as possible
Click here to download the game (As visual Studio Project)
Ok, Let's Start Open Visual Studio 2012 and Open new project
1. Program Design Stage
Let's add the tools 1 PictureBox, 2 Button, 2 Label, 1 Timer
In Picturebox1
My Image |
- Choose any picture in my case I will choose this image
- Make Visible Property = False
- Resize it as you like I will make it (150,150)
- Don't forget to Change SizeMode to StretchImage
Button1, Button2
Label1
In Label1 change the Text to your Description
Label2
In Label2, Change the Text to "Time: 60s" without quotation put in the middle Bottom of the Form and 60s is the game time
Timer1
Form1
- Change FormBorderStyle to None
- Change the Size to 800,600
- Change StartPostion to Centre of the Screen
Ok Your Window Should be like this
2. Program Coding
Ok now Press F7 and After Public Class Form1 paste this
Dim result As Integer
Dim stopper As Integer
This some variable we will use later Dim result As Integer
Dim stopper As Integer
In Quit Button Click Event Paste this Code
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
--Application.Exit()
- End Sub
I think this code doesn't need to explain
In Start Button Click event paste this code
-Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-- Button1.Visible = False
--Button2.Visible = False
--Label1.Visible = False
--PictureBox1.Visible = True
--Timer1.Enabled = True
--result = 0
--stopper = 0
-End Sub
Ok in this Code we hid all Controls expect The Timer Label (label2), We showed PictureBox1 and we enabled Timer1 and we return the result and the stopper to zero if the player will play again
-Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-- Button1.Visible = False
--Button2.Visible = False
--Label1.Visible = False
--PictureBox1.Visible = True
--Timer1.Enabled = True
--result = 0
--stopper = 0
-End Sub
Ok in this Code we hid all Controls expect The Timer Label (label2), We showed PictureBox1 and we enabled Timer1 and we return the result and the stopper to zero if the player will play again
In Timer1 Tick Event paste this code
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If stopper = 59 Then
Timer1.Enabled = False
Button1.Visible = True
Button2.Visible = True
Label1.Visible = True
PictureBox1.Visible = False
Label1.Text = "Your Result =" & result & " ,Do You want to play again ?"
Else
Dim x As Integer
Dim y As Integer
x = CInt(Rnd() * 800 - 0)
y = CInt(Rnd() * 600 - 0)
PictureBox1.Location = New Point(x, y)
End If
stopper += 1
Label2.Text = "Time: " & 60 - stopper & "s"
End Sub
This Code is the most important part in the game 1st we have an if statement that will check if stopper (our variable we define him early) = 59 (I decreased one from it because it start from 0 not 1 ) if yes the timer will stop and all controls will appear and picture will disappear else we define 2 variable x,y (location of the image) by using Rnd() function click in it to read about it and at the end of the code we increase the stopper by 1 and Decrease Label2 by 1 "Because my interval = 1000 Milliseconds (1 seconds)"
In PictureBox1 click event paste this
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
result += 1
End Sub
That All, Wait for me in Catch Me Version 2.0.0 comment below if you want any help I will answer you as soon as possible
Click here to download the game (As visual Studio Project)
Comments
Post a Comment