لطفا كد پازل 8 رو برام توضيح بديد
سالم لطفا كد بازي پازل رو كه مي بينيد برام توضيح بديد. اگه بصورت خط به خط باشه كه ديگه واقعا ممنونتونم.. مرسي
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace hamishebahar
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private MainB() As Button
Private Sub Btn_Sakht_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_Sakht.Click
MainB = New Button(Convert.ToInt32(3) * Convert.ToInt32(3) - 1) {}
Dim x As Integer = 3, y As Integer = 3, C As Integer = 0
For I As Integer = 0 To MainB.Length - 1
MainB(I) = New Button()
MainB(I).Font.Size(10)
MainB(I).Size = New Size(40, 33)
MainB(I).Location = New Point(x, y)
MainB(I).Text = ""
AddHandler MainB(I).Click, AddressOf Btns_Click
MainB(I).Tag = I.ToString()
x += 39
If x = Convert.ToInt32(3) * 39 + 3 Then
x = 3
y += 32
End If
If I = MainB.Length - 1 Then
MainB(I).Text = ""
End If
Me.Controls.Add(MainB(I))
Next I
Dim add As Boolean = True
Do
Dim RDM As New Random()
Dim Mrdm As Integer = RDM.Next(1, MainB.Length)
add = True
For I As Integer = 0 To MainB.Length - 1
If MainB(I).Text = Mrdm.ToString() Then
add = False
Exit For
End If
Next I
If add = True Then
MainB(C).Text = Mrdm.ToString()
C += 1
If C = MainB.Length - 1 Then
Exit Do
End If
End If
Loop
End Sub
Private Function RETMB(ByVal BTNIndex As Integer) As Button()
Dim RET(3) As Button
Try
If MainB(BTNIndex).Top = MainB(BTNIndex - 1).Top Then
RET(0) = MainB(BTNIndex - 1)
End If
Catch e1 As Exception
End Try
Try
If MainB(BTNIndex).Top = MainB(BTNIndex + 1).Top Then
RET(1) = MainB(BTNIndex + 1)
End If
Catch e2 As Exception
End Try
Try
If MainB(BTNIndex).Left = MainB(BTNIndex + Convert.ToInt32(3)).Left Then
RET(2) = MainB(BTNIndex + Convert.ToInt32(3))
End If
Catch e3 As Exception
End Try
Try
If MainB(BTNIndex).Left = MainB(BTNIndex - Convert.ToInt32(3)).Left Then
RET(3) = MainB(BTNIndex - Convert.ToInt32(3))
End If
Catch e4 As Exception
End Try
Return RET
End Function
Private Sub Btns_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim M As Button = CType(sender, Button)
Dim Anjam As Boolean = False
If RETMB(Convert.ToInt32(M.Tag))(0) IsNot Nothing Then
If RETMB(Convert.ToInt32(M.Tag))(0).Text = "" Then
RETMB(Convert.ToInt32(M.Tag))(0).Text = M.Text
M.Text = ""
Anjam = True
End If
End If
If RETMB(Convert.ToInt32(M.Tag))(1) IsNot Nothing AndAlso Anjam = False Then
If RETMB(Convert.ToInt32(M.Tag))(1).Text = "" Then
RETMB(Convert.ToInt32(M.Tag))(1).Text = M.Text
M.Text = ""
Anjam = True
End If
End If
If RETMB(Convert.ToInt32(M.Tag))(2) IsNot Nothing AndAlso Anjam = False Then
If RETMB(Convert.ToInt32(M.Tag))(2).Text = "" Then
RETMB(Convert.ToInt32(M.Tag))(2).Text = M.Text
M.Text = ""
Anjam = True
End If
End If
If RETMB(Convert.ToInt32(M.Tag))(3) IsNot Nothing AndAlso Anjam = False Then
If RETMB(Convert.ToInt32(M.Tag))(3).Text = "" Then
RETMB(Convert.ToInt32(M.Tag))(3).Text = M.Text
M.Text = ""
Anjam = True
End If
End If
CHECKBarandeh()
End Sub
Private Sub CHECKBarandeh()
Dim Pirozi As Boolean = False
For I As Integer = 0 To MainB.Length - 2
If MainB(I).Text = MainB(I + 1).Tag.ToString() Then
Pirozi = True
Else
Pirozi = False
Exit For
End If
Next I
If Pirozi Then
MessageBox.Show("شما برنده شدید")
End If
End Sub
End Class
End Namespace
|