Advertisement
Guest User

Listing Program Game PUZZLE

a guest
Oct 30th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.61 KB | None | 0 0
  1. Public Class Form1
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         Kode_randomisasi()
  5.     End Sub
  6.  
  7.     Private Sub Kode_randomisasi()
  8.         Dim control As Windows.Forms.Control
  9.         For Each control In Me.Controls
  10.             If control.GetType.Name = "Button" Then
  11.                 Dim rndnumber As Random
  12.                 rndnumber = New Random
  13.                 Dim number As Integer
  14.                 control.Text = number
  15.  
  16.                 number = rndnumber.Next(1, 10)
  17.                 Bt1.Text = number
  18.  
  19.                 If Bt2.Text = Bt1.Text Then
  20.                     Do
  21.                         number = rndnumber.Next(1, 10)
  22.                         Bt2.Text = number
  23.                     Loop Until Bt2.Text <> Bt1.Text
  24.                 End If
  25.  
  26.                 If Bt3.Text = Bt2.Text Or Bt3.Text = Bt1.Text Then
  27.                     Do
  28.                         number = rndnumber.Next(1, 10)
  29.                         Bt3.Text = number
  30.                     Loop Until Bt3.Text <> Bt2.Text And Bt3.Text <> Bt1.Text
  31.                 End If
  32.  
  33.                 If Bt4.Text = Bt3.Text Or Bt4.Text = Bt2.Text Or Bt4.Text = Bt1.Text Then
  34.                     Do
  35.                         number = rndnumber.Next(1, 10)
  36.                         Bt4.Text = number
  37.                     Loop Until Bt4.Text <> Bt3.Text And Bt4.Text <> Bt2.Text And Bt4.Text <> Bt1.Text
  38.                 End If
  39.  
  40.                 If Bt5.Text = Bt4.Text Or Bt5.Text = Bt3.Text Or Bt5.Text = Bt2.Text Or Bt5.Text = Bt1.Text Then
  41.                     Do
  42.                         number = rndnumber.Next(1, 10)
  43.                         Bt5.Text = number
  44.                     Loop Until Bt5.Text <> Bt4.Text And Bt5.Text <> Bt3.Text And Bt5.Text <> Bt2.Text And Bt5.Text <> Bt1.Text
  45.                 End If
  46.  
  47.                 If Bt6.Text = Bt5.Text Or Bt6.Text = Bt4.Text Or Bt6.Text = Bt3.Text Or Bt6.Text = Bt2.Text Or Bt6.Text = Bt1.Text Then
  48.                     Do
  49.                         number = rndnumber.Next(1, 10)
  50.                         Bt6.Text = number
  51.                     Loop Until Bt6.Text <> Bt5.Text And Bt6.Text <> Bt4.Text And Bt6.Text <> Bt3.Text And Bt6.Text <> Bt2.Text And Bt6.Text <> Bt1.Text
  52.                 End If
  53.  
  54.                 If Bt7.Text = Bt6.Text Or Bt7.Text = Bt5.Text Or Bt7.Text = Bt4.Text Or Bt7.Text = Bt3.Text Or Bt7.Text = Bt2.Text Or Bt7.Text = Bt1.Text Then
  55.                     Do
  56.                         number = rndnumber.Next(1, 10)
  57.                         Bt7.Text = number
  58.                     Loop Until Bt7.Text <> Bt6.Text And Bt7.Text <> Bt5.Text And Bt7.Text <> Bt4.Text And Bt7.Text <> Bt3.Text And Bt7.Text <> Bt2.Text And Bt7.Text <> Bt1.Text
  59.                 End If
  60.  
  61.                 If Bt8.Text = Bt7.Text Or Bt8.Text = Bt6.Text Or Bt8.Text = Bt5.Text Or Bt8.Text = Bt4.Text Or Bt8.Text = Bt3.Text Or Bt8.Text = Bt2.Text Or Bt8.Text = Bt1.Text Then
  62.                     Do
  63.                         number = rndnumber.Next(1, 10)
  64.                         Bt8.Text = number
  65.                     Loop Until Bt8.Text <> Bt7.Text And Bt8.Text <> Bt6.Text And Bt8.Text <> Bt5.Text And Bt8.Text <> Bt4.Text And Bt8.Text <> Bt3.Text And Bt8.Text <> Bt2.Text And Bt8.Text <> Bt1.Text
  66.                 End If
  67.  
  68.                 If Bt9.Text = Bt8.Text Or Bt9.Text = Bt7.Text Or Bt9.Text = Bt6.Text Or Bt9.Text = Bt5.Text Or Bt9.Text = Bt4.Text Or Bt9.Text = Bt3.Text Or Bt9.Text = Bt2.Text Or Bt9.Text = Bt1.Text Then
  69.                     Do
  70.                         number = rndnumber.Next(1, 10)
  71.                         Bt9.Text = number
  72.                     Loop Until Bt9.Text <> Bt8.Text And Bt9.Text <> Bt7.Text And Bt9.Text <> Bt6.Text And Bt9.Text <> Bt5.Text And Bt9.Text <> Bt4.Text And Bt9.Text <> Bt3.Text And Bt9.Text <> Bt2.Text And Bt9.Text <> Bt1.Text
  73.                 End If
  74.             End If
  75.         Next
  76.  
  77.         Btacak.Text = "Acak Angka"
  78.  
  79.         If Bt1.Text = "9" Then
  80.             Bt1.Text = ""
  81.         End If
  82.         If Bt2.Text = "9" Then
  83.             Bt2.Text = ""
  84.         End If
  85.         If Bt3.Text = "9" Then
  86.             Bt3.Text = ""
  87.         End If
  88.         If Bt4.Text = "9" Then
  89.             Bt4.Text = ""
  90.         End If
  91.         If Bt5.Text = "9" Then
  92.             Bt5.Text = ""
  93.         End If
  94.         If Bt6.Text = "9" Then
  95.             Bt6.Text = ""
  96.         End If
  97.         If Bt7.Text = "9" Then
  98.             Bt7.Text = ""
  99.         End If
  100.         If Bt8.Text = "9" Then
  101.             Bt8.Text = ""
  102.         End If
  103.         If Bt9.Text = "9" Then
  104.             Bt9.Text = ""
  105.         End If
  106.  
  107.     End Sub
  108.  
  109.     Private Sub Bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt1.Click
  110.         If Bt2.Text = "" Then
  111.             Bt2.Text = Bt1.Text
  112.             Bt1.Text = ""
  113.         ElseIf Bt4.Text = "" Then
  114.             Bt4.Text = Bt1.Text
  115.             Bt1.Text = ""
  116.         End If
  117.         Berhasil()
  118.     End Sub
  119.  
  120.     Private Sub Bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt2.Click
  121.         If Bt1.Text = "" Then
  122.             Bt1.Text = Bt2.Text
  123.             Bt2.Text = ""
  124.         ElseIf Bt3.Text = "" Then
  125.             Bt3.Text = Bt2.Text
  126.             Bt2.Text = ""
  127.         ElseIf Bt5.Text = "" Then
  128.             Bt5.Text = Bt2.Text
  129.             Bt2.Text = ""
  130.         End If
  131.         Berhasil()
  132.     End Sub
  133.  
  134.     Private Sub Bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt3.Click
  135.         If Bt2.Text = "" Then
  136.             Bt2.Text = Bt3.Text
  137.             Bt3.Text = ""
  138.         ElseIf Bt6.Text = "" Then
  139.             Bt6.Text = Bt3.Text
  140.             Bt3.Text = ""
  141.         End If
  142.         Berhasil()
  143.     End Sub
  144.  
  145.     Private Sub Bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt4.Click
  146.         If Bt1.Text = "" Then
  147.             Bt1.Text = Bt4.Text
  148.             Bt4.Text = ""
  149.         ElseIf Bt5.Text = "" Then
  150.             Bt5.Text = Bt4.Text
  151.             Bt4.Text = ""
  152.         ElseIf Bt7.Text = "" Then
  153.             Bt7.Text = Bt4.Text
  154.             Bt4.Text = ""
  155.         End If
  156.         Berhasil()
  157.     End Sub
  158.  
  159.     Private Sub Bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt5.Click
  160.         If Bt2.Text = "" Then
  161.             Bt2.Text = Bt5.Text
  162.             Bt5.Text = ""
  163.         ElseIf Bt4.Text = "" Then
  164.             Bt4.Text = Bt5.Text
  165.             Bt5.Text = ""
  166.         ElseIf Bt6.Text = "" Then
  167.             Bt6.Text = Bt5.Text
  168.             Bt5.Text = ""
  169.         ElseIf Bt8.Text = "" Then
  170.             Bt8.Text = Bt5.Text
  171.             Bt5.Text = ""
  172.         End If
  173.         Berhasil()
  174.     End Sub
  175.  
  176.     Private Sub Bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt6.Click
  177.         If Bt3.Text = "" Then
  178.             Bt3.Text = Bt6.Text
  179.             Bt6.Text = ""
  180.         ElseIf Bt5.Text = "" Then
  181.             Bt5.Text = Bt6.Text
  182.             Bt6.Text = ""
  183.         ElseIf Bt9.Text = "" Then
  184.             Bt9.Text = Bt6.Text
  185.             Bt6.Text = ""
  186.         End If
  187.         Berhasil()
  188.     End Sub
  189.  
  190.     Private Sub Bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt7.Click
  191.         If Bt4.Text = "" Then
  192.             Bt4.Text = Bt7.Text
  193.             Bt7.Text = ""
  194.         ElseIf Bt8.Text = "" Then
  195.             Bt8.Text = Bt7.Text
  196.             Bt7.Text = ""
  197.         End If
  198.         Berhasil()
  199.     End Sub
  200.  
  201.     Private Sub Bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt8.Click
  202.         If Bt5.Text = "" Then
  203.             Bt5.Text = Bt8.Text
  204.             Bt8.Text = ""
  205.         ElseIf Bt7.Text = "" Then
  206.             Bt7.Text = Bt8.Text
  207.             Bt8.Text = ""
  208.         ElseIf Bt9.Text = "" Then
  209.             Bt9.Text = Bt8.Text
  210.             Bt8.Text = ""
  211.         End If
  212.         Berhasil()
  213.     End Sub
  214.  
  215.     Private Sub Bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt9.Click
  216.         If Bt6.Text = "" Then
  217.             Bt6.Text = Bt9.Text
  218.             Bt9.Text = ""
  219.         ElseIf Bt8.Text = "" Then
  220.             Bt8.Text = Bt9.Text
  221.             Bt9.Text = ""
  222.         End If
  223.         Berhasil()
  224.     End Sub
  225.  
  226.     Private Sub Berhasil()
  227.         If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "" Then
  228.             MessageBox.Show("Selamat Anda Berhasil")
  229.         End If
  230.     End Sub
  231.  
  232.     Private Sub Btacak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btacak.Click
  233.         Kode_randomisasi()
  234.     End Sub
  235.  
  236. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement