home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / autose1g / frmcover.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-24  |  19.5 KB  |  560 lines

  1. VERSION 5.00
  2. Object = "{D2D9B7C1-7650-11D1-9481-00A0247B7657}#1.0#0"; "ZLIBOCX2.DLL"
  3. Begin VB.Form frmCover 
  4.    AutoRedraw      =   -1  'True
  5.    BackColor       =   &H00000000&
  6.    BorderStyle     =   0  'None
  7.    Caption         =   "4000 A.D."
  8.    ClientHeight    =   7290
  9.    ClientLeft      =   510
  10.    ClientTop       =   810
  11.    ClientWidth     =   9585
  12.    ControlBox      =   0   'False
  13.    BeginProperty Font 
  14.       Name            =   "MS Sans Serif"
  15.       Size            =   8.25
  16.       Charset         =   0
  17.       Weight          =   400
  18.       Underline       =   0   'False
  19.       Italic          =   -1  'True
  20.       Strikethrough   =   0   'False
  21.    EndProperty
  22.    ForeColor       =   &H00000000&
  23.    HelpContextID   =   30
  24.    Icon            =   "frmcover.frx":0000
  25.    LinkTopic       =   "Form1"
  26.    MaxButton       =   0   'False
  27.    MinButton       =   0   'False
  28.    PaletteMode     =   1  'UseZOrder
  29.    ScaleHeight     =   7290
  30.    ScaleWidth      =   9585
  31.    WindowState     =   2  'Maximized
  32.    Begin ZLIBOCX2LibCtl.zlibIF zlibTester 
  33.       Height          =   375
  34.       Left            =   1935
  35.       OleObjectBlob   =   "frmcover.frx":030A
  36.       TabIndex        =   7
  37.       Top             =   5535
  38.       Visible         =   0   'False
  39.       Width           =   1500
  40.    End
  41.    Begin VB.PictureBox picStarfield2 
  42.       Appearance      =   0  'Flat
  43.       BackColor       =   &H80000005&
  44.       BorderStyle     =   0  'None
  45.       ForeColor       =   &H80000008&
  46.       Height          =   2265
  47.       Left            =   9015
  48.       ScaleHeight     =   2265
  49.       ScaleWidth      =   2760
  50.       TabIndex        =   5
  51.       Top             =   5505
  52.       Visible         =   0   'False
  53.       Width           =   2760
  54.    End
  55.    Begin VB.PictureBox picStarfield1 
  56.       Appearance      =   0  'Flat
  57.       BackColor       =   &H80000005&
  58.       BorderStyle     =   0  'None
  59.       ForeColor       =   &H80000008&
  60.       Height          =   1620
  61.       Left            =   9120
  62.       Picture         =   "frmcover.frx":0342
  63.       ScaleHeight     =   1620
  64.       ScaleWidth      =   2730
  65.       TabIndex        =   6
  66.       Top             =   3390
  67.       Visible         =   0   'False
  68.       Width           =   2730
  69.    End
  70.    Begin VB.Timer tmrOptions 
  71.       Interval        =   500
  72.       Left            =   375
  73.       Top             =   6090
  74.    End
  75.    Begin VB.Label lblVersionNumber 
  76.       BackColor       =   &H00000000&
  77.       BackStyle       =   0  'Transparent
  78.       Caption         =   "Version 2.5"
  79.       BeginProperty Font 
  80.          Name            =   "MS Sans Serif"
  81.          Size            =   12
  82.          Charset         =   0
  83.          Weight          =   700
  84.          Underline       =   0   'False
  85.          Italic          =   0   'False
  86.          Strikethrough   =   0   'False
  87.       EndProperty
  88.       ForeColor       =   &H000000C0&
  89.       Height          =   465
  90.       Left            =   7515
  91.       TabIndex        =   8
  92.       Top             =   3330
  93.       Width           =   1545
  94.    End
  95.    Begin VB.Image imgTitle 
  96.       Appearance      =   0  'Flat
  97.       Height          =   1800
  98.       Left            =   585
  99.       Picture         =   "frmcover.frx":18EC4
  100.       Stretch         =   -1  'True
  101.       Top             =   1335
  102.       Width           =   8415
  103.    End
  104.    Begin VB.Shape Shape1 
  105.       BorderColor     =   &H000000C0&
  106.       Height          =   270
  107.       Left            =   3750
  108.       Shape           =   3  'Circle
  109.       Top             =   6570
  110.       Width           =   300
  111.    End
  112.    Begin VB.Label lblChoice 
  113.       BackStyle       =   0  'Transparent
  114.       Caption         =   "F3  Quit "
  115.       BeginProperty Font 
  116.          Name            =   "MS Sans Serif"
  117.          Size            =   12
  118.          Charset         =   0
  119.          Weight          =   700
  120.          Underline       =   0   'False
  121.          Italic          =   0   'False
  122.          Strikethrough   =   0   'False
  123.       EndProperty
  124.       ForeColor       =   &H000000FF&
  125.       Height          =   300
  126.       Index           =   2
  127.       Left            =   5205
  128.       TabIndex        =   2
  129.       Top             =   5460
  130.       Visible         =   0   'False
  131.       Width           =   1065
  132.    End
  133.    Begin VB.Label lblChoice 
  134.       BackStyle       =   0  'Transparent
  135.       Caption         =   "F2  Load A Game In Progress"
  136.       BeginProperty Font 
  137.          Name            =   "MS Sans Serif"
  138.          Size            =   12
  139.          Charset         =   0
  140.          Weight          =   700
  141.          Underline       =   0   'False
  142.          Italic          =   0   'False
  143.          Strikethrough   =   0   'False
  144.       EndProperty
  145.       ForeColor       =   &H000000FF&
  146.       Height          =   330
  147.       Index           =   1
  148.       Left            =   5205
  149.       TabIndex        =   1
  150.       Top             =   5010
  151.       Visible         =   0   'False
  152.       Width           =   3675
  153.    End
  154.    Begin VB.Label lblChoice 
  155.       BackStyle       =   0  'Transparent
  156.       Caption         =   "F1  Start A New Game"
  157.       BeginProperty Font 
  158.          Name            =   "MS Sans Serif"
  159.          Size            =   12
  160.          Charset         =   0
  161.          Weight          =   700
  162.          Underline       =   0   'False
  163.          Italic          =   0   'False
  164.          Strikethrough   =   0   'False
  165.       EndProperty
  166.       ForeColor       =   &H000000FF&
  167.       Height          =   315
  168.       Index           =   0
  169.       Left            =   5220
  170.       TabIndex        =   0
  171.       Top             =   4590
  172.       Visible         =   0   'False
  173.       Width           =   2730
  174.    End
  175.    Begin VB.Label lblCopyright2 
  176.       BackColor       =   &H00000000&
  177.       BackStyle       =   0  'Transparent
  178.       Caption         =   "1998-99, Gordon Stewart"
  179.       BeginProperty Font 
  180.          Name            =   "MS Sans Serif"
  181.          Size            =   8.25
  182.          Charset         =   0
  183.          Weight          =   700
  184.          Underline       =   0   'False
  185.          Italic          =   -1  'True
  186.          Strikethrough   =   0   'False
  187.       EndProperty
  188.       ForeColor       =   &H000000C0&
  189.       Height          =   270
  190.       Left            =   4095
  191.       TabIndex        =   4
  192.       Top             =   6600
  193.       Width           =   2280
  194.    End
  195.    Begin VB.Label lblCopyright1 
  196.       BackColor       =   &H00000000&
  197.       BackStyle       =   0  'Transparent
  198.       Caption         =   "C"
  199.       BeginProperty Font 
  200.          Name            =   "MS Sans Serif"
  201.          Size            =   9.75
  202.          Charset         =   0
  203.          Weight          =   400
  204.          Underline       =   0   'False
  205.          Italic          =   0   'False
  206.          Strikethrough   =   0   'False
  207.       EndProperty
  208.       ForeColor       =   &H000000C0&
  209.       Height          =   240
  210.       Left            =   3810
  211.       TabIndex        =   3
  212.       Top             =   6585
  213.       Width           =   225
  214.    End
  215. Attribute VB_Name = "frmCover"
  216. Attribute VB_GlobalNameSpace = False
  217. Attribute VB_Creatable = False
  218. Attribute VB_PredeclaredId = True
  219. Attribute VB_Exposed = False
  220. Option Explicit
  221. Dim blue, red
  222. Public StarsDrawn As Boolean
  223. Private Sub Form_Activate()
  224. Randomize
  225. If StarsDrawn = False Then
  226.     'draw white stars on the screen
  227.     Dim a, X, Y
  228.     For a = 1 To 600
  229.         X = Int(Rnd * frmCover.ScaleWidth)
  230.         Y = Int(Rnd * frmCover.ScaleHeight)
  231.         frmCover.PSet (X, Y), vbWhite
  232.     Next a
  233.     'draw darker stars
  234.     Dim grey
  235.     grey = &H808080
  236.     For a = 1 To 800
  237.        X = Int(Rnd * frmCover.ScaleWidth)
  238.        Y = Int(Rnd * frmCover.ScaleHeight)
  239.        frmCover.PSet (X, Y), grey
  240.     Next a
  241.        
  242.     'draw some blue stars
  243.     Dim blue
  244.     blue = &H800000
  245.     For a = 1 To 600
  246.        X = Int(Rnd * frmCover.ScaleWidth)
  247.        Y = Int(Rnd * frmCover.ScaleHeight)
  248.        frmCover.PSet (X, Y), blue
  249.     Next a
  250.         
  251.     StarsDrawn = True   'prevent screen being redrawn later, if user chooses to continue game
  252. End If
  253. End Sub
  254. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  255. Select Case KeyCode
  256. Case vbKeyF1
  257.     'start a new game
  258.     'hide the copyright labels
  259.     lblCopyright1.Visible = False
  260.     lblCopyright2.Visible = False
  261.     Shape1.Visible = False   'the circle around the "c"
  262.     'start newgame
  263.     frmNewGame.Show
  264. Case vbKeyF2
  265.     'load a saved game
  266.     'hide the copyright labels
  267.     lblCopyright1.Visible = False
  268.     lblCopyright2.Visible = False
  269.     Shape1.Visible = False   'the circle around the "c"
  270.     'show gameselect form
  271.     frmSelectGame.Show Modal
  272.     ReadBigFile
  273.     'change from one player to another, depending on
  274.     'value of "current" as read in from saved game file
  275.       If Current = 0 Then
  276.          Current = 1
  277.          Other = 0
  278.       ElseIf Current = 1 Then
  279.          Current = 0
  280.          Other = 1
  281.       End If
  282.       
  283.     'show player 2 setup form if this is player 2's first turn, or if player
  284.     '2 hasn't entered a name yet
  285.     If Player(Current).Name = "" Then
  286.        frmPlayer2Setup.Show Modal
  287.     End If
  288.     PlaySoundEffect "Ambient1"
  289.     'show main game screen
  290.     frmGameScreen.Show
  291. Case vbKeyF3
  292.     'quit
  293.     PlaySoundEffect "Abort"
  294.     End
  295. Case Else
  296.     'ignore other keystrokes
  297.     KeyCode = 0
  298. End Select
  299. End Sub
  300. Private Sub Form_Load()
  301. 'see if game is already running
  302. If App.PrevInstance = True Then
  303.     Call MsgBox("This program is already running!", vbExclamation)
  304.     End
  305. End If
  306. 'read config file
  307. On Error Resume Next
  308.     ReadConfigFile
  309.     SoundOn = DefaultGameSound
  310.     Me.WindowState = DefaultGameSize
  311.     If Me.WindowState = 0 Then
  312.         'readjust location
  313.         Me.Top = 0
  314.         Me.Left = 0
  315.     End If
  316. On Error GoTo 0
  317. PlaySoundEffect "Intro"
  318. blue = &HFF0000
  319. red = &HFF&
  320. 'DO NOT try to pre-load the game screen to speed it up
  321. 'It doesn't work, and screws up everything!
  322. 'position the version number
  323. 'lblVersionNumber.Top = Me.Height - 50
  324. 'lblVersionNumber.Left = Me.Width - 50
  325. End Sub
  326. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  327. 'reset label colours to red
  328. Dim i
  329. For i = 0 To 2
  330.     lblChoice(i).ForeColor = red
  331. Next i
  332. End Sub
  333. Private Sub lblChoice_Click(Index As Integer)
  334. Select Case Index
  335. Case 0
  336.     'start a new game
  337.     'load the new game screen
  338.     Randomize
  339.     'cover up title and labels so they don't show through later
  340.     With picStarfield1
  341.         .Left = 550
  342.         .Top = 1300
  343.         .Height = 1900
  344.         .Width = 8500
  345.     End With
  346.     With picStarfield2
  347.         .Left = 3435
  348.         .Top = 4125
  349.         .Height = 3105
  350.         .Width = 6435
  351.         .Picture = picStarfield1.Picture
  352.     End With
  353.     'hide the labels
  354.     lblCopyright1.Visible = False
  355.     lblCopyright2.Visible = False
  356.     Shape1.Visible = False  'the circle around the "c"
  357.     lblVersionNumber.Visible = False
  358.     'load form to start new game
  359.     frmNewGame.Show
  360. Case 1
  361.     'Load a saved game
  362.     'hide the labels
  363.     lblCopyright1.Visible = False
  364.     lblCopyright2.Visible = False
  365.     Shape1.Visible = False   'the circle around the "c"
  366.     lblVersionNumber.Visible = False
  367.     frmSelectGame.Show Modal
  368.     'player cancels load
  369.     If LoadCancelled = True Then
  370.         'program returns to frmCover
  371.         LoadCancelled = False
  372.         Exit Sub
  373.     End If
  374.     'read in saved game info from file
  375.     ReadBigFile
  376.     'delete the gameinfo.txt file
  377.     On Error Resume Next
  378.     Kill (App.Path + "\gameinfo.txt")
  379.     On Error GoTo 0
  380.     'change from one player to another, depending on
  381.     'value of "current" as read in from players.txt
  382.     If Current = 0 Then
  383.        Current = 1
  384.        Other = 0
  385.     ElseIf Current = 1 Then
  386.        Current = 0
  387.        Other = 1
  388.     End If
  389.     If Player(Current).Name = "" Then
  390.        frmPlayer2Setup.Show Modal
  391.     End If
  392.     PlaySoundEffect "Ambient1"
  393.     frmGameScreen.Show
  394.     '**********************Unload frmCover
  395. Case 2   'Quit Game
  396.     'exit to system
  397.     PlaySoundEffect "Abort"
  398.     'deregister help file
  399.     QuitHelp
  400.     'End
  401.     If TurnNumber = 1 Then
  402.         'for some as-yet unknown reason (at least to me),
  403.         'the program will not shut all the way down on turn 1
  404.         'unless I use End - I know it makes no sense, but...
  405.         
  406.         End
  407.     Else
  408.        '***Alternative to using End:
  409.         Dim F As Long
  410.         'fade form into taskbar
  411.         Me.WindowState = 1
  412.         'count forms opened
  413.         For F = Forms.Count - 1 To 0 Step -1
  414.            Unload Forms(F)
  415.         Next F
  416.         'close any open files
  417.         If (Forms.Count = 0) Then Close
  418.         'set all open forms to Nothing
  419.         Set frmGameScreen = Nothing
  420.     End If
  421. End Select
  422. End Sub
  423. Private Sub lblChoice_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  424.   Dim Counter
  425.   For Counter = 0 To 2
  426.     lblChoice(Counter).ForeColor = red
  427.   Next Counter
  428.   lblChoice(Index).ForeColor = blue
  429. End Sub
  430. Private Sub tmrOptions_Timer()
  431. 'wait a bit before displaying labels, forcing the player to admire the logo before playing...
  432. Dim X
  433. For X = 0 To 2
  434.     lblChoice(X).Visible = True
  435. Next X
  436. tmrOptions.Enabled = False
  437. End Sub
  438. Public Sub ReadBigFile()
  439. 'read in the file with saved game info
  440. Dim Filename As String
  441. Dim ShortName As String
  442. Dim i As Integer
  443. 'set up error trapping if file not in directory
  444. On Error GoTo FileError
  445. ShortName = "\gameinfo.txt"
  446. Filename = App.Path & ShortName
  447. 'get a free file number
  448. gFileNum = FreeFile
  449. 'open the file
  450. Open Filename For Input As gFileNum
  451. 'read galaxysize
  452. Input #gFileNum, GalaxySize
  453. 'read the planet data
  454. For i = 0 To 49
  455.   Input #gFileNum, Planet(i).Name, Planet(i).Owner, Planet(i).Troops, _
  456.   Planet(i).AssaultTroops, Planet(i).CombatStrength, Planet(i).Coordinate, _
  457.   Planet(i).Resources, Planet(i).HaveMissiles, Planet(i).HaveShields, _
  458.   Planet(i).ImprovedResources, Planet(i).HaveScanner, Planet(i).BackGround, _
  459.   Planet(i).HaveJammer, Planet(i).BioRocketETA, Planet(i).Contaminated, Planet(i).NukedResources, _
  460.   Planet(i).Sabotaged, Planet(i).SabotageReduction, Planet(i).SabotagedFactory, Planet(i).Damaged, _
  461.   Planet(i).BioFailed
  462. 'read the player data
  463. For i = 0 To 1
  464.   Input #gFileNum, Current, TurnNumber, Player(i).Name, Player(i).NumTroops, Player(i).NumAssaultTroops, Player(i).NumPlanets, Player(i).NumResources, _
  465.   Player(i).HomePlanet, Player(i).Message1Given, Player(i).Message2Given, Player(i).WasBig, Player(i).Missile1ResearchDone, Player(i).Missile1Researched, _
  466.   Player(i).Missile2ResearchDone, Player(i).Missile2Researched, Player(i).ShieldResearchDone, Player(i).ShieldResearched, _
  467.   Player(i).LaserResearchDone, Player(i).LaserResearched, Player(i).PlasmaResearchDone, Player(i).PlasmaResearched, Player(i).MechResearchDone, Player(i).MechResearched, _
  468.   Player(i).BioRocketResearchDone, Player(i).BioRocketResearched, Player(i).LongBioResearchDone, Player(i).LongBioResearched, Player(i).ShipShield1ResearchDone, Player(i).ShipShield1Researched, _
  469.   Player(i).ShipShield2ResearchDone, Player(i).ShipShield2Researched, Player(i).BigShipResearchDone, Player(i).BigShipResearched, Player(i).UltraWarpResearchDone, Player(i).UltraWarpResearched, _
  470.   Player(i).CloakingResearchDone, Player(i).CloakingResearched, Player(i).ResourceResearchDone, Player(i).ResourcesResearched, Player(i).BioCleanupResearchDone, Player(i).BioCleanupResearched, _
  471.   Player(i).RegenerationResearchDone, Player(i).RegenerationResearched, Player(i).ScannerResearchDone, Player(i).ScannerResearched, Player(i).DeepScannerResearchDone, Player(i).DeepScannerResearched, _
  472.   Player(i).JammerResearchDone, Player(i).JammerResearched, Player(i).WarpScannerResearchDone, Player(i).WarpScannerResearched
  473. 'read the ship data
  474. For i = 0 To 1
  475.   Input #gFileNum, Player(0).Ship(i).Launched, Player(0).Ship(i).HaveCloakingDevice, _
  476.   Player(0).Ship(i).Troops, Player(0).Ship(i).AssaultTroops, _
  477.   Player(0).Ship(i).CombatStrength, Player(0).Ship(i).WarpPosition, _
  478.   Player(0).Ship(i).Coordinate, Player(0).Ship(i).CenterX, _
  479.   Player(0).Ship(i).CenterY, Player(0).Ship(i).ShipNumber, Player(0).Ship(i).Sabotage, _
  480.   Player(1).Ship(i).Launched, Player(1).Ship(i).HaveCloakingDevice, _
  481.   Player(1).Ship(i).Troops, Player(1).Ship(i).AssaultTroops, _
  482.   Player(1).Ship(i).CombatStrength, Player(1).Ship(i).WarpPosition, _
  483.   Player(1).Ship(i).Coordinate, Player(1).Ship(i).CenterX, _
  484.   Player(1).Ship(i).CenterY, Player(1).Ship(i).ShipNumber, Player(1).Ship(i).Sabotage
  485. 'read in the general data
  486. Input #gFileNum, IncomingMessage, Player(Other).WasBig
  487. 'turn off previous error handling
  488. On Error GoTo 0
  489. 'allow older versions of game to be read, and notify player that their opponent
  490. 'needs to get the new version of the game
  491. 'the following info won't be in saved game files created by older versions of the game!
  492. On Error GoTo NewDataError
  493. 'read captured planets data
  494. Input #gFileNum, NumPlanetsCaptured
  495. For i = 0 To 49
  496.     Input #gFileNum, Planet(i).Captured
  497. Next i
  498. Input #gFileNum, NumFailedInvasions
  499. For i = 0 To 49
  500.     Input #gFileNum, Planet(i).FailedInvasion, Planet(i).FailedInvasionTroopLosses, Planet(i).FailedInvasionMechLosses
  501. Next i
  502. 'turn off that error handler
  503. On Error GoTo 0
  504. 'close the file
  505. Close gFileNum
  506. Exit Sub
  507. FileError:
  508.     'file not in the directory
  509.     PlaySoundEffect "Quiet"
  510.     MsgBox "File not found.", vbOKOnly + vbExclamation, "File Error"
  511.     End
  512.     Exit Sub
  513. NewDataError:
  514.     'error reading from older version
  515.     'close the file
  516.     Dim Msg
  517.     Msg = "The game information file being read by the program is from" + Chr(13)
  518.     Msg = Msg + "an older version of the game." + Chr(13) + Chr(13)
  519.     Msg = Msg + "Please ask your opponent to upgrade to the latest version" + Chr(13)
  520.     Msg = Msg + "of 4000 A.D., as they will not be able to load the file you " + Chr(13) + "send to them." + Chr(13) + Chr(13)
  521.     Msg = Msg + "Upgrades and more available on the internet at:" + Chr(13) + "www.interlog.com/~gordons/4000ad.html"
  522.     PlaySoundEffect "Quiet"
  523.     MsgBox Msg, vbOKOnly + vbInformation, "Reading Old Format"
  524.     Close gFileNum
  525.     Exit Sub
  526. End Sub
  527. Private Sub ZlibTester_Progress(ByVal percent_complete As Integer)
  528. 'this is included to test if the zlibtool.ocx file was properly registered
  529. 'during installation - see details in the sub_main procedure in
  530. 'the Declare.bas file
  531. End Sub
  532. Private Sub zlibITester_Progress(ByVal percent_complete As Integer)
  533. 'this is included to test if the zlibtool.ocx file was properly registered
  534. 'during installation - see details in the sub_main procedure in
  535. 'the Declare.bas file
  536. End Sub
  537. Public Sub ReadConfigFile()
  538. Dim Filename As String
  539. Dim ShortName As String
  540. 'set up error trapping
  541. On Error GoTo ErrorHandler
  542. ShortName = "\4000cfg.txt"
  543. Filename = App.Path & ShortName
  544. 'get a free file number
  545. gFileNum = FreeFile
  546. 'open the file
  547. Open Filename For Input As gFileNum
  548. 'read galaxysize
  549. Input #gFileNum, DefaultGameSound, DefaultGameSize
  550. 'close the file
  551. Close gFileNum
  552. Exit Sub
  553. ErrorHandler:
  554.     'file isn't there - could be missing/deleted, or player is reading game file from
  555.     'an older version of the game, where no 4000cfg.txt file is written
  556.     'close the file and continue
  557.     Close gFileNum
  558.     Exit Sub
  559. End Sub
  560.