home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / TB-Sensor2053563132007.psc / Form1.frm < prev    next >
Text File  |  2007-03-13  |  12KB  |  432 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   4320
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   3420
  8.    Icon            =   "Form1.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4320
  11.    ScaleWidth      =   3420
  12.    StartUpPosition =   2  'Bildschirmmitte
  13.    Begin VB.Timer Timer5 
  14.       Left            =   240
  15.       Top             =   3480
  16.    End
  17.    Begin VB.CheckBox Check1 
  18.       Caption         =   "Check1"
  19.       Height          =   255
  20.       Left            =   2280
  21.       TabIndex        =   8
  22.       Top             =   3480
  23.       Width           =   255
  24.    End
  25.    Begin VB.Timer Timer4 
  26.       Left            =   720
  27.       Top             =   3000
  28.    End
  29.    Begin VB.Timer Timer3 
  30.       Left            =   720
  31.       Top             =   2520
  32.    End
  33.    Begin VB.CommandButton Command2 
  34.       Caption         =   "Command2"
  35.       Height          =   255
  36.       Left            =   1200
  37.       TabIndex        =   5
  38.       Top             =   3960
  39.       Width           =   975
  40.    End
  41.    Begin VB.Timer Timer2 
  42.       Left            =   240
  43.       Top             =   3000
  44.    End
  45.    Begin VB.Timer Timer1 
  46.       Left            =   240
  47.       Top             =   2520
  48.    End
  49.    Begin VB.CommandButton Command1 
  50.       Caption         =   "Command1"
  51.       Height          =   495
  52.       Left            =   1200
  53.       TabIndex        =   4
  54.       Top             =   3240
  55.       Width           =   975
  56.    End
  57.    Begin VB.PictureBox Picture1 
  58.       BackColor       =   &H0000FFFF&
  59.       Height          =   1095
  60.       Index           =   2
  61.       Left            =   1680
  62.       ScaleHeight     =   1035
  63.       ScaleWidth      =   1275
  64.       TabIndex        =   2
  65.       Top             =   1320
  66.       Width           =   1335
  67.    End
  68.    Begin VB.PictureBox Picture1 
  69.       BackColor       =   &H0000FF00&
  70.       Height          =   1095
  71.       Index           =   1
  72.       Left            =   1680
  73.       ScaleHeight     =   1035
  74.       ScaleWidth      =   1275
  75.       TabIndex        =   1
  76.       Top             =   240
  77.       Width           =   1335
  78.    End
  79.    Begin VB.PictureBox Picture1 
  80.       BackColor       =   &H00FF0000&
  81.       Height          =   1095
  82.       Index           =   0
  83.       Left            =   360
  84.       ScaleHeight     =   1035
  85.       ScaleWidth      =   1275
  86.       TabIndex        =   0
  87.       Top             =   240
  88.       Width           =   1335
  89.    End
  90.    Begin VB.PictureBox Picture1 
  91.       BackColor       =   &H000000FF&
  92.       Height          =   1095
  93.       Index           =   3
  94.       Left            =   360
  95.       ScaleHeight     =   1035
  96.       ScaleWidth      =   1275
  97.       TabIndex        =   3
  98.       Top             =   1320
  99.       Width           =   1335
  100.    End
  101.    Begin VB.Label Label3 
  102.       Caption         =   "Label3"
  103.       Height          =   255
  104.       Left            =   2280
  105.       TabIndex        =   9
  106.       Top             =   3240
  107.       Width           =   1815
  108.    End
  109.    Begin VB.Label Label2 
  110.       Caption         =   "Label2"
  111.       Height          =   495
  112.       Left            =   120
  113.       TabIndex        =   7
  114.       Top             =   2640
  115.       Width           =   3135
  116.    End
  117.    Begin VB.Label Label1 
  118.       Caption         =   "Label1"
  119.       Height          =   255
  120.       Left            =   360
  121.       TabIndex        =   6
  122.       Top             =   0
  123.       Width           =   2655
  124.    End
  125.    Begin VB.Image Image1 
  126.       Height          =   375
  127.       Left            =   0
  128.       Top             =   0
  129.       Width           =   135
  130.    End
  131. End
  132. Attribute VB_Name = "Form1"
  133. Attribute VB_GlobalNameSpace = False
  134. Attribute VB_Creatable = False
  135. Attribute VB_PredeclaredId = True
  136. Attribute VB_Exposed = False
  137. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" ( _
  138.     ByVal lpszName As String, _
  139.     ByVal hModule As Long, _
  140.     ByVal dwFlags As Long) As Long
  141.     
  142. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" ( _
  143.     ByVal lpszLongPath As String, _
  144.     ByVal lpszShortPath As _
  145.     String, _
  146.     ByVal cchBuffer As Long) As Long
  147.  
  148.  
  149.  
  150. Dim OldHeight       As Long
  151. Dim OldWidth        As Long
  152. Dim Merker          As String
  153. Dim MerkerOld       As String
  154. Dim MerkerAnswer    As String
  155. Dim Level           As Integer
  156. Dim MerkerPosition           As Integer
  157.  
  158.  
  159. Private Sub Command1_Click()
  160.     Call Start
  161. End Sub
  162.  
  163. Private Sub Start()
  164.     'Start next level
  165.     Timer5.Enabled = False
  166.     MerkerPosition = 0
  167.     Merker = CalculateMerker(Level, Picture1.UBound)
  168.     MerkerAnswer = ""
  169.     Command1.Enabled = False
  170.     Timer1.Interval = 600 - (Level * 10)
  171.     Timer1.Enabled = True
  172.     If Timer1.Interval - 160 > 0 Then Timer4.Interval = Timer1.Interval - 160
  173.     Label2.Caption = "Level " & Level
  174.  
  175. End Sub
  176.  
  177. Private Sub Command2_Click()
  178.     'Show the asked colors
  179.     Timer2.Enabled = True
  180. End Sub
  181.  
  182. Private Sub Form_Load()
  183.     'Set Defaults
  184.     Me.Caption = "TB-SENSOR, by Timo B÷hme - info@goldengel.ch V1.01"
  185.     Level = 1
  186.     Command1.Caption = "START"
  187.     Command2.Caption = "DEMO"
  188.     Timer2.Interval = "100"
  189.     Timer3.Enabled = False
  190.     Timer3.Interval = "1000"
  191.     Timer5.Enabled = False
  192.     Timer5.Interval = 5000
  193.     Label1.Visible = False
  194.     Label1.Alignment = 2
  195.     Label2.BackStyle = vbTransparent
  196.     Label2.Alignment = 2
  197.     Label2.Caption = "WELCOME TO SENSOR"
  198.     Label3.Caption = "Option append"
  199.     Label3.BackStyle = vbTransparent
  200.     Check1.Caption = ""
  201.     Check1.Value = 1
  202.     Image1.Stretch = True
  203.     Image1.Width = Me.Width
  204.     Image1.Height = Me.Height
  205.     If Dir(App.Path & "\sensor.jpg") <> "" Then Image1.Picture = LoadPicture(App.Path & "\sensor.jpg")
  206.     
  207.     'Because of resizing, we need the AutoRedraw methode
  208.     For i = 0 To Picture1.UBound
  209.         Picture1(i).AutoRedraw = True
  210.     Next
  211. End Sub
  212.  
  213. Private Sub Form_Resize()
  214.     'Every control checked to resize it
  215.     
  216.     If OldWidth > 0 Then
  217.         Dim Ctl As Control
  218.         Dim T As Object
  219.         For Each Ctl In Me
  220.             If Left(Ctl.Name, 5) <> "Timer" Then
  221.                 Ctl.Left = Ctl.Left / (OldWidth / Me.Width)
  222.                 Ctl.Top = Ctl.Top / (OldHeight / Me.Height)
  223.                 Ctl.Width = Ctl.Width / (OldWidth / Me.Width)
  224.                 Ctl.Height = Ctl.Height / (OldHeight / Me.Height)
  225.             End If
  226.         Next
  227.     
  228.     End If
  229.     
  230.     OldWidth = Me.Width
  231.     OldHeight = Me.Height
  232.     
  233. End Sub
  234.  
  235.  
  236. Private Function CalculateMerker(ByVal myLevel As Integer, ByVal Max As Integer) As String
  237.     'Creates the colors for the game
  238.     Randomize Timer
  239.     Dim i           As Integer
  240.     Dim W           As String
  241.     
  242.     If Check1.Value = 0 Then
  243.         For i = 0 To myLevel
  244.             W = W & CStr(CInt(Rnd * Max)) & ";"
  245.         Next
  246.     Else
  247.         W = MerkerOld
  248.         W = W & CStr(CInt(Rnd * Max)) & ";"
  249.     End If
  250.     
  251.     CalculateMerker = W
  252.     MerkerOld = W
  253. End Function
  254.  
  255.  
  256. Private Sub Picture1_DblClick(Index As Integer)
  257.     'When you click the second time on a Box
  258.     'Windows things you mean a double click.
  259.     If Merker <> "" Then Call Light(Index)
  260.  
  261. End Sub
  262.  
  263. Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  264.     'Light the box if user is clicking in it
  265.     If Merker <> "" Then Call Light(Index)
  266. End Sub
  267.  
  268. Private Sub Picture1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  269.     'Now check the answer
  270.     If Merker <> "" Then
  271.         Call Light(-1)
  272.         Call CheckAnswer(Index)
  273.     End If
  274. End Sub
  275.  
  276. Private Sub CheckAnswer(ByVal Index As Integer)
  277.     'Checks if the answer is correct
  278.     MerkerAnswer = MerkerAnswer & Index & ";"
  279.     If MerkerAnswer = Left(Merker, Len(MerkerAnswer)) Then
  280.         Call Answer(True)
  281.         If Len(Merker) = Len(MerkerAnswer) Then
  282.             Call Answer(True)
  283.             Level = Level + 1
  284.             Label2.Caption = "You won this level! congratulation! Next Level=" & Level
  285.             If Level > 100 Then
  286.                 MsgBox ("No more levels available")
  287.                 Level = Level - 1
  288.             End If
  289.             Command1.Enabled = True
  290.             Merker = ""
  291.             Timer5.Enabled = True
  292.             Command1.SetFocus
  293.         End If
  294.     Else
  295.         Call Answer(False)
  296.         Call MsgBox("Watch again...")
  297.         MerkerAnswer = ""
  298.         Timer1.Enabled = True
  299.     End If
  300.     
  301.  
  302. End Sub
  303.  
  304. Private Sub Timer1_Timer()
  305.     'Shows the asked colors of the game
  306.     Dim i As Integer
  307.     
  308.     If MerkerPosition >= UBound(Split(Merker, ";")) Then
  309.         Me.Enabled = True
  310.         Timer1.Enabled = False
  311.         Call Light(-1)
  312.         MerkerPosition = 0
  313.     Else
  314.         Me.Enabled = False
  315.         
  316.         i = Val(Split(Merker, ";")(MerkerPosition))
  317.         Call Light(i)
  318.         MerkerPosition = MerkerPosition + 1
  319.     End If
  320.     
  321.     
  322. End Sub
  323.  
  324.  
  325. Private Sub Light(ByVal myIndex As Integer)
  326.     'Let the color light up of the Picturebox
  327.     Dim i       As Integer
  328.     Dim R       As Integer
  329.     Dim G       As Integer
  330.     Dim B       As Integer
  331.     Dim Col1    As Long
  332.     Dim Col2    As Long
  333.     Dim D       As String
  334.     Dim W       As String
  335.     
  336.     
  337.     For i = 0 To Picture1.UBound
  338.         Col1 = Picture1(i).Point(1, 1)
  339.         Call RGBsplit1(Col1, R, G, B)
  340.         If i = myIndex Then
  341.             If Picture1(i).Tag <> "ON" Then
  342.                 R = R * 2
  343.                 G = G * 2
  344.                 B = B * 2
  345.             End If
  346.             Picture1(i).Tag = "ON"
  347.         Else
  348.             If Picture1(i).Tag = "ON" Then
  349.                 R = R / 2
  350.                 G = G / 2
  351.                 B = B / 2
  352.             End If
  353.             Picture1(i).Tag = "OFF"
  354.         End If
  355.         If R > 255 Then R = 255
  356.         If G > 255 Then G = 255
  357.         If B > 255 Then B = 255
  358.         Picture1(i).BackColor = RGB(R, G, B)
  359.     Next
  360.     
  361.     
  362.     'Play the sound
  363.     W = Space$(260)
  364.     D = App.Path & "\" & "sensor" & myIndex + 1 & ".wav"
  365.     Call GetShortPathName(D, W, Len(W))
  366.     If Len(W) > 0 Then Call PlaySound(W, 0, 1)
  367.     
  368.     'For switching the colors off.
  369.     Timer4.Enabled = False
  370.     Timer4.Enabled = True
  371. End Sub
  372.  
  373. Private Sub RGBsplit1(ByVal Col As Long, ByRef R As Integer, ByRef G As Integer, ByRef B As Integer)
  374.     'Split the Color in R, G and B value
  375.     B = (Col And 16711680) / 65536
  376.     G = (Col And 65280) / 256
  377.     R = Col And 255
  378. End Sub
  379.  
  380. Private Sub Timer2_Timer()
  381.     'Intro
  382.     Dim i       As Integer
  383.     
  384.     i = Val(Timer2.Tag)
  385.     If i < 4 Then
  386.         Call Light(i Mod 5)
  387.     ElseIf i < 20 Then
  388.         Call Light(3 - i Mod 4)
  389.     Else
  390.         Call Light(i Mod 4)
  391.     End If
  392.     i = i + 1
  393.     Timer2.Tag = i
  394.     
  395.     If i > 40 Then
  396.         Call Light(-1)
  397.         Timer2.Enabled = False
  398.         Timer2.Tag = ""
  399.     End If
  400. End Sub
  401.  
  402.  
  403. Private Sub Answer(ByVal OK As Boolean)
  404.     'Shows the label red or green with text
  405.     If OK Then
  406.         Label1.BackColor = vbGreen
  407.         Label1.Caption = "OK"
  408.     Else
  409.         Label1.BackColor = vbRed
  410.         Label1.Caption = "WRONG"
  411.     End If
  412.     
  413.     Label1.Visible = True
  414.     Timer3.Enabled = True
  415. End Sub
  416.  
  417. Private Sub Timer3_Timer()
  418.     'Shows, if the answer was right or wrong
  419.     Label1.Visible = False
  420.     Timer3.Enabled = False
  421. End Sub
  422.  
  423. Private Sub Timer4_Timer()
  424.     'Switch off all lights after a while
  425.     Call Light(-1)
  426. End Sub
  427.  
  428. Private Sub Timer5_Timer()
  429.     Timer5.Enabled = False
  430.     Call Start
  431. End Sub
  432.