home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / crispy / pfields.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  19.5 KB  |  686 lines

  1. ' Crispy1 (Kings on top, Queens on the side, and Jacks in the corners)
  2. ' A diversion by Chris Pando
  3. ' IF IT IS SQUINKY, THEN YOU KNOW IT IS BrilligWare!
  4. '
  5. ' I dedicate this program to the public domain.
  6. '
  7. DefInt A-Z
  8.  
  9. Declare Function CardVersion Lib "VBCards.dll" () As Integer
  10.  
  11. Declare Sub GetCard Lib "VBCards.dll" (ByVal Card As Integer)
  12. Declare Sub GetCardBack Lib "VBCards.dll" (ByVal C As Integer)
  13. Declare Sub GetCardMisc Lib "VBCards.dll" (ByVal C As Integer)
  14.  
  15. Declare Function SameCardValue Lib "VBCards.dll" (ByVal C1 As Integer, ByVal C2 As Integer) As Integer
  16.  
  17. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
  18. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
  19.  
  20.  
  21.  
  22. Const TRUE = -1
  23. Const FALSE = 0
  24. Const PIXEL = 3
  25. Const ROYALMOD = 13
  26. Const KING = 0
  27. Const QUEEN = 12
  28. Const JACK = 11
  29.  
  30. Const KING1 = 1   ' valid squares for face cards
  31. Const KING2 = 2
  32. Const KING3 = 13
  33. Const KING4 = 14
  34. Const QUEEN1 = 4
  35. Const QUEEN2 = 7
  36. Const QUEEN3 = 8
  37. Const QUEEN4 = 11
  38. Const JACK1 = 0
  39. Const JACK2 = 3
  40. Const JACK3 = 12
  41. Const JACK4 = 15
  42.  
  43. Const CENTER1 = 5   'symbolic values for the center squares
  44. Const CENTER2 = 6
  45. Const CENTER3 = 9
  46. Const CENTER4 = 10
  47.  
  48. Const CLOSEDFIELD = 1   ' here are the various states
  49. Const OPENFIELD = 2
  50. Const APENDING = 3
  51. Const CPENDING = 4
  52.  
  53. Dim Deck(1 To 52) As Integer    'Deck contains the deal
  54. Dim Field(15) As Integer        'Field contains the playing field
  55.  
  56.             ' State Variables
  57.  
  58. Dim FromCard As Integer         'Contains Card to Match
  59. Dim NumberOpen As Integer       'open places on field
  60. Dim NextCard As Integer         'Pointer to Deck
  61. Dim State As Integer            'Current State
  62. Dim BackDesign As Integer       'Card Back
  63.  
  64. Sub AppExit ()
  65.    WriteProfile
  66.    End
  67. End Sub
  68.  
  69. Sub CenterCtlBottom (Source As Form, Ctl As Control, Alt As Integer)
  70.  ' center control a specified distance above the bottom of the form
  71.  ' works regardless of ScaleMode
  72.  
  73.    Ctl.Top = Source.ScaleHeight - Ctl.Height - Alt
  74.    Ctl.Left = (Source.ScaleWidth - Ctl.Width) / 2
  75. End Sub
  76.  
  77. Sub ChangeCardBack (Index As Integer)
  78.     ReverseImage CardBack.CardBackPic(BackDesign - 1)
  79.     ReverseImage CardBack.CardBackPic(Index)
  80.     BackDesign = Index + 1
  81.     If (NextCard <> 53) Then
  82.        Pfield.NewCards.Picture = CardBack.CardBackPic(Index).Picture
  83.     End If
  84. End Sub
  85.  
  86. Sub CtlEnable (SetMe As Integer)
  87. ' 1 = Click2 off, menus off
  88. ' 2 = Click2 off, menus on
  89. ' 3 = Click2 on, menus on
  90.  
  91.    Select Case SetMe
  92.       Case 1
  93.          Pfield.Click2.Enabled = False
  94.          Pfield.CardBacks.Enabled = False
  95.          Pfield.Shelp.Enabled = False
  96.          Pfield.CAbout.Enabled = False
  97.       Case 2
  98.          Pfield.Click2.Enabled = False
  99.          Pfield.CardBacks.Enabled = True
  100.          Pfield.Shelp.Enabled = True
  101.          Pfield.CAbout.Enabled = True
  102.       Case 3
  103.          Pfield.Click2.Enabled = True
  104.          Pfield.CardBacks.Enabled = True
  105.          Pfield.Shelp.Enabled = True
  106.          Pfield.CAbout.Enabled = True
  107.    End Select
  108.  
  109. End Sub
  110.  
  111. Sub DealCards ()
  112. ' deal a card to all empty positions on the playing field
  113.    i = 0
  114.    Do While (NextCard < 53 And NumberOpen > 0) 'NumberOpen > 0 implies that
  115.       Do While (Field(i) <> -1)                ' there exists a Field(I)
  116.          i = i + 1                             ' = -1
  117.       Loop
  118.  
  119.       Field(i) = Deck(NextCard)
  120.       GetCard (Field(i))
  121.       Pfield.Picture1(i).Picture = ClipBoard.GetData(2)
  122.       NumberOpen = NumberOpen - 1
  123.       NextCard = NextCard + 1
  124.       If (NextCard = 53) Then
  125.          GetCardMisc (1)
  126.       Else
  127.          GetCardBack (BackDesign)
  128.       End If
  129.       Pfield.NewCards.Picture = ClipBoard.GetData(2)
  130.     
  131.       State = CLOSEDFIELD      'set state
  132.       CtlEnable 2
  133.    Loop
  134. End Sub
  135.  
  136. Sub DealDeck ()
  137.  
  138.    NextCard = 1
  139.    For i = 0 To 15
  140.       Field(i) = Deck(NextCard)
  141.       NextCard = NextCard + 1
  142.       GetCard (Field(i))
  143.       Pfield.Picture1(i).Picture = ClipBoard.GetData(2)
  144.    Next
  145.  
  146.    GetCardBack (BackDesign)
  147.    Pfield.NewCards.Picture = ClipBoard.GetData(2)
  148.    
  149.    GetCardMisc (1)
  150.    Pfield.OldCards.Picture = ClipBoard.GetData(2)
  151.     
  152.    CtlEnable 2
  153.    NumberOpen = 0
  154.    State = CLOSEDFIELD
  155.  
  156. End Sub
  157.  
  158. Sub Engine (Index As Integer)
  159.     ' This is the routine that does all the work
  160.     ' I decided this routine would be most reliably implemented
  161.     ' as a semi-rigorous finite state machine
  162.     '
  163.     '
  164.     '
  165.     Select Case State
  166.        Case CLOSEDFIELD
  167.  
  168.           If (RoyalCard(Index) <> True) Then
  169.              ReverseImage Pfield.Picture1(Index)
  170.              State = APENDING
  171.              CtlEnable 1
  172.              FromCard = Index
  173.           End If
  174.  
  175.  
  176.        Case OPENFIELD
  177.  
  178.           If (Field(Index) <> -1) Then
  179.              If (RoyalCard(Index) <> True) Then
  180.                 ReverseImage Pfield.Picture1(Index)
  181.                 State = APENDING
  182.                 CtlEnable 1
  183.                 FromCard = Index
  184.              Else
  185.                 ReverseImage Pfield.Picture1(Index)
  186.                 State = CPENDING
  187.                 CtlEnable 1
  188.                 FromCard = Index
  189.              End If
  190.           End If
  191.  
  192.        Case APENDING
  193.           If (FromCard = Index) Then
  194.              ReverseImage Pfield.Picture1(Index)
  195.              OpenOrClosed                        ' set state
  196.           ElseIf (SameCardValue(Field(FromCard), Field(Index))) Then
  197.              Remove FromCard, Index
  198.              OpenOrClosed                        ' set state
  199.           End If
  200.  
  201.        Case CPENDING
  202.  
  203.           If (FromCard = Index) Then
  204.              ReverseImage Pfield.Picture1(Index)
  205.              State = OPENFIELD
  206.              CtlEnable 3
  207.           ElseIf (ValidEmpty(Index)) Then
  208.              Swap FromCard, Index
  209.              State = OPENFIELD
  210.              CtlEnable 3
  211.           End If
  212.  
  213.     End Select
  214.  
  215.     If TestWin() Then
  216.       LoadWin
  217.     End If
  218. End Sub
  219.  
  220. Sub FrameForm (Source As Form)
  221.    Source.Line (0, 0)-(Source.ScaleWidth - 1, Source.ScaleHeight - 1), RGB(0, 0, 0), B
  222.    Source.Line (1, 1)-(Source.ScaleWidth - 2, Source.ScaleHeight - 2), RGB(255, 255, 255), B
  223.    Source.Line (4, 4)-(Source.ScaleWidth - 5, Source.ScaleHeight - 5), RGB(128, 128, 128), B
  224. End Sub
  225.  
  226. Sub GetProfile ()
  227. ' set a couple of the global variables
  228.    Pfield.WindowState = GetPrivateProfileInt("Crispy1", "WindowState", 2, "CRISPY.INI")
  229.    BackDesign = GetPrivateProfileInt("Crispy1", "BackDesign", 1, "CRISPY.INI")
  230. End Sub
  231.  
  232. Sub Init ()
  233.    GetProfile
  234.    InitDeck
  235.    ShuffleDeck
  236.    DealDeck
  237. End Sub
  238.  
  239. Sub InitDeck ()
  240. ' randomize, load cards into array, and condition control array
  241.    Randomize
  242.  
  243.    For i = 1 To 52
  244.       Deck(i) = i
  245.    Next i
  246.  
  247.    For i = 0 To 15
  248.       Pfield.Picture1(i).FillStyle = 0                   'solid
  249.       Pfield.Picture1(i).FillColor = RGB(192, 192, 192)  'gray
  250.       Pfield.Picture1(i).DrawMode = 10           ' NOT XOR
  251.       Pfield.Picture1(i).ScaleMode = PIXEL
  252.       Pfield.Picture1(i).ScaleHeight = 96
  253.       Pfield.Picture1(i).ScaleWidth = 71
  254.    Next i
  255. End Sub
  256.  
  257. Sub LoadAbout ()
  258.    Dim Color1 As Long
  259.    Dim Color2 As Long
  260.  
  261.    Color2 = RGB(255, 255, 255)
  262.    Color1 = RGB(128, 128, 128)
  263.  
  264.    Load Form1
  265.  
  266.    Form1.WindowState = 0
  267.    Form1.AutoRedraw = True
  268.    Form1.ScaleMode = PIXEL
  269.    Form1.BackColor = RGB(192, 192, 192)
  270.   
  271.    Form1.Top = 690
  272.    Form1.Left = 480
  273.    Form1.Height = 6135
  274.    Form1.Width = 5055
  275.  
  276. ' position the command botton
  277.    CenterCtlBottom Form1, Form1.Command1, 10
  278.    
  279. ' go ahead and frame the form
  280.    FrameForm Form1
  281.  
  282. ' now lets print something
  283.    Form1.FontName = "Helv"
  284.    Form1.FontSize = 24
  285.  
  286.    Form1.ForeColor = Color2
  287.    Form1.CurrentX = 85
  288.    Form1.CurrentY = 15
  289.    Form1.Print "Crispy1"
  290.  
  291.    Form1.ForeColor = Color1
  292.    Form1.CurrentX = 84
  293.    Form1.CurrentY = 14
  294.    Form1.Print "Crispy1"
  295.  
  296.    Form1.ForeColor = Color1
  297.    Form1.CurrentX = 83
  298.    Form1.CurrentY = 13
  299.    Form1.Print "Crispy1"
  300.  
  301.    'now lets print the actual Form1 text
  302.    Form1.FontName = "Helv"
  303.    Form1.FontSize = 18
  304.                              
  305.    Print3D Form1, 10, 55, -1, -1, Color1, Color2, "A game by Chris Pando                        "
  306.    Form1.FontSize = 9.75
  307.    Print3D Form1, 10, 95, -1, -1, Color1, Color2, "71020,2545 (CIS)                             "
  308.    Color2 = RGB(255, 0, 0)
  309.    Color1 = RGB(0, 0, 0)
  310.    Form1.FontSize = 18
  311.    Print3D Form1, 10, 130, 2, -2, Color1, Color2, "If it is squinky, then you "
  312.    Print3D Form1, 10, 155, 2, -2, Color1, Color2, "know it is BrilligWare!    "
  313.  
  314.    SplitFramedForm Form1
  315.  
  316.    Color2 = RGB(255, 255, 255)
  317.    Color1 = RGB(128, 128, 128)
  318.    Form1.FontSize = 9.75
  319.    Print3D Form1, 10, 220, -1, -1, Color1, Color2, "Many thanks to Richard R. Sands, the creator "
  320.    Print3D Form1, 10, 240, -1, -1, Color1, Color2, "of VBCARDS.DLL, who developed the tools      "
  321.    Print3D Form1, 10, 260, -1, -1, Color1, Color2, "and techniques that made this game possible. "
  322.  
  323.  ' Print3D Form1, 10, 290, -1, -1, Color1, Color2, "Also, many thanks to my co-workers who,      "
  324.  ' Print3D Form1, 10, 310, -1, -1, Color1, Color2, "despite great personal hardship, found the   "
  325.  ' Print3D Form1, 10, 330, -1, -1, Color1, Color2, "time to test (and criticize) this game.      "
  326.  
  327.    Form1.Show 1
  328. End Sub
  329.  
  330. Sub LoadCardBack ()
  331.    Load CardBack
  332.  
  333.    CardBack.WindowState = 0
  334.    CardBack.AutoRedraw = True
  335.    CardBack.BackColor = RGB(192, 192, 192)
  336.    CardBack.ScaleMode = PIXEL
  337.  
  338.    For i = 0 To 6
  339.  
  340.    'resize a little bit
  341.       CardBack.CardBackPic(i).Width = 71
  342.       CardBack.CardBackPic(i).Height = 96
  343.  
  344.    'now assign card back
  345.       J = i + 1
  346.       GetCardBack (J)
  347.       CardBack.CardBackPic(i).Picture = ClipBoard.GetData(2)
  348.  
  349.    'now raise card - 4 thick, raised
  350.       RaiseControl CardBack, CardBack.CardBackPic(i), 3, 1
  351.    
  352.    'now set the properties for reverse imaging
  353.       CardBack.CardBackPic(i).FillStyle = 0                   'solid
  354.       CardBack.CardBackPic(i).FillColor = RGB(192, 0, 0)
  355.       CardBack.CardBackPic(i).DrawMode = 10                   'NOT XOR
  356.       CardBack.CardBackPic(i).AutoRedraw = True
  357.    Next i
  358.  
  359.    ReverseImage CardBack.CardBackPic(BackDesign - 1)
  360.    CardBack.Top = 690
  361.    CardBack.Left = 480
  362.    CardBack.Height = 6135
  363.    CardBack.Width = 5055
  364.  
  365.     
  366. ' go ahead and center the command button
  367.    CenterCtlBottom CardBack, CardBack.CardBackOK, 15
  368.  
  369. ' go ahead and frame the form
  370.    FrameForm CardBack
  371.  
  372. ' now lets print something
  373.    CardBack.FontName = "Helv"
  374.    CardBack.FontSize = 24
  375.  
  376.    CardBack.ForeColor = RGB(128, 128, 128)
  377.    CardBack.CurrentX = 40
  378.    CardBack.CurrentY = 20
  379.    CardBack.Print "Pick A Card Back"
  380.  
  381.    CardBack.ForeColor = RGB(128, 128, 128)
  382.    CardBack.CurrentX = 41
  383.    CardBack.CurrentY = 19
  384.    CardBack.Print "Pick A Card Back"
  385.  
  386.    CardBack.ForeColor = RGB(255, 255, 255)
  387.    CardBack.CurrentX = 42
  388.    CardBack.CurrentY = 18
  389.    CardBack.Print "Pick A Card Back"
  390.  
  391.    CardBack.Show 1
  392. End Sub
  393.  
  394. Sub LoadHelp ()
  395.  
  396.    Dim Color1 As Long
  397.    Dim Color2 As Long
  398.     
  399.    Color2 = RGB(255, 255, 255)
  400.    Color1 = RGB(128, 128, 128)
  401.  
  402.    Load Form1
  403.  
  404.    Form1.WindowState = 0
  405.    Form1.AutoRedraw = True
  406.    Form1.BackColor = RGB(192, 192, 192)
  407.   
  408.    Form1.Top = 690
  409.    Form1.Left = 480
  410.    Form1.Height = 6135
  411.    Form1.Width = 5055
  412.  
  413. ' position command button
  414.    CenterCtlBottom Form1, Form1.Command1, 10
  415.  
  416. ' go ahead and frame the form
  417.    FrameForm Form1
  418.  
  419. ' now lets print something
  420.    Form1.FontName = "Helv"
  421.    Form1.FontSize = 24
  422.  
  423.    Form1.ForeColor = Color2
  424.    Form1.CurrentX = 10
  425.    Form1.CurrentY = 10
  426.    Form1.Print "Crispy1 Quick Help"
  427.  
  428.    Form1.ForeColor = Color1
  429.    Form1.CurrentX = 9
  430.    Form1.CurrentY = 9
  431.    Form1.Print "Crispy1 Quick Help"
  432.  
  433.    Form1.ForeColor = Color1
  434.    Form1.CurrentX = 8
  435.    Form1.CurrentY = 8
  436.    Form1.Print "Crispy1 Quick Help"
  437.  
  438. ' now lets print the actual Form1 text
  439.    Form1.FontName = "Helv"
  440.    Form1.FontSize = 9.75
  441.                              
  442.    Print3D Form1, 10, 55, -1, -1, Color1, Color2, "        Kings on Top, Queens on the Side     "
  443.    Print3D Form1, 10, 70, -1, -1, Color1, Color2, "             and Jacks in the Corner         "
  444.    Print3D Form1, 10, 90, -1, -1, Color1, Color2, "The object of the game is to place the face  "
  445.    Print3D Form1, 10, 110, -1, -1, Color1, Color2, "cards on the edges while removing all non-   "
  446.    Print3D Form1, 10, 130, -1, -1, Color1, Color2, "face cards a pair at a time. To remove a     "
  447.    Print3D Form1, 10, 150, -1, -1, Color1, Color2, "pair, click the first card. It will reverse  "
  448.    Print3D Form1, 10, 170, -1, -1, Color1, Color2, "image. Click matching card and the pair will "
  449.    Print3D Form1, 10, 190, -1, -1, Color1, Color2, "be removed. To migrate a face card to the    "
  450.    Print3D Form1, 10, 210, -1, -1, Color1, Color2, "edge, first click the face card, and then the"
  451.    Print3D Form1, 10, 230, -1, -1, Color1, Color2, "eligible edge position to which you wish to  "
  452.    Print3D Form1, 10, 250, -1, -1, Color1, Color2, "move it. (Kings go on top (and bottom),      "
  453.    Print3D Form1, 10, 270, -1, -1, Color1, Color2, "queens go on the sides, and jacks in the cor-"
  454.    Print3D Form1, 10, 290, -1, -1, Color1, Color2, "ner). Click a reverse imaged card to cancel  "
  455.    Print3D Form1, 10, 310, -1, -1, Color1, Color2, "the operation. If the face cards are all in  "
  456.    Print3D Form1, 10, 330, -1, -1, Color1, Color2, "valid edge positions and all other cards have"
  457.    Print3D Form1, 10, 350, -1, -1, Color1, Color2, "been removed, then you have won!.            "
  458.  
  459.   Form1.Show 1
  460. End Sub
  461.  
  462. Sub LoadWin ()
  463.    Dim Color1 As Long
  464.    Dim Color2 As Long
  465.  
  466.    Color2 = RGB(255, 255, 255)
  467.    Color1 = RGB(128, 128, 128)
  468.  
  469.    Load Form1
  470.  
  471.    Form1.WindowState = 0
  472.    Form1.AutoRedraw = True
  473.    Form1.ScaleMode = PIXEL
  474.    Form1.BackColor = RGB(192, 192, 192)
  475.   
  476.    Form1.Top = 2250
  477.    Form1.Left = 1800
  478.    Form1.Height = 3015
  479.    Form1.Width = 2415
  480.  
  481. ' center the command button
  482.    CenterCtlBottom Form1, Form1.Command1, 10
  483.     
  484. ' go ahead and frame the form
  485.    FrameForm Form1
  486.  
  487. ' now lets print something
  488.    Form1.FontName = "Helv"
  489.    Form1.FontSize = 24
  490.  
  491.    Form1.ForeColor = Color2
  492.    Form1.CurrentX = 15
  493.    Form1.CurrentY = 15
  494.    Form1.Print "CRISPY1"
  495.  
  496.    Form1.ForeColor = Color1
  497.    Form1.CurrentX = 14
  498.    Form1.CurrentY = 14
  499.    Form1.Print "CRISPY1"
  500.  
  501.    Form1.ForeColor = Color1
  502.    Form1.CurrentX = 13
  503.    Form1.CurrentY = 13
  504.    Form1.Print "CRISPY1"
  505.  
  506.    'now lets print the actual Form1 text
  507.    Form1.FontName = "Helv"
  508.    Form1.FontSize = 18
  509.                              
  510.    Print3D Form1, 10, 55, -1, -1, Color1, Color2, "We Have  "
  511.    Print3D Form1, 10, 75, -1, -1, Color1, Color2, "A Winner!"
  512.  
  513.    Form1.Show 1
  514.  
  515. End Sub
  516.  
  517. Sub NewGame ()
  518.    ShuffleDeck
  519.    DealDeck
  520. End Sub
  521.  
  522. Sub OpenOrClosed ()
  523. '
  524. ' if any places are open, the we want OPENFIELD & ENABLED
  525. '
  526.    i = -1
  527.    State = CLOSEDFIELD
  528.    CtlEnable 2              'click2 off, menus on
  529.  
  530.    Do
  531.       i = i + 1
  532.       If Field(i) = -1 Then
  533.          State = OPENFIELD
  534.          CtlEnable 3        'everything enabled
  535.       End If
  536.   Loop Until (i = 15 Or Field(i) = -1)
  537.  
  538. End Sub
  539.  
  540. Sub PaintPfield ()
  541. 'not using persistent bit maps, so if Pfield is redisplayed
  542. '(minimized, and then un-minimized) redo graphic effects
  543.    If State = APENDING Or State = CPENDING Then
  544.       ReverseImage Pfield.Picture1(FromCard)
  545.    End If
  546. End Sub
  547.  
  548. Sub Print3D (Source As Form, x As Integer, y As Integer, xdir As Integer, ydir As Integer, Color1 As Long, Color2 As Long, PrintMe As String)
  549.    Dim OldColor As Long
  550.    OldColor = Source.ForeColor
  551.  
  552.    Source.ForeColor = Color1
  553.    Source.CurrentX = x
  554.    Source.CurrentY = y
  555.    Source.Print PrintMe
  556.     
  557.    Source.ForeColor = Color2
  558.    Source.CurrentX = x + xdir
  559.    Source.CurrentY = y + ydir
  560.    Source.Print PrintMe
  561.  
  562.    Source.ForeColor = OldColor
  563. End Sub
  564.  
  565. Sub RaiseControl (Source1 As Form, Source2 As Control, Thickness As Integer, TopColor As Integer)
  566. '
  567. ' will draw a border around a control, with actual graphics on the form
  568. ' assuming everthing is done in pixels
  569. '
  570. Dim Color1 As Long
  571. Dim Color2 As Long
  572.  
  573.    x = Source2.Left
  574.    y = Source2.Top
  575.    w = Source2.Width
  576.    h = Source2.Height
  577.  
  578.    If TopColor = 1 Then
  579.       Color1 = RGB(255, 255, 255)
  580.       Color2 = RGB(128, 128, 128)
  581.    Else
  582.       Color1 = RGB(128, 128, 128)
  583.       Color2 = RGB(255, 255, 255)
  584.    End If
  585.  
  586.    For i = 1 To Thickness
  587.       Source1.Line (x - i, y - i)-Step(w + (2 * i - 1), 0), Color1
  588.       Source1.Line -Step(0, h + (2 * i - 1)), Color1
  589.       Source1.Line -Step(-(w + (2 * i - 1)), 0), Color2
  590.       Source1.Line -Step(0, -(h + 2 * i)), Color2
  591.    Next
  592.  
  593.  
  594. End Sub
  595.  
  596. Sub Remove (Card1 As Integer, Card2 As Integer)
  597.  '
  598.  ' remove the matching cards, and update state varaible NumberOpen
  599.  '
  600.     Pfield.OldCards.Picture = Pfield.Picture1(Card1).Picture
  601.     GetCardMisc (1)
  602.     Pfield.Picture1(Card1).Picture = ClipBoard.GetData(2)
  603.     Pfield.Picture1(Card2).Picture = ClipBoard.GetData(2)
  604.     Field(Card1) = -1
  605.     Field(Card2) = -1
  606.     NumberOpen = NumberOpen + 2
  607. End Sub
  608.  
  609. Sub ReverseImage (Source As Control)
  610. ' assumes drawmode and fillcolor,fillstyle have all been set
  611.    Source.Line (0, 0)-(Source.ScaleWidth, Source.ScaleHeight), , B
  612. End Sub
  613.  
  614. Function RoyalCard (Index As Integer) As Integer
  615.    i = Field(Index) Mod ROYALMOD
  616.    If (i = KING Or i = QUEEN Or i = JACK) Then
  617.       RoyalCard = True
  618.    Else
  619.       RoyalCard = False
  620.    End If
  621. End Function
  622.  
  623. Sub ShuffleDeck ()
  624.    For i = 1 To 10
  625.       For J = 1 To 52
  626.          K = Int(1 + (52 * Rnd))
  627.          Temp = Deck(J)
  628.          Deck(J) = Deck(K)
  629.          Deck(K) = Temp
  630.       Next
  631.    Next
  632. End Sub
  633.  
  634. Sub SplitFramedForm (Source As Form)
  635. 'assuming Source.ScaleMode = PIXEL
  636.    Source.Line (5, (Int(Source.ScaleHeight / 2)))-Step(Source.ScaleWidth - 10, 0), RGB(0, 0, 0)
  637.    Source.Line (5, (Int(Source.ScaleHeight / 2)) + 1)-Step(Source.ScaleWidth - 10, 0), RGB(255, 255, 255)
  638. End Sub
  639.  
  640. Sub Swap (Card1 As Integer, Card2 As Integer)
  641.     Pfield.Picture1(Card2).Picture = Pfield.Picture1(Card1).Picture
  642.     GetCardMisc (1)
  643.     Pfield.Picture1(Card1).Picture = ClipBoard.GetData(2)
  644.     Field(Card2) = Field(Card1)
  645.     Field(Card1) = -1
  646. End Sub
  647.  
  648. Function TestWin () As Integer
  649. ' if the four center places are empty, and all cards have been dealt, then we have a winner
  650.    If NextCard = 53 And Field(CENTER1) = -1 And Field(CENTER2) = -1 And Field(CENTER3) = -1 And Field(CENTER4) = -1 Then
  651.       TestWin = True
  652.    Else
  653.       TestWin = False
  654.    End If
  655. End Function
  656.  
  657. Function ValidEmpty (Index As Integer) As Integer
  658. ' determine if a valid TO location for a face card
  659.    ValidEmpty = False
  660.    If (Field(Index) = -1) Then
  661.  
  662.       i = Field(FromCard) Mod ROYALMOD
  663.       Select Case i
  664.          Case KING
  665.             If (Index = KING1 Or Index = KING2 Or Index = KING3 Or Index = KING4) Then
  666.                ValidEmpty = True
  667.             End If
  668.          Case QUEEN
  669.             If (Index = QUEEN1 Or Index = QUEEN2 Or Index = QUEEN3 Or Index = QUEEN4) Then
  670.                ValidEmpty = True
  671.             End If
  672.          Case JACK
  673.             If (Index = JACK1 Or Index = JACK2 Or Index = JACK3 Or Index = JACK4) Then
  674.                ValidEmpty = True
  675.             End If
  676.       End Select
  677.  
  678.    End If
  679. End Function
  680.  
  681. Sub WriteProfile ()
  682.    x = WritePrivateProfileString("Crispy1", "WindowState", Str$(Pfield.WindowState), "CRISPY.INI")
  683.    x = WritePrivateProfileString("Crispy1", "BackDesign", Str$(BackDesign), "CRISPY.INI")
  684. End Sub
  685.  
  686.