Batch Index du Forum
S’enregistrerRechercherFAQMembresGroupesConnexion
Répondre au sujet Page 1 sur 1
[VB.NET] [Jeux] Tic-Tac-Toe
Auteur Message
Répondre en citant
Message [VB.NET] [Jeux] Tic-Tac-Toe 
Salut tout le monde !

Je sais que je n'ai pas beaucoup partagé dernièrement mais j'ai beaucoup programmé durant mon absence !
Je commence en force avec un jeu, le tic-tac-toe ! Avec une belle interface et plusieurs fonctionnalitées !

Informations sur la programmation :

- Programmé en : Visual Basic.NET sur Microsoft Visual Basic 2010 Express sous Windows XP SP3

- Nécessite : Microsoft.NET Framework Version je-ne-sais-plus-quelle...

- Contient : 2 Form, 13 boutons, 9 labels et beaucoup de conditions !

- Taille : 835 Ko

Idée originale de Yunsst mais je l'ai beaucoup adapté... ( https://www.youtube.com/user/YunSST/videos )

Attention le code est long !

Code:
'Créé par MrSolotek22
'Ne pas modifier ou distribuer sans autorisation
'© - Copyright - 2013

Public Class Form1

    Dim son = New System.Media.SoundPlayer(My.Resources.Triangle)
    Dim son2 = New System.Media.SoundPlayer(My.Resources.Reset)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Label4.Text = "X" Then
            Button1.Text = "X"
            Label4.Text = "O"
        Else
            Button1.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button1.Enabled = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Label4.Text = "X" Then
            Button2.Text = "X"
            Label4.Text = "O"
        Else
            Button2.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button2.Enabled = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Label4.Text = "X" Then
            Button3.Text = "X"
            Label4.Text = "O"
        Else
            Button3.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button3.Enabled = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Label4.Text = "X" Then
            Button4.Text = "X"
            Label4.Text = "O"
        Else
            Button4.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button4.Enabled = False
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Label4.Text = "X" Then
            Button5.Text = "X"
            Label4.Text = "O"
        Else
            Button5.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button5.Enabled = False
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Label4.Text = "X" Then
            Button6.Text = "X"
            Label4.Text = "O"
        Else
            Button6.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button6.Enabled = False
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Label4.Text = "X" Then
            Button8.Text = "X"
            Label4.Text = "O"
        Else
            Button8.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button8.Enabled = False
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Label4.Text = "X" Then
            Button7.Text = "X"
            Label4.Text = "O"
        Else
            Button7.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button7.Enabled = False
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Label4.Text = "X" Then
            Button9.Text = "X"
            Label4.Text = "O"
        Else
            Button9.Text = "O"
            Label4.Text = "X"
        End If
        Call Win()
        Button9.Enabled = False
    End Sub

    Private Sub Win()
        Dim b1 As String = Button1.Text
        Dim b2 As String = Button2.Text
        Dim b3 As String = Button3.Text
        Dim b4 As String = Button4.Text
        Dim b5 As String = Button5.Text
        Dim b6 As String = Button6.Text
        Dim b7 As String = Button7.Text
        Dim b8 As String = Button8.Text
        Dim b9 As String = Button9.Text
        If b1 = b2 And b2 = b3 And b1 <> "" Then
            winner.Text = b1 + " win"
            son.play()
            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False

            Button1.BackColor = Color.Blue
            Button2.BackColor = Color.Blue
            Button3.BackColor = Color.Blue

            If b1 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b4 = b5 And b5 = b6 And b4 <> "" Then
            winner.Text = b4 + " win"
            son.play()
            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False

            Button4.BackColor = Color.Blue
            Button5.BackColor = Color.Blue
            Button6.BackColor = Color.Blue

            If b4 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b7 = b8 And b8 = b9 And b7 <> "" Then
            winner.Text = b7 + " win"
            son.play()
            Button7.BackColor = Color.Blue
            Button8.BackColor = Color.Blue
            Button9.BackColor = Color.Blue

            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False
            If b7 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b1 = b4 And b4 = b7 And b1 <> "" Then
            winner.Text = b1 + " win"
            son.play()
            Button1.BackColor = Color.Blue
            Button4.BackColor = Color.Blue
            Button7.BackColor = Color.Blue

            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False
            If b1 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b2 = b5 And b5 = b8 And b2 <> "" Then
            winner.Text = b2 + " win"
            son.play()
            Button2.BackColor = Color.Blue
            Button5.BackColor = Color.Blue
            Button8.BackColor = Color.Blue

            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False

            If b2 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b3 = b6 And b6 = b9 And b3 <> "" Then
            winner.Text = b3 + " win"
            son.play()
            Button3.BackColor = Color.Blue
            Button6.BackColor = Color.Blue
            Button9.BackColor = Color.Blue

            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False

            If b3 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b1 = b5 And b5 = b9 And b1 <> "" Then
            winner.Text = b1 + " win"
            son.play()
            Button1.BackColor = Color.Blue
            Button5.BackColor = Color.Blue
            Button9.BackColor = Color.Blue

            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False
            If b1 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        ElseIf b3 = b5 And b5 = b7 And b3 <> "" Then
            winner.Text = b3 + " win"
            son.play()
            Button3.BackColor = Color.Blue
            Button5.BackColor = Color.Blue
            Button7.BackColor = Color.Blue

            Button1.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Enabled = False
            Button5.Enabled = False
            Button6.Enabled = False
            Button7.Enabled = False
            Button8.Enabled = False
            Button9.Enabled = False

            If b3 = "X" Then
                XWin.Text = Int(XWin.Text) + 1
            Else
                OWin.Text = Int(OWin.Text) + 1
            End If
        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        son2.play()
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        Button7.Enabled = True
        Button8.Enabled = True
        Button9.Enabled = True
        Button1.BackColor = Color.Transparent
        Button2.BackColor = Color.Transparent
        Button3.BackColor = Color.Transparent
        Button4.BackColor = Color.Transparent
        Button5.BackColor = Color.Transparent
        Button6.BackColor = Color.Transparent
        Button7.BackColor = Color.Transparent
        Button8.BackColor = Color.Transparent
        Button9.BackColor = Color.Transparent
        winner.Text = ""
        Button1.Text = ""
        Button2.Text = ""
        Button3.Text = ""
        Button4.Text = ""
        Button5.Text = ""
        Button6.Text = ""
        Button7.Text = ""
        Button8.Text = ""
        Button9.Text = ""
        nbrgames.Text = Int(nbrgames.Text) + 1
        winner.Text = ""
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        MsgBox("Merci d'avoir joué !")
        Me.Close()
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Form2.Show()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.NotifyIcon1.ShowBalloonTip(6000, "© - Copyright - 2013", "Créé par MrSolotek22.  Bon jeu !", ToolTipIcon.Info)
    End Sub
End Class


Code:
Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r As New Random
        Label1.Text = r.Next(1, 5)
        If Label1.Text = "1" Then
            Label1.Text = "X"
        ElseIf Label1.Text = "2" Then
            Label1.Text = "O"
        ElseIf Label1.Text = "3" Then
            Label1.Text = "X"
        ElseIf Label1.Text = "4" Then
            Label1.Text = "O"
        ElseIf Label1.Text = "5" Then
            Label1.Text = "X"
        End If

        Button1.Visible = False
        Button2.Visible = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
        Form1.Focus()
    End Sub
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form1.Opacity = 50 / 100
    End Sub

    Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Form1.Opacity = 100 / 100
    End Sub
End Class







Je pense que c'est assez complet,

Merci d'avoir lu,

MrSolotek22



Visiter le site web du posteur Skype
Message Publicité 
PublicitéSupprimer les publicités ?


Montrer les messages depuis:
Répondre au sujet Page 1 sur 1
  



Index | créer un forum | Forum gratuit d’entraide | Annuaire des forums gratuits | Signaler une violation | Conditions générales d'utilisation
Copyright 2008 - 2016 // Batch