Cool Typing Game (Test your typing speed)
Posted by Samath
Last Updated: September 22, 2012

Hello everyone my name is Samath, today I am going to show you how to create a cool typing game using visual basic.net. I wrote this program when I was a novice in the programming world. I started my .Net journey with visual Basic.net then later migrated to the one and only C#. This program was one of the first I wrote in that time. I am going to explain everything thats going on in the program from the GUI to the code. By time I’m finish you will be able to create one of your own.

Lets Begin!

I am going to start with the splash screen. The splash screen purpose is to load all the components of the program. But in my case its only here for its good looks…lol. Here is a screen shot of the splash screen at development time and at run time.

Impressive isn’t it. I am now going to explain the code behind this beautiful design.

Public NotInheritable Class SplashScreen1

    Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       ' This Change the default to a icon that is located in resources

        Me.Cursor = New Cursor(My.Resources._1__62_.Handle)

End Sub

 

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick   

        pbStatus.Increment(15)

        If pbStatus.Value >= pbStatus.Maximum Then

            Timer1.Enabled = False

        End If

 

        If pbStatus.Value <= 30 Then

            lblload.Text = "Initializing....."

        ElseIf pbStatus.Value <= 50 Then

            lblload.Text = "Loading components....."

        ElseIf pbStatus.Value <= 70 Then

            lblload.Text = "Loading components....."

        ElseIf pbStatus.Value <= 100 Then

            lblload.Text = "Please wait..."

        End If

 

        If pbStatus.Value = 100 Then

            frmmenu.Show()

            Me.Hide()

            Timer1.Enabled = False

        End If

    End Sub

   End Class

 

 Main Menu

 

Public Class frmmenu

    Private Sub frmmenu_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

        End

    End Sub

    Private Sub frmmenu_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave

        End

    End Sub

    Private Sub frmmenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized

        Me.Cursor = New Cursor(My.Resources._1__62_.Handle)

    End Sub

    Private Sub lblpalygame_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblpalygame.MouseHover

        lblpalygame.BackColor = Color.Black

        My.Computer.Audio.Play(My.Resources.Menusound, AudioPlayMode.Background)

    End Sub

    Private Sub lblpalygame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblpalygame.Click

        Form1.Show()

        Me.Hide()

    End Sub

    Private Sub lblpalygame_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblpalygame.MouseLeave

        lblpalygame.BackColor = Color.WhiteSmoke

    End Sub

    Private Sub lblllquitgame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblllquitgame.Click

        End

    End Sub

    Private Sub lblllquitgame_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblllquitgame.MouseHover

        lblllquitgame.BackColor = Color.Black

        My.Computer.Audio.Play(My.Resources.Menusound, AudioPlayMode.Background)

    End Sub

    Private Sub lblllquitgame_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblllquitgame.MouseLeave

        lblllquitgame.BackColor = Color.WhiteSmoke

    End Sub

    Private Sub lblhelp_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblhelp.MouseHover

        lblhelp.BackColor = Color.Black

        My.Computer.Audio.Play(My.Resources.Menusound, AudioPlayMode.Background)

    End Sub

    Private Sub lblabout_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblabout.MouseHover

        lblabout.BackColor = Color.Black

        My.Computer.Audio.Play(My.Resources.Menusound, AudioPlayMode.Background)

    End Sub

    Private Sub lblhelp_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblhelp.MouseLeave

        lblhelp.BackColor = Color.WhiteSmoke

    End Sub

    Private Sub lblabout_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblabout.MouseLeave

        lblabout.BackColor = Color.WhiteSmoke

    End Sub

    Private Sub lblabout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblabout.Click

        MsgBox("Storm typer v1.0, Created by Samath Scott ")

    End Sub

    Private Sub lblword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblword.Click

startit:

        My.Settings.Word = InputBox("Word ?", "Change Title")

        My.Settings.Save()

        Form1.Label1.Text = My.Settings.Word

        My.Settings.highscore = "00:60:00"

        My.Settings.name = "Computer"

        If Form1.Label1.Text = "" Then

            GoTo startit

        End If

    End Sub

    Private Sub lblword_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblword.MouseLeave

        lblword.BackColor = Color.WhiteSmoke

    End Sub

    Private Sub lblword_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblword.MouseHover

        lblword.BackColor = Color.Black

        My.Computer.Audio.Play(My.Resources.Menusound, AudioPlayMode.Background)

    End Sub

End Class

 

 

Let the Game Begin!

 

 

 

Imports System.IO

