Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
JEU DE RAPIDITÉ AU CLAVIER EN VB .NET 2.0 (FAIT AVEC VB EXPRESS 2005)
Information sur la source
Description
Ce petit jeu s'adresse à ceux qui veulent tester leur rapidité au clavier :) Il y a trois mode : - Letters only, avec seulement les touches de lettre + touche Espace (idéal pour apprendre à taper du texte) - Laptop, l'équivalent du mode expert pour les Portables (sans les touches numériques) - Expert, avec les touches alphabétiques, les touches F1 à F12, les touches de directions, les touches numériques ainsi que la touche Verr Num. Le principe est simple : le nom d'une touche s'affiche, si on la frappe c'est score+1 et si on se trompe c'est score-1 :) Vous disposez de 30 sec, et vous devez donc vous dépécher de taper le plus possible de touches affichées à l'écran. Je vous dis mon score en mode expert, c'est 43 pour le moment :) A vos claviers!
Source
- 'Auteur : Gabriel Hautclocq
- '
- Public Class Main
-
- Private touches As New Hashtable()
- Private time As Single
- Private score As Integer
- Private rndTouche As Integer
- Private trouve As Boolean = True
- Private encours As Boolean = False
- Private mode As Integer
- Private Const duree As Single = 30
-
- Private Sub Main_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- Arreter()
- End Sub
-
- Private Sub Main_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
- If Not encours Then
- Demarrer()
- Else
- Arreter()
- End If
- End Sub
-
- Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
- If Not encours Then
- Demarrer()
- Else
- Arreter()
- End If
- End Sub
-
- Private Sub Main_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
- If encours Then
- If e.KeyData.ToString() = touches(rndTouche) Then
- trouve = True
- score = score + 1
- My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
- Else
- score = score - 1
- My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)
- End If
- Label3.Text = "Score : " & score
- Else
- If e.KeyData = Keys.Enter Or e.KeyData = Keys.Return Then
- Demarrer()
- End If
- End If
- End Sub
-
- Private Sub initialisation()
-
- touches.Clear()
- Dim currentMode As Integer = getMode()
-
- 'Mode de base
- touches.Add(1, "A")
- touches.Add(2, "B")
- touches.Add(3, "C")
- touches.Add(4, "D")
- touches.Add(5, "E")
- touches.Add(6, "F")
- touches.Add(7, "G")
- touches.Add(8, "H")
- touches.Add(9, "I")
- touches.Add(10, "J")
- touches.Add(11, "K")
- touches.Add(12, "L")
- touches.Add(13, "M")
- touches.Add(14, "N")
- touches.Add(15, "O")
- touches.Add(16, "P")
- touches.Add(17, "Q")
- touches.Add(18, "R")
- touches.Add(19, "S")
- touches.Add(20, "T")
- touches.Add(21, "U")
- touches.Add(22, "V")
- touches.Add(23, "W")
- touches.Add(24, "X")
- touches.Add(25, "Y")
- touches.Add(26, "Z")
- touches.Add(27, "Space")
-
- If currentMode > 1 Then 'Mode Laptop
- touches.Add(28, "F1")
- touches.Add(29, "F2")
- touches.Add(30, "F3")
- touches.Add(31, "F4")
- touches.Add(32, "F5")
- touches.Add(33, "F6")
- touches.Add(34, "F7")
- touches.Add(35, "F8")
- touches.Add(36, "F9")
- touches.Add(37, "F10")
- touches.Add(38, "F11")
- touches.Add(39, "F12")
- touches.Add(40, "Up")
- touches.Add(41, "Down")
- touches.Add(42, "Left")
- touches.Add(43, "Right")
-
- If currentMode > 2 Then 'Mode Expert
- touches.Add(44, "NumPad0")
- touches.Add(45, "NumPad1")
- touches.Add(46, "NumPad2")
- touches.Add(47, "NumPad3")
- touches.Add(48, "NumPad4")
- touches.Add(49, "NumPad5")
- touches.Add(50, "NumPad6")
- touches.Add(51, "NumPad7")
- touches.Add(52, "NumPad8")
- touches.Add(53, "NumPad9")
- touches.Add(54, "NumLock")
- End If
- End If
-
- End Sub
-
- Private Function getMode() As Integer
- Dim lemode As Integer = 1
- If R1.Checked Then
- lemode = 1
- ElseIf R2.Checked Then
- lemode = 2
- ElseIf R3.Checked Then
- lemode = 3
- End If
- Return lemode
- End Function
-
- Private Sub Demarrer()
- time = duree
- score = 0
- Label2.Text = "Time : " & duree & "s"
- Label3.Text = "Score : 0"
- Timer.Start()
- encours = True
- While time > 0
- Application.DoEvents()
- If trouve Then
- Randomize()
- rndTouche = CInt(Int((touches.Count * Rnd()) + 1))
- trouve = False
- Label1.Text = touches(rndTouche).ToString
- End If
- End While
- Timer.Stop()
- encours = False
- trouve = True
- Label1.Text = "Ready ?"
-
- End Sub
-
- Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
- time = time - 0.1
- If time < 0 Then time = 0
- Label2.Text = "Time : " & CSng(CInt(time * 10)) / 10 & "s"
- End Sub
-
- Private Sub Arreter()
- time = 0
- End Sub
-
- Private Sub R1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles R1.CheckedChanged
- If R1.Checked Then
- initialisation()
- End If
- End Sub
-
- Private Sub R2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles R2.CheckedChanged
- If R2.Checked Then
- initialisation()
- End If
- End Sub
-
- Private Sub R3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles R3.CheckedChanged
- If R3.Checked Then
- initialisation()
- End If
- End Sub
-
- Private Sub Main_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
- Me.Focus()
- End Sub
- End Class
'Auteur : Gabriel Hautclocq
'
Public Class Main
Private touches As New Hashtable()
Private time As Single
Private score As Integer
Private rndTouche As Integer
Private trouve As Boolean = True
Private encours As Boolean = False
Private mode As Integer
Private Const duree As Single = 30
Private Sub Main_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Arreter()
End Sub
Private Sub Main_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If Not encours Then
Demarrer()
Else
Arreter()
End If
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
If Not encours Then
Demarrer()
Else
Arreter()
End If
End Sub
Private Sub Main_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If encours Then
If e.KeyData.ToString() = touches(rndTouche) Then
trouve = True
score = score + 1
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
Else
score = score - 1
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)
End If
Label3.Text = "Score : " & score
Else
If e.KeyData = Keys.Enter Or e.KeyData = Keys.Return Then
Demarrer()
End If
End If
End Sub
Private Sub initialisation()
touches.Clear()
Dim currentMode As Integer = getMode()
'Mode de base
touches.Add(1, "A")
touches.Add(2, "B")
touches.Add(3, "C")
touches.Add(4, "D")
touches.Add(5, "E")
touches.Add(6, "F")
touches.Add(7, "G")
touches.Add(8, "H")
touches.Add(9, "I")
touches.Add(10, "J")
touches.Add(11, "K")
touches.Add(12, "L")
touches.Add(13, "M")
touches.Add(14, "N")
touches.Add(15, "O")
touches.Add(16, "P")
touches.Add(17, "Q")
touches.Add(18, "R")
touches.Add(19, "S")
touches.Add(20, "T")
touches.Add(21, "U")
touches.Add(22, "V")
touches.Add(23, "W")
touches.Add(24, "X")
touches.Add(25, "Y")
touches.Add(26, "Z")
touches.Add(27, "Space")
If currentMode > 1 Then 'Mode Laptop
touches.Add(28, "F1")
touches.Add(29, "F2")
touches.Add(30, "F3")
touches.Add(31, "F4")
touches.Add(32, "F5")
touches.Add(33, "F6")
touches.Add(34, "F7")
touches.Add(35, "F8")
touches.Add(36, "F9")
touches.Add(37, "F10")
touches.Add(38, "F11")
touches.Add(39, "F12")
touches.Add(40, "Up")
touches.Add(41, "Down")
touches.Add(42, "Left")
touches.Add(43, "Right")
If currentMode > 2 Then 'Mode Expert
touches.Add(44, "NumPad0")
touches.Add(45, "NumPad1")
touches.Add(46, "NumPad2")
touches.Add(47, "NumPad3")
touches.Add(48, "NumPad4")
touches.Add(49, "NumPad5")
touches.Add(50, "NumPad6")
touches.Add(51, "NumPad7")
touches.Add(52, "NumPad8")
touches.Add(53, "NumPad9")
touches.Add(54, "NumLock")
End If
End If
End Sub
Private Function getMode() As Integer
Dim lemode As Integer = 1
If R1.Checked Then
lemode = 1
ElseIf R2.Checked Then
lemode = 2
ElseIf R3.Checked Then
lemode = 3
End If
Return lemode
End Function
Private Sub Demarrer()
time = duree
score = 0
Label2.Text = "Time : " & duree & "s"
Label3.Text = "Score : 0"
Timer.Start()
encours = True
While time > 0
Application.DoEvents()
If trouve Then
Randomize()
rndTouche = CInt(Int((touches.Count * Rnd()) + 1))
trouve = False
Label1.Text = touches(rndTouche).ToString
End If
End While
Timer.Stop()
encours = False
trouve = True
Label1.Text = "Ready ?"
End Sub
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
time = time - 0.1
If time < 0 Then time = 0
Label2.Text = "Time : " & CSng(CInt(time * 10)) / 10 & "s"
End Sub
Private Sub Arreter()
time = 0
End Sub
Private Sub R1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles R1.CheckedChanged
If R1.Checked Then
initialisation()
End If
End Sub
Private Sub R2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles R2.CheckedChanged
If R2.Checked Then
initialisation()
End If
End Sub
Private Sub R3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles R3.CheckedChanged
If R3.Checked Then
initialisation()
End If
End Sub
Private Sub Main_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
Me.Focus()
End Sub
End Class
Conclusion
Attention, ceci est un code .NET 2.0, donc veuillez à installer le Framework .NET 2.0 au préalable. Vous le trouverez en version finale ici : http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&DisplayLang=en
Attention à un petit bug : Lors de la compilation, il faut veiller à ce que les propriétés TabStop des boutons radio soit bien à false dans le fichier Main.Designer.vb Sinon, le programme ne réagira pas à l'appui des touches...
Ce jeu sera régulièrement mis à jour sur mon site : http://gabsoftware.free.fr
La prochaine version sauvegardera les meilleurs scores et, j'espère, supprimera le petit bug cité ci-dessus :)
Fichier Zip
Sources de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | | | 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|