home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / stra / bluegray.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-20  |  29.3 KB  |  756 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Blue and Gray"
  5.    ClientHeight    =   6030
  6.    ClientLeft      =   960
  7.    ClientTop       =   660
  8.    ClientWidth     =   9000
  9.    Height          =   6435
  10.    Icon            =   BLUEGRAY.FRX:0000
  11.    Left            =   900
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   402
  14.    ScaleMode       =   3  'Pixel
  15.    ScaleWidth      =   600
  16.    Top             =   315
  17.    Width           =   9120
  18.    Begin PictureBox picInfo 
  19.       BackColor       =   &H00C0C0C0&
  20.       BorderStyle     =   0  'None
  21.       Height          =   495
  22.       Left            =   6360
  23.       ScaleHeight     =   495
  24.       ScaleWidth      =   2295
  25.       TabIndex        =   4
  26.       Tag             =   "/3d_inset/"
  27.       Top             =   480
  28.       Width           =   2295
  29.    End
  30.    Begin CommandButton btnStart 
  31.       Caption         =   "&New Game"
  32.       Height          =   315
  33.       Left            =   6180
  34.       TabIndex        =   2
  35.       Top             =   4920
  36.       Width           =   2655
  37.    End
  38.    Begin PictureBox picField 
  39.       AutoRedraw      =   -1  'True
  40.       BackColor       =   &H00808080&
  41.       Height          =   3195
  42.       Left            =   120
  43.       Picture         =   BLUEGRAY.FRX:0302
  44.       ScaleHeight     =   211
  45.       ScaleMode       =   3  'Pixel
  46.       ScaleWidth      =   289
  47.       TabIndex        =   0
  48.       Tag             =   "/3d_inset/"
  49.       Top             =   120
  50.       Width           =   4365
  51.       Begin Shape shpHilite 
  52.          BackColor       =   &H00FFFFFF&
  53.          BorderColor     =   &H00FFFFFF&
  54.          BorderWidth     =   2
  55.          Height          =   435
  56.          Index           =   1
  57.          Left            =   180
  58.          Top             =   720
  59.          Visible         =   0   'False
  60.          Width           =   495
  61.       End
  62.       Begin Image imgDefense 
  63.          Height          =   480
  64.          Index           =   0
  65.          Left            =   1800
  66.          Top             =   720
  67.          Visible         =   0   'False
  68.          Width           =   480
  69.       End
  70.       Begin Image imgOffense 
  71.          Height          =   480
  72.          Index           =   0
  73.          Left            =   1140
  74.          Top             =   720
  75.          Visible         =   0   'False
  76.          Width           =   480
  77.       End
  78.       Begin Shape shpHilite 
  79.          BackColor       =   &H00FFFFFF&
  80.          BorderColor     =   &H000000FF&
  81.          BorderWidth     =   2
  82.          Height          =   435
  83.          Index           =   0
  84.          Left            =   180
  85.          Top             =   180
  86.          Visible         =   0   'False
  87.          Width           =   495
  88.       End
  89.    End
  90.    Begin Label lblPrompt 
  91.       Alignment       =   2  'Center
  92.       BackColor       =   &H0080FFFF&
  93.       BorderStyle     =   1  'Fixed Single
  94.       Caption         =   "Game Over"
  95.       FontBold        =   -1  'True
  96.       FontItalic      =   0   'False
  97.       FontName        =   "MS Sans Serif"
  98.       FontSize        =   9.75
  99.       FontStrikethru  =   0   'False
  100.       FontUnderline   =   0   'False
  101.       ForeColor       =   &H00000080&
  102.       Height          =   315
  103.       Left            =   6180
  104.       TabIndex        =   9
  105.       Tag             =   "/3d_raised/"
  106.       Top             =   4500
  107.       Width           =   2655
  108.    End
  109.    Begin Label Label5 
  110.       BackStyle       =   0  'Transparent
  111.       Caption         =   "Result:"
  112.       Height          =   195
  113.       Left            =   6360
  114.       TabIndex        =   1
  115.       Top             =   2760
  116.       Width           =   1215
  117.    End
  118.    Begin Label lblResult 
  119.       BackStyle       =   0  'Transparent
  120.       ForeColor       =   &H00FF0000&
  121.       Height          =   1215
  122.       Left            =   6360
  123.       TabIndex        =   8
  124.       Tag             =   "/3d_inset/"
  125.       Top             =   3000
  126.       Width           =   2295
  127.    End
  128.    Begin Label Label3 
  129.       BackStyle       =   0  'Transparent
  130.       Caption         =   "Action:"
  131.       Height          =   195
  132.       Left            =   6360
  133.       TabIndex        =   7
  134.       Top             =   1140
  135.       Width           =   1215
  136.    End
  137.    Begin Label lblAction 
  138.       BackStyle       =   0  'Transparent
  139.       ForeColor       =   &H00FF0000&
  140.       Height          =   1215
  141.       Left            =   6360
  142.       TabIndex        =   6
  143.       Tag             =   "/3d_inset/"
  144.       Top             =   1380
  145.       Width           =   2295
  146.    End
  147.    Begin Label Label2 
  148.       BackStyle       =   0  'Transparent
  149.       Caption         =   "Game Piece:"
  150.       Height          =   195
  151.       Left            =   6360
  152.       TabIndex        =   5
  153.       Top             =   240
  154.       Width           =   1815
  155.    End
  156.    Begin Label lbl3DFrame1 
  157.       BackStyle       =   0  'Transparent
  158.       BorderStyle     =   1  'Fixed Single
  159.       Height          =   4275
  160.       Left            =   6180
  161.       TabIndex        =   3
  162.       Tag             =   "/3d_inset/"
  163.       Top             =   120
  164.       Width           =   2655
  165.    End
  166. Option Explicit
  167. '----------------------------------------------------------------------
  168. ' CW.FRM
  169. '----------------------------------------------------------------------
  170. Function Attack (Attacker As tPiece, Defender As tPiece) As Integer
  171. '----------------------------------------------------------------------
  172. ' One player attacks another.  This routine is used by both sides to
  173. ' determine the outcome of an attack by one piece against another.
  174. '----------------------------------------------------------------------
  175. Dim OldStrength As Integer
  176. Dim Distance As Double
  177. Dim i As Integer
  178. Dim AppPath As String
  179. Dim SoundFile As String
  180. Dim rc As Integer
  181.     AppPath = App.Path
  182.     If Right$(AppPath, 1) <> "\" Then AppPath = AppPath & "\"
  183.     OldStrength = Defender.strength
  184.     Describe Attacker, Defender
  185.     Select Case Attacker.type
  186.         Case INFANTRY:
  187.             Select Case Defender.type
  188.                 Case INFANTRY:
  189.                     Defender.strength = Defender.strength - 1
  190.                 Case ARTILLERY, CAVALRY:
  191.                     If (Attacker.strength > Defender.strength) Then
  192.                         Defender.strength = Defender.strength - 1
  193.                     End If
  194.             End Select
  195.             SoundFile = "GUNFIRE.WAV"
  196.         Case ARTILLERY:
  197.             Distance = GetDistance(Attacker, Defender)
  198.             If Distance <= (Attacker.strength * 2) Then
  199.                 Defender.strength = Defender.strength - 1
  200.             End If
  201.             SoundFile = "CANNON.WAV"
  202.         Case CAVALRY:
  203.             Select Case Defender.type
  204.                 Case INFANTRY:
  205.                     Defender.strength = Defender.strength - 2
  206.                 Case ARTILLERY, CAVALRY:
  207.                     Defender.strength = Defender.strength - 1
  208.             End Select
  209.             SoundFile = "GALLOP.WAV"
  210.         Case SPY:
  211.             SoundFile = "THUNDER.WAV"
  212.     End Select
  213.     ' Give the spy a chance...
  214.     If Defender.type = SPY Then
  215.         If (Rnd * 15) = 3 Then
  216.             Defender.strength = 0
  217.         End If
  218.     ' The player got the flag!
  219.     ElseIf (Defender.type = FLAG) And (Attacker.type <> SPY) Then
  220.         gGameState = GAME_OVER
  221.         lblPrompt = "Game Over"
  222.     End If
  223.     If (SoundFile <> "") Then rc = sndPlaySound(AppPath & SoundFile, SND_ASYNC)
  224.     If Attacker.side = OFFENSE Then
  225.         lblResult.ForeColor = BLUE
  226.     Else
  227.         lblResult.ForeColor = RED
  228.     End If
  229.     ' Describe the results of the attack in the lblResult label.
  230.     lblResult = gSideName(Defender.side) & " "
  231.     lblResult = lblResult & gPieceName(Defender.type)
  232.     If Defender.strength <= 0 Then
  233.         Defender.strength = 0
  234.         Attack = True
  235.         lblResult = lblResult & " defeated."
  236.     ElseIf OldStrength > Defender.strength Then
  237.         Attack = False
  238.         lblResult = lblResult & " sustains casualties."
  239.     Else
  240.         Attack = False
  241.         If Attacker.type = SPY Then
  242.             lblResult = gSideName(Attacker.side) & " Spy observes that enemy "
  243.             lblResult = lblResult & gPieceName(Defender.type) & " strength is "
  244.             lblResult = lblResult & gStrengthName(Defender.strength) & "."
  245.         Else
  246.             If Attacker.type = ARTILLERY Then
  247.                 lblResult = gSideName(Attacker.side) & " Artillery missed the target. " & lblResult
  248.             End If
  249.             lblResult = lblResult & " holds fast against enemy " & gPieceName(Attacker.type)
  250.         End If
  251.     End If
  252.     ' Blink the attacker and attacked pieces.
  253.     For i = 1 To 5
  254.         Highlight 1, Defender.row, Defender.col, True
  255.         Highlight 0, Attacker.row, Attacker.col, True
  256.         Pause .25
  257.         Highlight 1, Defender.row, Defender.col, False
  258.         Highlight 0, Attacker.row, Attacker.col, False
  259.         Pause .25
  260.     Next
  261. End Function
  262. Sub btnStart_Click ()
  263. '----------------------------------------------------------------------
  264. ' Start a new game.
  265. '----------------------------------------------------------------------
  266.     SetupOffense
  267.     SetupDefense
  268.     gGameState = SELECT_PIECE
  269.     lblPrompt = "Select a Piece to Move"
  270.     Me.Show
  271. End Sub
  272. Sub DefenseMove ()
  273. '----------------------------------------------------------------------
  274. ' Defense Counter-attacks.  The computer plays defense, so we must
  275. ' try to make the computer relatively intelligent.
  276. '----------------------------------------------------------------------
  277. Dim i As Integer
  278. Dim r As Integer
  279. Dim c As Integer
  280. Dim side As Integer
  281. Dim element As Integer
  282. Dim Defeated As Integer
  283. Dim WorkingArtillery As Integer
  284. Dim NearestTarget As Integer
  285. Dim NearestDistance As Double
  286. Dim Distance As Double
  287.     element = -1
  288.     gGameState = DEFENSE_MOVE
  289.     lblPrompt = "Defense Counter-Attacks"
  290.     ' Look for enemy adjacent to us.
  291.     For i = 1 To gLastDefense
  292.         r = gDefense(i).row
  293.         c = gDefense(i).col
  294.         If imgDefense(i).Visible Then
  295.             ' N
  296.             If WhatPieceHere(side, element, r - 1, c) = OFFENSE Then
  297.             ' NE
  298.             ElseIf WhatPieceHere(side, element, r - 1, c + 1) = OFFENSE Then
  299.             ' E
  300.             ElseIf WhatPieceHere(side, element, r, c + 1) = OFFENSE Then
  301.             ' SE
  302.             ElseIf WhatPieceHere(side, element, r + 1, c + 1) = OFFENSE Then
  303.             ' S
  304.             ElseIf WhatPieceHere(side, element, r + 1, c) = OFFENSE Then
  305.             ' SW
  306.             ElseIf WhatPieceHere(side, element, r + 1, c - 1) = OFFENSE Then
  307.             ' W
  308.             ElseIf WhatPieceHere(side, element, r - 1, c) = OFFENSE Then
  309.             ' NW
  310.             ElseIf WhatPieceHere(side, element, r - 1, c - 1) = OFFENSE Then
  311.             End If
  312.             If side > 0 Then Exit For
  313.         End If
  314.     Next
  315.     ' If someone is close by, attack him.
  316.     If side > 0 Then
  317.         Defeated = Attack(gDefense(i), gOffense(element))
  318.         If Defeated Then
  319.             imgOffense(element).Visible = False
  320.             If Not (gDefense(i).type = ARTILLERY) Then
  321.                 MovePiece gDefense(i), i, gMouseRow, gMouseCol
  322.             End If
  323.         End If
  324.     Else
  325.         ' Look for target to shoot artillery at.
  326.         WorkingArtillery = -1
  327.         For i = 1 To gLastDefense
  328.             If gDefense(i).type = ARTILLERY And imgDefense(i).Visible Then
  329.                 WorkingArtillery = i
  330.                 Exit For
  331.             End If
  332.         Next
  333.         NearestDistance = 100
  334.         If WorkingArtillery > 0 Then
  335.             For i = 1 To gLastOffense
  336.                 If imgOffense(i).Visible Then
  337.                     Distance = GetDistance(gDefense(WorkingArtillery), gOffense(i))
  338.                     If Distance < NearestDistance Then
  339.                         NearestDistance = Distance
  340.                         NearestTarget = i
  341.                     End If
  342.                 End If
  343.             Next
  344.             Defeated = Attack(gDefense(WorkingArtillery), gOffense(NearestTarget))
  345.             If Defeated Then
  346.                 imgOffense(NearestTarget).Visible = False
  347.             End If
  348.         End If
  349.     End If
  350. End Sub
  351. Sub Describe (Attacker As tPiece, Defender As tPiece)
  352. '----------------------------------------------------------------------
  353. ' Describe (in the lblAction label) what action the attacker is taking.
  354. '----------------------------------------------------------------------
  355. Dim Desc As String
  356. Dim ActionVerb As String
  357.     Desc = ""
  358.     If Attacker.type = SPY Then
  359.         ActionVerb = "spies on"
  360.     Else
  361.         ActionVerb = "attacks"
  362.     End If
  363.     Desc = gSideName(Attacker.side)
  364.     Desc = Desc & " " & gPieceName(Attacker.type)
  365.     Desc = Desc & " (" & gStrengthName(Attacker.strength) & " strength) "
  366.     Desc = Desc & ActionVerb & " "
  367.     Desc = Desc & gSideName(Defender.side) & " "
  368.     Desc = Desc & gPieceName(Defender.type) & " ("
  369.     Desc = Desc & gStrengthName(Defender.strength) & " strength). "
  370.     If Attacker.side = OFFENSE Then
  371.         lblAction.ForeColor = BLUE
  372.     Else
  373.         lblAction.ForeColor = RED
  374.     End If
  375.     lblAction = Desc
  376. End Sub
  377. Sub DrawIcon (AnImage As Image, r As Integer, c As Integer)
  378. '----------------------------------------------------------------------
  379. ' Move an icon (stored in an image control) to a row/column location.
  380. '----------------------------------------------------------------------
  381.     AnImage.Move c * P_WIDTH + 2, r * P_WIDTH + 2
  382. End Sub
  383. Sub Form_Load ()
  384. '----------------------------------------------------------------------
  385. ' Set up the playing board and initialize variables used throughout
  386. ' the game.
  387. '----------------------------------------------------------------------
  388. Dim i As Integer
  389. Dim TitleHeight As Integer
  390. Dim BorderWidth As Integer
  391.     Randomize
  392.     ' Calculate the main form's dimensions
  393.     Me.ScaleMode = TWIPS
  394.     BorderWidth = (Me.Width - Me.ScaleWidth)
  395.     TitleHeight = (Me.Height - Me.ScaleHeight - BorderWidth)
  396.     Me.ScaleMode = PIXELS
  397.     picField.Width = BOARD_DIM * P_WIDTH + 1
  398.     picField.Height = picField.Width
  399.     Me.Height = (picField.Height + (picField.Top * 2)) * Screen.TwipsPerPixelY + BorderWidth + TitleHeight
  400.     ' Initialize the highlighting boxes
  401.     shpHilite(0).Width = P_WIDTH + 2
  402.     shpHilite(0).Height = P_WIDTH + 2
  403.     shpHilite(0).ZOrder 0
  404.     shpHilite(1).Width = P_WIDTH + 2
  405.     shpHilite(1).Height = P_WIDTH + 2
  406.     shpHilite(1).ZOrder 0
  407.     ' Center the form on the screen.
  408.     Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
  409.     Me.Hide
  410.     ' Set up the playing board.
  411.     For i = 1 To BOARD_DIM - 1
  412.         picField.Line (0, i * P_WIDTH)-(picField.ScaleWidth, i * P_WIDTH), RGB(0, 128, 0), BF
  413.         picField.Line (i * P_WIDTH, 0)-(i * P_WIDTH, picField.ScaleHeight), RGB(0, 128, 0), BF
  414.     Next
  415.     gLastOffense = 0
  416.     gLastDefense = 0
  417.     ' Piece names used in descriptions.
  418.     gPieceName(INFANTRY) = "Infantry"
  419.     gPieceName(ARTILLERY) = "Artillery"
  420.     gPieceName(CAVALRY) = "Cavalry"
  421.     gPieceName(SPY) = "Spy"
  422.     gPieceName(FLAG) = "Flag"
  423.     ' Strength levels used in descriptions.
  424.     gStrengthName(NONE) = "gone"
  425.     gStrengthName(LOW) = "low"
  426.     gStrengthName(MODERATE) = "moderate"
  427.     gStrengthName(HIGH) = "high"
  428.     ' Names of the sides used in descriptions.
  429.     gSideName(OFFENSE) = "Offensive"
  430.     gSideName(DEFENSE) = "Defensive"
  431.     ' Prepare for the first game.
  432.     btnStart_Click
  433. End Sub
  434. Sub Form_Paint ()
  435. '----------------------------------------------------------------------
  436. ' Put a 3D border around any control tagged "/3D_INSET/" or "/3D_RAISED/.
  437. '----------------------------------------------------------------------
  438. Dim i As Integer
  439.     For i = 0 To Me.Controls.Count - 1
  440.         If UCase$(Me.Controls(i).Tag) = "/3D_RAISED/" Then
  441.             Make3D Me, Me.Controls(i), BORDER_RAISED, 1
  442.         ElseIf UCase$(Me.Controls(i).Tag) = "/3D_INSET/" Then
  443.             Make3D Me, Me.Controls(i), BORDER_INSET, 1
  444.         End If
  445.     Next
  446. End Sub
  447. Function GetDistance (A As tPiece, B As tPiece) As Double
  448. '----------------------------------------------------------------------
  449. ' Calculate the linear distance between two squares.
  450. '----------------------------------------------------------------------
  451.     GetDistance = Sqr((Abs(A.row - B.row) ^ 2) + (Abs(A.col - B.col) ^ 2))
  452. End Function
  453. Sub Highlight (index As Integer, r As Integer, c As Integer, OnOff As Integer)
  454. '----------------------------------------------------------------------
  455. ' Turn on or off the highlight square.
  456. '----------------------------------------------------------------------
  457.     shpHilite(index).Visible = OnOff
  458.     shpHilite(index).Move c * P_WIDTH, r * P_WIDTH
  459. End Sub
  460. Sub imgDefense_Click (index As Integer)
  461. '----------------------------------------------------------------------
  462. ' Clicking on a defensive piece indicates an attack on that piece by
  463. ' the player (offense), if the game state is MOVE_PIECE. After the
  464. ' offensive move is completed, Defense counter-attacks.
  465. '----------------------------------------------------------------------
  466. Dim row As Integer
  467. Dim col As Integer
  468. Dim Defeated As Integer
  469. Dim LegalMove As Integer
  470.     If gGameState = MOVE_PIECE Then
  471.         row = gOffense(gCurrentPiece).row
  472.         col = gOffense(gCurrentPiece).col
  473.         ' If it's a legal move.
  474.         LegalMove = ((Abs(row - gMouseRow) <= 1) And (Abs(col - gMouseCol) <= 1))
  475.         If LegalMove Or (gOffense(gCurrentPiece).type = ARTILLERY) Then
  476.             Highlight 0, gMouseRow, gMouseCol, False
  477.             gGameState = SELECT_PIECE
  478.             lblPrompt = "Select a Piece to Move"
  479.             ' Execute offensive moves
  480.             Defeated = Attack(gOffense(gCurrentPiece), gDefense(index))
  481.             If Defeated Then
  482.                 imgDefense(index).Visible = False
  483.                 If Not (gOffense(gCurrentPiece).type = ARTILLERY) Then
  484.                     MovePiece gOffense(gCurrentPiece), gCurrentPiece, gDefense(index).row, gDefense(index).col
  485.                 End If
  486.             End If
  487.             
  488.             If gGameState = GAME_OVER Then Exit Sub
  489.             Pause 3
  490.             
  491.             ' Execute defensive moves
  492.             DefenseMove
  493.             gGameState = SELECT_PIECE
  494.             lblPrompt = "Select a Piece to Move"
  495.             
  496.         End If
  497.     End If
  498. End Sub
  499. Sub imgDefense_MouseMove (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  500. '----------------------------------------------------------------------
  501. ' Display the name of the Defensive piece when the mouse moves over it.
  502. '----------------------------------------------------------------------
  503.     gMouseRow = gDefense(index).row
  504.     gMouseCol = gDefense(index).col
  505.     picInfo.Cls
  506.     picInfo.ForeColor = BLUE
  507.     picInfo.Print "Defensive "; gPieceName(gDefense(index).type)
  508. End Sub
  509. Sub imgOffense_Click (index As Integer)
  510. '----------------------------------------------------------------------
  511. ' If the game is in SELECT_PIECE or MOVE_PIECE state, clicking on an
  512. ' offensive piece has the effect of making it the currently selected
  513. ' piece.
  514. '----------------------------------------------------------------------
  515.     If (gGameState = SELECT_PIECE) Or (gGameState = MOVE_PIECE) Then
  516.         Highlight 0, gMouseRow, gMouseCol, True
  517.         gCurrentPiece = index
  518.         gGameState = MOVE_PIECE
  519.         lblPrompt = "Move Selected Piece"
  520.     End If
  521. End Sub
  522. Sub imgOffense_MouseMove (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  523. '----------------------------------------------------------------------
  524. ' Give the player information about one of his pieces when the mouse
  525. ' is over it.
  526. '----------------------------------------------------------------------
  527.     gMouseRow = gOffense(index).row
  528.     gMouseCol = gOffense(index).col
  529.     picInfo.Cls
  530.     picInfo.ForeColor = BLUE
  531.     picInfo.Print "Offensive "; gPieceName(gOffense(index).type)
  532.     picInfo.Print "Strength is ";
  533.     Select Case gOffense(index).strength
  534.         Case NONE: picInfo.ForeColor = BLACK
  535.         Case LOW: picInfo.ForeColor = RED
  536.         Case MODERATE: picInfo.ForeColor = YELLOW
  537.         Case HIGH: picInfo.ForeColor = GREEN
  538.     End Select
  539.     picInfo.Print UCase$(gStrengthName(gOffense(index).strength))
  540. End Sub
  541. Sub InitPiece (PieceNum As Integer, ASide As Integer, AType As Integer, AStrength As Integer, ARow As Integer, ACol As Integer)
  542. '----------------------------------------------------------------------
  543. ' Initialize a game piece's data structure in preparation for a new
  544. ' game.
  545. '----------------------------------------------------------------------
  546. Dim APiece As tPiece
  547. Dim AppPath As String
  548.     APiece.side = ASide
  549.     APiece.type = AType
  550.     APiece.strength = AStrength
  551.     APiece.row = ARow
  552.     APiece.col = ACol
  553.     AppPath = App.Path
  554.     If (Right$(AppPath, 1) <> "\") Then AppPath = AppPath & "\"
  555.     If ASide = OFFENSE Then
  556.         Load imgOffense(PieceNum)
  557.         Select Case AType
  558.             Case INFANTRY:
  559.                 imgOffense(PieceNum).Picture = LoadPicture(AppPath & "O_INFTRY.ICO")
  560.             Case CAVALRY:
  561.                 imgOffense(PieceNum).Picture = LoadPicture(AppPath & "O_CAVLRY.ICO")
  562.             Case ARTILLERY:
  563.                 imgOffense(PieceNum).Picture = LoadPicture(AppPath & "O_ARTLRY.ICO")
  564.             'Case GENERAL:
  565.             '    imgOffense(PieceNum).Picture = LoadPicture(AppPath & "O_GENRL.ICO")
  566.             Case SPY:
  567.                 imgOffense(PieceNum).Picture = LoadPicture(AppPath & "O_SPY.ICO")
  568.         End Select
  569.         gOffense(PieceNum) = APiece
  570.         DrawIcon imgOffense(PieceNum), ARow, ACol
  571.         imgOffense(PieceNum).Visible = True
  572.     ElseIf ASide = DEFENSE Then
  573.         Load imgDefense(PieceNum)
  574.         Select Case AType
  575.             Case INFANTRY:
  576.                 imgDefense(PieceNum).Picture = LoadPicture(AppPath & "D_INFTRY.ICO")
  577.             Case CAVALRY:
  578.                 imgDefense(PieceNum).Picture = LoadPicture(AppPath & "D_CAVLRY.ICO")
  579.             Case ARTILLERY:
  580.                 imgDefense(PieceNum).Picture = LoadPicture(AppPath & "D_ARTLRY.ICO")
  581.             'Case GENERAL:
  582.             '    imgDefense(PieceNum).Picture = LoadPicture(AppPath & "D_GENRL.ICO")
  583.             Case FLAG:
  584.                 imgDefense(PieceNum).Picture = LoadPicture(AppPath & "D_FLAG.ICO")
  585.         End Select
  586.         gDefense(PieceNum) = APiece
  587.         DrawIcon imgDefense(PieceNum), ARow, ACol
  588.         imgDefense(PieceNum).Visible = True
  589.     End If
  590. End Sub
  591. Sub MovePiece (APiece As tPiece, Elem As Integer, row As Integer, col As Integer)
  592. '----------------------------------------------------------------------
  593. ' Move a game piece to a specified row and column.
  594. '----------------------------------------------------------------------
  595.     APiece.row = row
  596.     APiece.col = col
  597.     If APiece.side = OFFENSE Then
  598.         DrawIcon imgOffense(Elem), row, col
  599.     Else
  600.         DrawIcon imgDefense(Elem), row, col
  601.     End If
  602. End Sub
  603. Sub Pause (Seconds As Single)
  604. '----------------------------------------------------------------------
  605. ' Pause for a specified number of seconds.
  606. '----------------------------------------------------------------------
  607. Dim StartTime As Single
  608.     StartTime = Timer
  609.     Do
  610.         DoEvents
  611.     Loop Until (Timer - StartTime) >= Seconds
  612. End Sub
  613. Sub picField_Click ()
  614. '----------------------------------------------------------------------
  615. ' If player is in process of moving a piece, clicking on an empty
  616. ' adjacent field will move the piece to that location.  This counts
  617. ' as a move, so defense will counter-attack afterwards.
  618. '----------------------------------------------------------------------
  619. Dim row As Integer
  620. Dim col As Integer
  621.     If gGameState = MOVE_PIECE Then
  622.         gGameState = DEFENSE_MOVE
  623.         row = gOffense(gCurrentPiece).row
  624.         col = gOffense(gCurrentPiece).col
  625.         ' If it's a legal move.
  626.         If ((Abs(row - gMouseRow) <= 1) And (Abs(col - gMouseCol) <= 1)) Then
  627.             Highlight 0, gMouseRow, gMouseCol, False
  628.             MovePiece gOffense(gCurrentPiece), gCurrentPiece, gMouseRow, gMouseCol
  629.             lblAction = "Offense moves " & gPieceName(gOffense(gCurrentPiece).type) & "."
  630.             lblResult = ""
  631.             Pause 1
  632.             
  633.             ' Execute defensive moves
  634.             DefenseMove
  635.             gGameState = SELECT_PIECE
  636.             lblPrompt = "Select a Piece to Move"
  637.         Else
  638.             gGameState = MOVE_PIECE
  639.             gMouseRow = gOffense(gCurrentPiece).row
  640.             gMouseCol = gOffense(gCurrentPiece).col
  641.         End If
  642.     End If
  643. End Sub
  644. Sub picField_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  645. '----------------------------------------------------------------------
  646. ' Set the current board row and column, and clear any information
  647. ' displayed in picInfo.
  648. '----------------------------------------------------------------------
  649. Dim r As Integer, c As Integer
  650.     XYtoRC X, Y, gMouseRow, gMouseCol
  651.     picInfo.Cls
  652. End Sub
  653. Sub SetupDefense ()
  654. '----------------------------------------------------------------------
  655. ' Set up the pieces used by the Defense.
  656. '----------------------------------------------------------------------
  657. Dim i As Integer
  658. Dim MaxStrength As Integer
  659.     For i = 1 To gLastDefense
  660.         Unload imgDefense(i)
  661.     Next
  662.     gLastDefense = 1
  663.     InitPiece gLastDefense, DEFENSE, FLAG, LOW, 0, 6
  664.     gLastDefense = gLastDefense + 1
  665.     InitPiece gLastDefense, DEFENSE, INFANTRY, NONE, 0, 4
  666.     gLastDefense = gLastDefense + 1
  667.     InitPiece gLastDefense, DEFENSE, INFANTRY, NONE, 0, 7
  668.     gLastDefense = gLastDefense + 1
  669.     InitPiece gLastDefense, DEFENSE, INFANTRY, NONE, 1, 4
  670.     gLastDefense = gLastDefense + 1
  671.     InitPiece gLastDefense, DEFENSE, INFANTRY, NONE, 1, 5
  672.     gLastDefense = gLastDefense + 1
  673.     InitPiece gLastDefense, DEFENSE, INFANTRY, NONE, 1, 6
  674.     gLastDefense = gLastDefense + 1
  675.     InitPiece gLastDefense, DEFENSE, INFANTRY, NONE, 1, 7
  676.     gLastDefense = gLastDefense + 1
  677.     InitPiece gLastDefense, DEFENSE, CAVALRY, NONE, 2, 5
  678.     gLastDefense = gLastDefense + 1
  679.     InitPiece gLastDefense, DEFENSE, CAVALRY, NONE, 2, 6
  680.     gLastDefense = gLastDefense + 1
  681.     InitPiece gLastDefense, DEFENSE, ARTILLERY, NONE, 2, 3
  682.     gLastDefense = gLastDefense + 1
  683.     InitPiece gLastDefense, DEFENSE, ARTILLERY, NONE, 2, 8
  684.     gLastDefense = gLastDefense + 1
  685.     InitPiece gLastDefense, DEFENSE, ARTILLERY, NONE, 3, 2
  686.     gLastDefense = gLastDefense + 1
  687.     InitPiece gLastDefense, DEFENSE, ARTILLERY, NONE, 3, 9
  688.     MaxStrength = 24
  689.     For i = 2 To gLastDefense
  690.         gDefense(i).strength = Rnd * 2 + 1
  691.         MaxStrength = MaxStrength - gDefense(i).strength
  692.     Next
  693.     For i = 2 To gLastDefense
  694.         If (MaxStrength > 0) And (gDefense(i).strength < HIGH) Then
  695.             gDefense(i).strength = gDefense(i).strength + 1
  696.             MaxStrength = MaxStrength + 1
  697.         End If
  698.     Next
  699. End Sub
  700. Sub SetupOffense ()
  701. '----------------------------------------------------------------------
  702. ' Set up the pieces used by the Offense.
  703. '----------------------------------------------------------------------
  704. Dim i As Integer
  705.     For i = 1 To gLastOffense
  706.         Unload imgOffense(i)
  707.     Next
  708.     gLastOffense = 1
  709.     InitPiece gLastOffense, OFFENSE, INFANTRY, HIGH, 10, 4
  710.     gLastOffense = gLastOffense + 1
  711.     InitPiece gLastOffense, OFFENSE, CAVALRY, MODERATE, 9, 5
  712.     gLastOffense = gLastOffense + 1
  713.     InitPiece gLastOffense, OFFENSE, ARTILLERY, HIGH, 9, 3
  714.     gLastOffense = gLastOffense + 1
  715.     InitPiece gLastOffense, OFFENSE, INFANTRY, MODERATE, 10, 6
  716.     gLastOffense = gLastOffense + 1
  717.     InitPiece gLastOffense, OFFENSE, SPY, LOW, 11, 5
  718.     gLastOffense = gLastOffense + 1
  719.     InitPiece gLastOffense, OFFENSE, CAVALRY, HIGH, 9, 6
  720.     gLastOffense = gLastOffense + 1
  721.     InitPiece gLastOffense, OFFENSE, INFANTRY, MODERATE, 10, 7
  722.     gLastOffense = gLastOffense + 1
  723.     InitPiece gLastOffense, OFFENSE, ARTILLERY, MODERATE, 9, 8
  724. End Sub
  725. Function WhatPieceHere (side As Integer, element As Integer, r As Integer, c As Integer) As Integer
  726. '----------------------------------------------------------------------
  727. ' Determine what piece (if any) is at this row and column.
  728. '----------------------------------------------------------------------
  729. Dim i As Integer
  730.     side = NEITHER
  731.     ' Check Offense
  732.     For i = 1 To gLastOffense
  733.         If (gOffense(i).row = r) And (gOffense(i).col = c) And (imgOffense(i).Visible) Then
  734.             side = OFFENSE
  735.             element = i
  736.             Exit For
  737.         End If
  738.     Next
  739.     ' Check Defense
  740.     For i = 1 To gLastDefense
  741.         If (gDefense(i).row = r) And (gDefense(i).col = c) And (imgDefense(i).Visible) Then
  742.             side = DEFENSE
  743.             element = i
  744.             Exit For
  745.         End If
  746.     Next
  747.     WhatPieceHere = side
  748. End Function
  749. Sub XYtoRC (ByVal X As Integer, ByVal Y As Integer, r As Integer, c As Integer)
  750. '----------------------------------------------------------------------
  751. ' Translate an x-y coordinate into a board row and column.
  752. '----------------------------------------------------------------------
  753.     r = Y \ P_WIDTH
  754.     c = X \ P_WIDTH
  755. End Sub
  756.