Public Class Form1

    Dim The_Time, mistakes_Count, Curent_Char As Integer

    Dim The_Text As String

    Dim min As Integer = 0

    Dim sec As Integer = 0

    Dim msec As Integer = 0

    Dim textfile As String

    Dim yourname As String

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        My.Computer.Audio.Play(My.Resources.Goodbye, AudioPlayMode.WaitToComplete)

        frmmenu.Show()

    End Sub

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

 

        If Timer1.Enabled = False Then Timer1.Enabled = True

 

        ' press Esc butonn to restart the game

        If e.KeyChar.ToString = "_" Then

            ' restart the game

            Timer1.Enabled = False

            Curent_Char = 1

            Label5.Text = ""

            Time_Label.Text = "00:00:00"

            The_Time = 0

            mistakes_Count = 0

            Wrong_Label.Text = 0

            min = 0

            sec = 0

            msec = 0

            Exit Sub

        End If

 

        ' checking the chracter

        If e.KeyChar = Mid(The_Text, Curent_Char, 1) Then

 

            Label5.Text = Label5.Text & Mid(The_Text, Curent_Char, 1)

            ' checking if the user finsh the exercies

            If Label5.Text = The_Text Then

                Timer1.Enabled = False

                MsgBox("excellent you have done the exercise during : " & Time_Label.Text & " and mistakes number :  " & mistakes_Count, , "Good job")

                ' restart the game

                Curent_Char = 1

                Label5.Text = ""

                Time_Label.Text = "00:00:00"

                The_Time = 0

                mistakes_Count = 0

                Wrong_Label.Text = 0

                min = 0

                sec = 0

                msec = 0

                Exit Sub

            End If

            Curent_Char += 1

        Else

            mistakes_Count += 1

            Wrong_Label.Text = mistakes_Count

            Label5.BackColor = (Color.Red)

            My.Computer.Audio.Play(My.Resources.error_sound, AudioPlayMode.Background)

            Timer2.Enabled = True

        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Cursor = New Cursor(My.Resources._1__62_.Handle)

        Label1.Text = My.Settings.Word

        The_Text = Label1.Text

        Curent_Char = 1

        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

        Me.WindowState = FormWindowState.Maximized

        ListBox1.Items.Add(My.Settings.name)

        ListBox1.Items.Add(My.Settings.highscore)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        msec = msec + 1

        If msec = 10 Then

            sec = sec + 1

            msec = 0

        End If

        If sec = 60 Then

            min = min + 1

            sec = 0

        End If

        If Timer1.Enabled = False Then

            min = 0

            sec = 0

            msec = 0

        End If

        Time_Label.Text = (Format(min, "00") & ":" & Format(sec, "00") & ":" & Format(msec, "00"))

    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

        Label5.BackColor = (Color.White)

        Timer2.Enabled = False

    End Sub

    Private Sub tmrchangewords_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrchangewords.Tick

        String.Compare(Time_Label.Text, My.Settings.highscore)

        If Time_Label.Text <> "00:00:00" Then

            If Timer1.Enabled = False Then

                If Time_Label.Text < My.Settings.highscore Then

                    tmrchangewords.Enabled = True

                    tmrchangewords.Interval = 1999900000

                    My.Computer.Audio.Play(My.Resources.Soundthealarm, AudioPlayMode.WaitToComplete)

                    My.Computer.Audio.Play(My.Resources.newrecordvoice, AudioPlayMode.Background)

                    yourname = InputBox("Please enter your name", "New Record", "name")

                    tmrchangewords.Interval = 100

                    ListBox1.Items.Clear()

ListBox1.Items.Add(yourname)

ListBox1.Items.Add(Time_Label.Text)

                    My.Settings.highscore = Time_Label.Text

                    My.Settings.name = yourname

                    My.Settings.Save()

                    tmrchangewords.Enabled = False

                End If

            End If

        End If

        tmrchangewords.Enabled = True

    End Sub

    Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label10.Click

        Me.Close()

    End Sub

End Class 

 

 

 

 

Related Content
The Matching Game in Java
The Matching Game in Java
Samath | Mar 20, 2015
Hangman Game in C++
Hangman Game in C++
Samath | Jan 17, 2024
Hangman Game using C#
Hangman Game using C#
Samath | Jan 17, 2024
Animal Game in Java
Animal Game in Java
gideonna | Apr 13, 2016
Number Guessing Game using C++
Number Guessing Game using C++
Samath | Jan 04, 2017
Blackjack Game in C++
Blackjack Game in C++
Samath | Jan 05, 2017
Checkers Game using C++
Checkers Game using C++
Samath | Jan 17, 2024
Minesweeper Game using C++
Minesweeper Game using C++
Samath | Jan 05, 2017
Craps Dice game in C++
Craps Dice game in C++
Samath | Jan 06, 2021
Paper Strip Game using Python
Paper Strip Game using Python
Samath | Jan 17, 2024
Tic Tac Toe Game using C#
Tic Tac Toe Game using C#
Samath | Jan 17, 2024
John Conway's Game of Life using C++
John Conway's Game of Life using C++
Samath | Jan 04, 2017
C++ Rock Paper Scissors Game
C++ Rock Paper Scissors Game
Samath | Jan 05, 2017
Tic Tac Toe Game using Python
Tic Tac Toe Game using Python
Samath | Jan 17, 2024
Casino Number Guessing Game in C++
Casino Number Guessing Game in C++
Samath | Jan 20, 2024