home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / score / score1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-17  |  10.5 KB  |  330 lines

  1. VERSION 2.00
  2. Begin Form frmScores 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "High Scores"
  6.    ClientHeight    =   3765
  7.    ClientLeft      =   2850
  8.    ClientTop       =   1515
  9.    ClientWidth     =   4230
  10.    ControlBox      =   0   'False
  11.    Height          =   4170
  12.    Icon            =   SCORE1.FRX:0000
  13.    Left            =   2790
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   3765
  18.    ScaleWidth      =   4230
  19.    Top             =   1170
  20.    Width           =   4350
  21.    Begin Timer Timer1 
  22.       Interval        =   3000
  23.       Left            =   3420
  24.       Top             =   3240
  25.    End
  26.    Begin CommandButton btnNewScore 
  27.       Caption         =   "&OK"
  28.       Height          =   375
  29.       Left            =   1500
  30.       TabIndex        =   5
  31.       Top             =   3240
  32.       Width           =   1185
  33.    End
  34.    Begin TextBox txtScore 
  35.       FontBold        =   -1  'True
  36.       FontItalic      =   0   'False
  37.       FontName        =   "MS Sans Serif"
  38.       FontSize        =   9.75
  39.       FontStrikethru  =   0   'False
  40.       FontUnderline   =   0   'False
  41.       Height          =   360
  42.       Left            =   2130
  43.       TabIndex        =   3
  44.       TabStop         =   0   'False
  45.       Text            =   "Text2"
  46.       Top             =   2820
  47.       Width           =   1965
  48.    End
  49.    Begin CommandButton btnOK 
  50.       Caption         =   "&OK"
  51.       Default         =   -1  'True
  52.       Height          =   375
  53.       Left            =   1500
  54.       TabIndex        =   4
  55.       Top             =   3480
  56.       Width           =   1185
  57.    End
  58.    Begin TextBox txtName 
  59.       FontBold        =   -1  'True
  60.       FontItalic      =   0   'False
  61.       FontName        =   "MS Sans Serif"
  62.       FontSize        =   9.75
  63.       FontStrikethru  =   0   'False
  64.       FontUnderline   =   0   'False
  65.       Height          =   360
  66.       Left            =   120
  67.       TabIndex        =   0
  68.       Text            =   "Text1"
  69.       Top             =   2820
  70.       Width           =   1905
  71.    End
  72.    Begin ListBox lstScores 
  73.       BackColor       =   &H00C0C0C0&
  74.       FontBold        =   -1  'True
  75.       FontItalic      =   0   'False
  76.       FontName        =   "MS Sans Serif"
  77.       FontSize        =   9.75
  78.       FontStrikethru  =   0   'False
  79.       FontUnderline   =   0   'False
  80.       ForeColor       =   &H000000FF&
  81.       Height          =   1230
  82.       Left            =   2160
  83.       TabIndex        =   2
  84.       TabStop         =   0   'False
  85.       Top             =   1080
  86.       Width           =   1965
  87.    End
  88.    Begin ListBox lstNames 
  89.       BackColor       =   &H00C0C0C0&
  90.       FontBold        =   -1  'True
  91.       FontItalic      =   0   'False
  92.       FontName        =   "MS Sans Serif"
  93.       FontSize        =   9.75
  94.       FontStrikethru  =   0   'False
  95.       FontUnderline   =   0   'False
  96.       ForeColor       =   &H000000FF&
  97.       Height          =   1230
  98.       Left            =   120
  99.       TabIndex        =   1
  100.       TabStop         =   0   'False
  101.       Top             =   1080
  102.       Width           =   1905
  103.    End
  104.    Begin Label Label2 
  105.       Alignment       =   2  'Center
  106.       BackStyle       =   0  'Transparent
  107.       Caption         =   "SCORES"
  108.       FontBold        =   -1  'True
  109.       FontItalic      =   0   'False
  110.       FontName        =   "MS Sans Serif"
  111.       FontSize        =   9.75
  112.       FontStrikethru  =   0   'False
  113.       FontUnderline   =   0   'False
  114.       Height          =   195
  115.       Left            =   2160
  116.       TabIndex        =   8
  117.       Top             =   840
  118.       Width           =   1875
  119.    End
  120.    Begin Label Label1 
  121.       Alignment       =   2  'Center
  122.       BackStyle       =   0  'Transparent
  123.       Caption         =   "PLAYERS"
  124.       FontBold        =   -1  'True
  125.       FontItalic      =   0   'False
  126.       FontName        =   "MS Sans Serif"
  127.       FontSize        =   9.75
  128.       FontStrikethru  =   0   'False
  129.       FontUnderline   =   0   'False
  130.       Height          =   195
  131.       Left            =   120
  132.       TabIndex        =   7
  133.       Top             =   840
  134.       Width           =   1875
  135.    End
  136.    Begin Image Image3 
  137.       Height          =   720
  138.       Left            =   0
  139.       Picture         =   SCORE1.FRX:0302
  140.       Top             =   5400
  141.       Width           =   4230
  142.    End
  143.    Begin Image Image1 
  144.       Height          =   720
  145.       Left            =   0
  146.       Picture         =   SCORE1.FRX:1E7C
  147.       Top             =   3840
  148.       Width           =   4230
  149.    End
  150.    Begin Image Image2 
  151.       Height          =   720
  152.       Left            =   0
  153.       Picture         =   SCORE1.FRX:39F6
  154.       Top             =   4620
  155.       Width           =   4230
  156.    End
  157.    Begin Label lblInfo 
  158.       Alignment       =   2  'Center
  159.       BackStyle       =   0  'Transparent
  160.       Caption         =   "Congatulations!  You've just achieved a New High Score!  Enter your name below:"
  161.       ForeColor       =   &H00FF0000&
  162.       Height          =   405
  163.       Left            =   180
  164.       TabIndex        =   6
  165.       Top             =   2400
  166.       Width           =   3765
  167.    End
  168.    Begin Image imgMain 
  169.       Height          =   720
  170.       Left            =   0
  171.       Picture         =   SCORE1.FRX:5570
  172.       Top             =   30
  173.       Width           =   4230
  174.    End
  175. Option Explicit
  176. '------------------------------------------------------------
  177. ' SCORE1.FRM
  178. ' This form is dependent on file SCORE1.BAS.
  179. '------------------------------------------------------------
  180. ' Windows API call used to send a message to a window.  In
  181. ' our case, we use it to send a message to a text box control
  182. ' that it should be read-only.
  183. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  184. ' Constants used to make a text box read-only.
  185. Const WM_USER = &H400
  186. Const EM_SETREADONLY = (WM_USER + 31)
  187. Sub btnNewScore_Click ()
  188. '------------------------------------------------------------
  189. ' When this button is pressed, save the new player name and
  190. ' score, then hide the text boxes and button used to enter
  191. ' the player's name, and resize the form.
  192. '------------------------------------------------------------
  193.     ' Save all high scores back to the .INI file.
  194.     AddScoreAndSave txtName, txtScore
  195.     DisplayScores
  196.     SetForDisplay
  197. End Sub
  198. Sub btnOK_Click ()
  199. '------------------------------------------------------------
  200. ' Close the frmScores window when this button is pushed.
  201. '------------------------------------------------------------
  202.     Timer1.Enabled = False
  203.     Timer1.Interval = 0
  204.     DoEvents
  205.     Unload Me
  206. End Sub
  207. Sub DisplayScores ()
  208. '------------------------------------------------------------
  209. ' Display the scores and player names from the Hi() array
  210. ' into the form's list controls.
  211. '------------------------------------------------------------
  212. Dim i As Integer
  213.                       
  214.     If Num_HiScores > 0 Then
  215.     ' Empty the lists.
  216.     lstNames.Clear
  217.     lstScores.Clear
  218.     ' Display the high scores in the list boxes.
  219.     For i = 1 To Num_HiScores
  220.         lstNames.AddItem Hi(i).Name
  221.         lstScores.AddItem Format$(Hi(i).Score)
  222.     Next
  223.     End If
  224. End Sub
  225. Sub Form_Load ()
  226. '------------------------------------------------------------
  227. ' When the form is loaded, center it and display the current
  228. ' high scores.
  229. '------------------------------------------------------------
  230. Dim rc As Long
  231.     ' Center the form on the screen.
  232.     Me.Left = (Screen.Width - Me.Width) \ 2
  233.     Me.Top = (Screen.Height - Me.Height) \ 2
  234.     Me.Caption = gGameTitle
  235.     ' Display current high scores.
  236.     DisplayScores
  237.     If gDisplayOnly Then
  238.     SetForDisplay
  239.     Else
  240.     btnOK.Visible = False
  241.     btnNewScore.Default = True
  242.     ' Clear text field to let player enter their name.
  243.     txtName = ""
  244.     txtName.MaxLength = 15
  245.     txtScore = Format$(gNewScore)
  246.     rc = SendMessage(txtScore.hWnd, EM_SETREADONLY, 1, 0)
  247.     End If
  248. End Sub
  249. Sub Form_Paint ()
  250.     Make3D Me, lstNames, 1
  251.     Make3D Me, lstScores, 1
  252.     If txtName.Visible Then
  253.     Make3D Me, txtName, 0
  254.     Make3D Me, txtScore, 0
  255.     End If
  256. End Sub
  257. Sub Make3D (pic As Form, ctl As Control, ByVal BorderStyle As Integer)
  258. '--------------------------------------------------
  259. ' Wrap a 3D effect around a control on a form.
  260. '--------------------------------------------------
  261. Dim AdjustX As Integer, AdjustY As Integer
  262. Dim RightSide As Single
  263. Dim BW As Integer, BorderWidth As Integer
  264. Dim LeftTopColor As Long, RightBottomColor As Long
  265. Dim i As Integer
  266. ' Color Constants
  267. Const DARK_GRAY = &H808080
  268. Const WHITE = &HFFFFFF
  269. Const BLACK = &H0
  270.     If Not ctl.Visible Then Exit Sub
  271.     AdjustX = Screen.TwipsPerPixelX
  272.     AdjustY = Screen.TwipsPerPixelY
  273.     BorderWidth = 1
  274.     Select Case BorderStyle
  275.     Case 0: ' Inset
  276.         LeftTopColor = DARK_GRAY
  277.         RightBottomColor = WHITE
  278.     Case 1: ' Raised
  279.         LeftTopColor = WHITE
  280.         RightBottomColor = DARK_GRAY
  281.     End Select
  282.     ' Set the top shading line.
  283.     For BW = 1 To BorderWidth
  284.     ' Top
  285.     pic.CurrentX = ctl.Left - (AdjustX * BW)
  286.     pic.CurrentY = ctl.Top - (AdjustY * BW)
  287.     pic.Line -(ctl.Left + ctl.Width + (AdjustX * (BW - 1)), ctl.Top - (AdjustY * BW)), LeftTopColor
  288.     ' Right
  289.     pic.Line -(ctl.Left + ctl.Width + (AdjustX * (BW - 1)), ctl.Top + ctl.Height + (AdjustY * (BW - 1))), RightBottomColor
  290.     ' Bottom
  291.     pic.Line -(ctl.Left - (AdjustX * BW), ctl.Top + ctl.Height + (AdjustY * (BW - 1))), RightBottomColor
  292.     ' Left
  293.     pic.Line -(ctl.Left - (AdjustX * BW), ctl.Top - (AdjustY * BW)), LeftTopColor
  294.     Next
  295. End Sub
  296. Sub SetForDisplay ()
  297.     ' Hide "New Hi" controls...
  298.     lblInfo.Visible = False
  299.     txtName.Visible = False
  300.     txtScore.Visible = False
  301.     btnNewScore.Visible = False
  302.     ' Adjust the OK button position and Window Height.
  303.     btnOK.Visible = True
  304.     btnOK.Top = lblInfo.Top
  305.     btnOK.Default = True
  306.     Me.Height = btnNewScore.Top + 45
  307.     Me.Refresh
  308. End Sub
  309. Sub Timer1_Timer ()
  310. Static InSub As Integer
  311. Dim StartTime As Single
  312. Dim i As Integer
  313.     If InSub Then Exit Sub
  314.     InSub = True
  315.     For i = 1 To 4
  316.     imgMain.Picture = Image2.Picture
  317.     StartTime = Timer
  318.     Do While (Timer - StartTime) < .1
  319.         DoEvents
  320.     Loop
  321.     imgMain.Picture = Image3.Picture
  322.     StartTime = Timer
  323.     Do While (Timer - StartTime) < .1
  324.         DoEvents
  325.     Loop
  326.     Next
  327.     imgMain.Picture = Image1.Picture
  328.     InSub = False
  329. End Sub
  330.