سورس کد بازی XO در ویژوال بیسیک NET.

سورس بازی XO در ویژوال بیسیک.. برای دانلود پروژه به ادامه مطلب بروید

 

image

[ddownload id=”2129″ style=”button” button=”grey”]

توضیحات بازی : قانون بازی XO بسیار ساده است، هدف بازی پر کردن 3 خانه در راستاری افقی، عمودی و یا قطر های جدول 9 خانه ای بالا می باشد، این بازی تمرین خوبی برای بالا بردن سرعت و دقت شماست.

 

هر گونه سوالی یا نظری در مورد این سورس کد دارید می توانید در قسمت نظرات سوال خود را بپرسید

برنامه نویس این کد : امیرمحسن کسایی

انتشار دهنده : امیرمحسن کسایی

 

Public Class Form1
    ' X-O GAME 
    ' Progerammer : Amir Mohsen Kasaee
    ' AmirMohsen_kasaee@hotmail.com
    ' Samiantec.ir
    Friend x, m, d, y As Integer
    Friend a(0 To 8) As String
    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox5.Image = xogame.My.Resources.x
            a(4) = "x"
            PictureBox5.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox5.Image = xogame.My.Resources.o
            a(4) = "o"
            PictureBox5.Enabled = False
        End If
        checkgame()
    End Sub
    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox4.Image = xogame.My.Resources.x
            a(5) = "x"
            PictureBox4.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox4.Image = xogame.My.Resources.o
            PictureBox4.Enabled = False
            a(5) = "o"
        End If
        checkgame()
    End Sub
    Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox9.Image = xogame.My.Resources.x
            a(6) = "x"
            PictureBox9.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox9.Image = xogame.My.Resources.o
            a(6) = "o"
            PictureBox9.Enabled = False
        End If
        checkgame()
    End Sub
    Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox8.Image = xogame.My.Resources.x
            a(7) = "x"
            PictureBox8.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox8.Image = xogame.My.Resources.o
            PictureBox8.Enabled = False
            a(7) = "o"
        End If
        checkgame()
    End Sub
    Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox7.Image = xogame.My.Resources.x
            a(8) = "x"
            PictureBox7.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox7.Image = xogame.My.Resources.o
            a(8) = "o"
            PictureBox7.Enabled = False
        End If
        checkgame()
    End Sub
    Function checknumber(ByVal x As Integer) As String
        Dim s As Integer
        s = x / 2
        If x = s * 2 Then
            Return "Z"
        Else
            Return "F"
        End If
    End Function
    Sub checkgame()
        If (a(2) = a(4) And a(2) = a(6) And a(4) = a(6)) Then
            If a(2) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(2) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If

        If a(3) = a(4) And a(4) = a(5) And a(3) = a(5) Then
            If a(5) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(5) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If

        If a(2) = a(5) And a(2) = a(8) And a(5) = a(8) Then
            If a(2) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(2) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If
        If a(1) = a(4) And a(1) = a(7) And a(4) = a(7) Then
            If a(1) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(1) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If
        If (a(6) = a(7) And a(8) = a(6) And a(8) = a(7)) Then
            If a(7) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(7) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If
        If (a(0) = a(2) And a(0) = a(1) And a(1) = a(2)) Then
            If a(0) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(0) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If
        If (a(0) = a(3) And a(0) = a(6) And a(3) = a(6)) Then
            If a(0) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(0) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If
        If (a(0) = a(4) And a(0) = a(8) And a(4) = a(8)) Then
            If a(0) = "o" Then
                m = m + 1
                Label4.Text = Str(m)
                Label6.Text = Label2.Text
                endgame()
            ElseIf a(0) = "x" Then
                d = d + 1
                Label3.Text = Str(d)
                Label6.Text = Label1.Text
                endgame()
            End If
        End If
        If y = Val(Label7.Text) And x = 9 Then
            MsgBox("Equal")
            endgame()
        End If
    End Sub
    Sub endgame()
        Dim result As Integer = MessageBox.Show("End Game.... NEXT RUN", "XO game", MessageBoxButtons.OK)
        If result = DialogResult.OK Then
            PictureBox1.Image = My.Resources.w
            PictureBox2.Image = My.Resources.w
            PictureBox3.Image = My.Resources.w
            PictureBox4.Image = My.Resources.w
            PictureBox5.Image = My.Resources.w
            PictureBox6.Image = My.Resources.w
            PictureBox7.Image = My.Resources.w
            PictureBox8.Image = My.Resources.w
            PictureBox9.Image = My.Resources.w
            PictureBox1.Enabled = True
            PictureBox2.Enabled = True
            PictureBox3.Enabled = True
            PictureBox4.Enabled = True
            PictureBox5.Enabled = True
            PictureBox6.Enabled = True
            PictureBox7.Enabled = True
            PictureBox8.Enabled = True
            PictureBox9.Enabled = True
            Label6.Text = " "
            x = 0
            y = y + 1
            Label7.Text = Str(y)
            For i = 0 To 8
                a(i) = ""
            Next
        End If
    End Sub
    Sub game()
        If a(0) = "o" Then
            m = m + 1
            Label4.Text = Str(m)
            Label6.Text = Label2.Text
            endgame()
        ElseIf a(0) = "x" Then
            d = d + 1
            Label3.Text = Str(d)
            Label6.Text = Label1.Text
            endgame()
        End If
    End Sub

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



    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1.Image = My.Resources.w
        PictureBox2.Image = My.Resources.w
        PictureBox3.Image = My.Resources.w
        PictureBox4.Image = My.Resources.w
        PictureBox5.Image = My.Resources.w
        PictureBox6.Image = My.Resources.w
        PictureBox7.Image = My.Resources.w
        PictureBox8.Image = My.Resources.w
        PictureBox9.Image = My.Resources.w
        PictureBox1.Enabled = True
        PictureBox2.Enabled = True
        PictureBox3.Enabled = True
        PictureBox4.Enabled = True
        PictureBox5.Enabled = True
        PictureBox6.Enabled = True
        PictureBox7.Enabled = True
        PictureBox8.Enabled = True
        PictureBox9.Enabled = True
        x = 0
        y = 0
        m = 0
        d = 0
        Label7.Text = Str(y)
        Label3.Text = ""
        Label4.Text = ""
        For i = 0 To 8
            a(i) = ""
        Next
    End Sub

    Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.Click
        Process.Start("iexplore.exe", "Samiantec.ir")
    End Sub

    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox6.Image = xogame.My.Resources.x
            a(3) = "x"
            PictureBox6.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox6.Image = xogame.My.Resources.o
            PictureBox6.Enabled = False
            a(3) = "o"
        End If
        checkgame()
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox1.Image = xogame.My.Resources.x
            PictureBox1.Enabled = False
            a(0) = "x"
        ElseIf checknumber(x) = "Z" Then
            PictureBox1.Image = xogame.My.Resources.o
            a(0) = "o"
            PictureBox1.Enabled = False
        End If
        checkgame()
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox2.Image = xogame.My.Resources.x
            a(1) = "x"
            PictureBox2.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox2.Image = xogame.My.Resources.o
            a(1) = "o"
            PictureBox2.Enabled = False
        End If
        checkgame()
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        x = x + 1
        If checknumber(x) = "F" Then
            PictureBox3.Image = xogame.My.Resources.x
            a(2) = "x"
            PictureBox3.Enabled = False
        ElseIf checknumber(x) = "Z" Then
            PictureBox3.Image = xogame.My.Resources.o
            a(2) = "o"
            PictureBox3.Enabled = False
        End If
        checkgame()
    End Sub
End Class



 

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *




Enter Captcha Here :