home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / compar1r / asciigam.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-07-01  |  4.2 KB  |  148 lines

  1. VERSION 5.00
  2. Begin VB.Form AsciiGame 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Ascii Game"
  5.    ClientHeight    =   1695
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   2895
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   1695
  13.    ScaleWidth      =   2895
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.Timer Timer1 
  16.       Left            =   1320
  17.       Top             =   240
  18.    End
  19.    Begin VB.Frame fmeScore 
  20.       Caption         =   "Score"
  21.       Height          =   615
  22.       Left            =   120
  23.       TabIndex        =   4
  24.       Top             =   960
  25.       Width           =   2655
  26.       Begin VB.Label lblScore 
  27.          Caption         =   "0"
  28.          Height          =   255
  29.          Left            =   360
  30.          TabIndex        =   5
  31.          Top             =   240
  32.          Width           =   2055
  33.       End
  34.    End
  35.    Begin VB.TextBox txtChar 
  36.       Height          =   375
  37.       Left            =   1560
  38.       TabIndex        =   1
  39.       Top             =   480
  40.       Width           =   1215
  41.    End
  42.    Begin VB.TextBox txtAscii 
  43.       Height          =   375
  44.       Left            =   120
  45.       TabIndex        =   0
  46.       Top             =   480
  47.       Width           =   1215
  48.    End
  49.    Begin VB.Label lblChar 
  50.       Alignment       =   2  'Center
  51.       Caption         =   "Character"
  52.       Height          =   255
  53.       Left            =   1560
  54.       TabIndex        =   3
  55.       Top             =   120
  56.       Width           =   1215
  57.    End
  58.    Begin VB.Label lblAscii 
  59.       Alignment       =   2  'Center
  60.       Caption         =   "Ascii"
  61.       Height          =   255
  62.       Left            =   120
  63.       TabIndex        =   2
  64.       Top             =   120
  65.       Width           =   1215
  66.    End
  67. Attribute VB_Name = "AsciiGame"
  68. Attribute VB_GlobalNameSpace = False
  69. Attribute VB_Creatable = False
  70. Attribute VB_PredeclaredId = True
  71. Attribute VB_Exposed = False
  72. Option Explicit
  73. Dim temp1 As Integer, temp2 As Integer, score As Integer
  74. Private Sub Form_Load()
  75.     score = 1
  76.     Timer1.Interval = 5000
  77.     MsgBox ( _
  78.         "RULES:" _
  79.         & Chr(13) & Chr(13) & _
  80.         "Fill in the blank text box so that it " & _
  81.         "matches the ascii code or character " & _
  82.         "filled in the other text box." _
  83.         & Chr(13) & Chr(13) & _
  84.         "The left text box contains the ascii code" _
  85.         & Chr(13) & _
  86.         "The right text box contains the character" _
  87.         & Chr(13) & Chr(13) & _
  88.         "Every 5 seconds a new round starts" _
  89.         & Chr(13) & _
  90.         "If you don't fill in the blank correctly, " & _
  91.         "you lose a point" _
  92.         & Chr(13) & _
  93.         "If you fill it in correctly, you gain a point." _
  94.         & Chr(13) & Chr(13) & _
  95.         "Have fun!" _
  96.     )
  97.     Timer1.Enabled = True
  98. End Sub
  99. Private Sub Form_Unload(Cancel As Integer)
  100.     Timer1.Enabled = False
  101. End Sub
  102. Private Sub Timer1_Timer()
  103.     If txtAscii.Text = "" Or txtChar.Text = "" Then
  104.     scoreDown
  105.     Else
  106.         If txtAscii.Text = Asc(txtChar.Text) Then
  107.             scoreUp
  108.         Else
  109.             scoreDown
  110.         End If
  111.     End If
  112.     txtAscii.Enabled = True
  113.     txtChar.Enabled = True
  114.     txtAscii.Text = ""
  115.     txtChar.Text = ""
  116.     Randomize
  117.     temp1 = Int((Rnd * 2) + 1)
  118.     If temp1 = 1 Then
  119.         txtAscii.Text = Int((Rnd * 94) + 33) '33-126
  120.         txtAscii.Enabled = False
  121.     ElseIf temp1 = 2 Then
  122.         txtChar.Text = Chr(Int((Rnd * 94) + 33)) '33-126
  123.         txtChar.Enabled = False
  124.     End If
  125. End Sub
  126. Sub scoreDown()
  127.     score = score - 1
  128.     lblScore.Caption = score
  129. End Sub
  130. Sub scoreUp()
  131.     score = score + 1
  132.     lblScore.Caption = score
  133. End Sub
  134. Private Sub txtAscii_Change()
  135.     If IsNumeric(txtAscii.Text) = False Then
  136.         txtAscii.Text = ""
  137.     ElseIf txtAscii.Text < 0 Then
  138.         txtAscii.Text = 0
  139.     ElseIf txtAscii.Text > 255 Then
  140.         txtAscii.Text = 255
  141.     End If
  142. End Sub
  143. Private Sub txtChar_Change()
  144.     If Len(txtChar.Text) > 1 Then
  145.         txtChar.Text = ""
  146.     End If
  147. End Sub
  148.