home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / my_mem / mymemry.bas < prev    next >
BASIC Source File  |  1992-01-27  |  13KB  |  327 lines

  1. '  User Profile Routines (from WINAPI.TXT)
  2. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
  3. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  4. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  5.  
  6. Sub InitField ()
  7. 'Tell user to wait
  8.     MyMemory.MousePointer = HOURGLASS
  9.  
  10. 'Reset status variables
  11.     CurrentSquare = 0
  12.     CurrentSquare1 = 0
  13.     CurrentMoves = 0
  14.     CurrentSolved = 0
  15.  
  16. 'Enter Scene pointers, 2 each on the field
  17. ' also Reset squares to closed
  18.     Scene% = 0
  19.     For X% = 0 To (NumberXSquares - 1)
  20.         For Y% = 0 To (NumberYSquares - 1)
  21.             'Reset square to closed
  22.             SquareStatusArray(X%, Y%) = SquareClosed
  23.             'Set scene value
  24.             SquareSceneArray(X%, Y%) = Scene%
  25.             'If half way thru array, repeat scenes
  26.             If Scene% < ((NumberXSquares * NumberYSquares) / 2 - 1) Then
  27.                 Scene% = Scene% + 1
  28.             Else
  29.                 Scene% = 0
  30.             End If
  31.         Next Y%
  32.     Next X%
  33.  
  34. 'Now Shuffle each address scene 3 times
  35.     Randomize
  36.     For I% = 1 To 3
  37.         For X% = 0 To (NumberXSquares - 1)
  38.             For Y% = 0 To (NumberYSquares - 1)
  39.                 RndX% = Int(NumberXSquares * Rnd)
  40.                 RndY% = Int(NumberYSquares * Rnd)
  41.                 TempScene% = SquareSceneArray(RndX%, RndY%)
  42.                 SquareSceneArray(RndX%, RndY%) = SquareSceneArray(X%, Y%)
  43.                 SquareSceneArray(X%, Y%) = TempScene%
  44.             Next Y%
  45.         Next X%
  46.     Next I%
  47.  
  48. 'Build Field of squares, X and Y are now pixel offsets
  49.     'Don't paint screen twice, MyMemory Form will be painted
  50.     'if not active by its Form_Paint routine
  51.     If Screen.ActiveForm.Tag = "MyMemory" Then
  52.         For X% = 0 To ((NumberXSquares - 1) * SquareSize) Step SquareSize
  53.             For Y% = 0 To ((NumberYSquares - 1) * SquareSize) Step SquareSize
  54.                 BuildSquare X%, Y%
  55.             Next Y%
  56.         Next X%
  57.     End If
  58.  
  59. 'Initialize labels and Tell User we're ready
  60.     FieldStatus = FieldReady
  61.     MyMemory.LabelFieldStatus.Caption = ""
  62.     MyMemory.LabelSquareStatus.Caption = ""
  63.     MoveWord = " move."
  64.     Xb% = (NumberXSquares - 8) / 2
  65.     Yb% = (NumberYSquares - 6) / 2
  66.     If ScoreArray(Xb%, Yb%) = NoScore Then
  67.         BS$ = "None"
  68.     Else
  69.         BS$ = Str$(ScoreArray(Xb%, Yb%))
  70.     End If
  71.     MyMemory.FieldDesc.Caption = "Field is " + LTrim$(Str$(NumberXSquares)) + "x" + LTrim$(Str$(NumberYSquares)) + "    Score to Beat: " + BS$
  72.     MyMemory.MousePointer = DEFAULT
  73.  
  74. End Sub
  75.  
  76. Sub BuildSquare (X As Integer, Y As Integer)
  77. 'X and Y are pixel offsets
  78. 'A button has left and top lighter and right and bottom darker than middle
  79. 'outside shading is two pixels wide
  80.  
  81.     MyMemory.Line (X, Y)-(X + SquareSize - 1, Y), WHITE
  82.     MyMemory.Line (X, Y)-(X, Y + SquareSize - 1), WHITE
  83.     MyMemory.Line (X + SquareSize - 1, Y + SquareSize - 1)-(X + SquareSize - 1, Y), GRAY_MEDIUM
  84.     MyMemory.Line (X + SquareSize - 1, Y + SquareSize - 1)-(X, Y + SquareSize - 1), GRAY_MEDIUM
  85.     MyMemory.Line (X + 1, Y + 1)-(X + SquareSize - 2, Y + 1), WHITE
  86.     MyMemory.Line (X + 1, Y + 1)-(X + 1, Y + SquareSize - 2), WHITE
  87.     MyMemory.Line (X + SquareSize - 2, Y + SquareSize - 2)-(X + SquareSize - 2, Y + 1), GRAY_MEDIUM
  88.     MyMemory.Line (X + SquareSize - 2, Y + SquareSize - 2)-(X + 1, Y + SquareSize - 2), GRAY_MEDIUM
  89. 'now clear middle in case an item was displayed
  90.     MyMemory.Line (X + 2, Y + 2)-(X + SquareSize - 3, Y + SquareSize - 3), GRAY_LIGHT, BF
  91. End Sub
  92.  
  93. Sub ResizeMyMemoryForm ()
  94. 'Resize Form according to selected X, Y and squaresize
  95.     XField% = NumberXSquares * SquareSize
  96.     YField% = NumberYSquares * SquareSize
  97.     MyMemory.Width = XField% * TwipsPerPixel + FormBorder
  98.     
  99. 'We need to double label height for small X arrays
  100.     If NumberXSquares < 12 Then
  101.         MyMemory.LabelFieldStatus.Height = FormLabel * 2
  102.         MyMemory.LabelSquareStatus.Height = FormLabel * 2
  103.     ElseIf NumberXSquares > 10 Then
  104.         MyMemory.LabelFieldStatus.Height = FormLabel
  105.         MyMemory.LabelSquareStatus.Height = FormLabel
  106.     End If
  107.     
  108.     If NumberXSquares = 8 And SquareSize = 32 Then
  109.         MyMemory.FieldDesc.Height = FormLabel - 5
  110.         MyMemory.FieldDesc.FontSize = 9.75
  111.     Else
  112.         MyMemory.FieldDesc.Height = FormLabel
  113.         MyMemory.FieldDesc.FontSize = 12
  114.     End If
  115.  
  116. 'After determining label height we can set form height
  117.     MyMemory.Height = (YField% + MyMemory.LabelFieldStatus.Height + MyMemory.FieldDesc.Height) * TwipsPerPixel + FormHeader
  118.  
  119. 'Now set labels in correct position
  120.     Label2L% = XField% / 2
  121.     
  122.     MyMemory.FieldDesc.Top = YField%
  123.     MyMemory.FieldDesc.Left = 0
  124.     MyMemory.FieldDesc.Width = XField%
  125.     
  126.     MyMemory.LabelFieldStatus.Top = YField% + MyMemory.FieldDesc.Height
  127.     MyMemory.LabelFieldStatus.Left = Label2L%
  128.     MyMemory.LabelFieldStatus.Width = Label2L%
  129.     
  130.     MyMemory.LabelSquareStatus.Top = YField% + MyMemory.FieldDesc.Height
  131.     MyMemory.LabelSquareStatus.Left = 0
  132.     MyMemory.LabelSquareStatus.Width = Label2L%
  133.     
  134. End Sub
  135.  
  136. Sub GetMyProfile ()
  137.  
  138.     Temp1% = GetPrivateProfileInt(SelectHeader, "NumberXSquares", -1, IniFile)
  139.     Temp2% = GetPrivateProfileInt(SelectHeader, "NumberYSquares", -1, IniFile)
  140.     Temp3% = GetPrivateProfileInt(SelectHeader, "SquareSize", -1, IniFile)
  141.     Temp4% = GetPrivateProfileInt(SelectHeader, "Timer", -1, IniFile)
  142.     Temp5% = GetPrivateProfileInt(SelectHeader, "SaveBestScore", -1, IniFile)
  143.  
  144.     GetScores
  145.  
  146.     Msg$ = "A Profile has been found in: " + IniFile + NL + NL
  147.     Msg$ = Msg$ + "The following settings are asked for:" + NL
  148.     Msg$ = Msg$ + "  NumberXSquares = " + Str$(Temp1%) + NL
  149.     Msg$ = Msg$ + "  NumberYSquares = " + Str$(Temp2%) + NL
  150.     Msg$ = Msg$ + "  SquareSize = " + Str$(Temp3%) + NL
  151.     Msg$ = Msg$ + "  Timer = " + Str$(Temp4%) + NL
  152.     Msg$ = Msg$ + "  SaveBestScore = " + Str$(Temp5%)
  153.     MsgBox Msg$, MB_OK, "MyMemory Game Setup"
  154.  
  155.     PF$ = "Profile Error"
  156.     TempE% = FALSE
  157.  
  158.     Select Case Temp1%
  159.         Case 8, 10, 12, 14, 16, 18
  160.             NumberXSquares = Temp1%
  161.         Case Else
  162.             TempE% = TRUE
  163.     End Select
  164.  
  165.     Select Case Temp2%
  166.         Case 6, 8, 10
  167.             NumberYSquares = Temp2%
  168.         Case Else
  169.             TempE% = TRUE
  170.     End Select
  171.  
  172.     Select Case Temp3%
  173.         Case 32, 40, 48
  174.             SquareSize = Temp3%
  175.         Case Else
  176.             TempE% = TRUE
  177.     End Select
  178.  
  179.     Select Case Temp4%
  180.         Case 1 To 5
  181.             SetTimer = Temp4%
  182.         Case Else
  183.             TempE% = TRUE
  184.     End Select
  185.  
  186.     Select Case Temp5%
  187.         Case CHECKED, UNCHECKED
  188.             SaveScore = Temp5%
  189.         Case Else
  190.             TempE% = TRUE
  191.     End Select
  192.  
  193.     If TempE% = TRUE Then
  194.         'Indicate change so we can correct setup on exit
  195.         SaveFileChange = TRUE
  196.         'Default Values already in variables
  197.         MsgBox "Illegal value in profile has been reset to default", MB_OK, PF$
  198.     End If
  199.  
  200. 'Check for valid combinations
  201.  
  202.     Msg1$ = "Invalid Field Size resetting to defaults"
  203.     
  204.     If NumberXSquares < 12 Then
  205.         FieldY% = (FormLabel * 3) + (FormHeader / TwipsPerPixel)
  206.     Else
  207.         FieldY% = (FormLabel * 2) + (FormHeader / TwipsPerPixel)
  208.     End If
  209.  
  210.     If (SquareSize * NumberXSquares >= ScreenPixelSizeX) Or (SquareSize * NumberYSquares + FieldY% >= ScreenPixelSizeY) Then
  211.         SquareSize = DefaultSquareSize
  212.         NumberXSquares = DefaultXSquares
  213.         NumberYSquares = DefaultYSquares
  214.         MsgBox Msg1$, MB_OK, PF$
  215.     End If
  216.     
  217. End Sub
  218.  
  219. Sub SaveMyProfile ()
  220.  
  221.     If SaveFile = SelectSaveFileNo Or SaveFileChange = FALSE Then Exit Sub
  222.  
  223.     Temp1% = WritePrivateProfileString(SelectHeader, "NumberXSquares", Str$(NumberXSquares), IniFile)
  224.     Temp2% = WritePrivateProfileString(SelectHeader, "NumberYSquares", Str$(NumberYSquares), IniFile)
  225.     Temp3% = WritePrivateProfileString(SelectHeader, "SquareSize", Str$(SquareSize), IniFile)
  226.     Temp4% = WritePrivateProfileString(SelectHeader, "Timer", Str$(SetTimer), IniFile)
  227.     Temp5% = WritePrivateProfileString(SelectHeader, "SaveBestScore", Str$(SaveScore), IniFile)
  228.  
  229.     If Temp1% = 0 Or Temp2% = 0 Or Temp3% = 0 Or Temp4% = 0 Or Temp5% = 0 Then
  230.         Msg$ = "Error Writing Profile - Check -> " + IniFile + NL
  231.         MsgBox Msg$, MB_OK, "Profile Error"
  232.     End If
  233.  
  234. End Sub
  235.  
  236. Sub GetScores ()
  237. 'Get any scores from ini file
  238.     For X% = 8 To 18 Step 2
  239.         For Y% = 6 To 10 Step 2
  240.             Xa% = (X% - 8) / 2
  241.             Ya% = (Y% - 6) / 2
  242.             KeyWord$ = "Score" + LTrim$(Str$(X%)) + "x" + LTrim$(Str$(Y%))
  243.             ScoreArray(Xa%, Ya%) = GetPrivateProfileInt(SelectHeader, KeyWord$, NoScore, IniFile)
  244.             If ScoreArray(Xa%, Ya%) = 0 Then ScoreArray(Xa%, Ya%) = NoScore
  245.             KeyValue$ = Space$(255)
  246.             KeyWord$ = KeyWord$ + "Name"
  247.             MyGet% = GetPrivateProfileString(SelectHeader, KeyWord$, "N/A", KeyValue$, Len(KeyValue$), IniFile)
  248.             ScoreArrayName(Xa%, Ya%) = Mid$(KeyValue$, 1, MyGet%)
  249.         Next Y%
  250.     Next X%
  251. End Sub
  252.  
  253. Sub SaveMyScore ()
  254.  
  255. 'Get array address for item
  256.     Xa% = (NumberXSquares - 8) / 2
  257.     Ya% = (NumberYSquares - 6) / 2
  258.  
  259. 'If old score, compare to new score
  260.     If CurrentMoves >= ScoreArray(Xa%, Ya%) Then Exit Sub
  261.     ScoreArray(Xa%, Ya%) = CurrentMoves
  262.  
  263. 'See if scores being saved
  264.     If SaveScore <> CHECKED Then Exit Sub
  265.  
  266. 'Now get name of person winning game
  267.     Msg$ = "You've Beaten the last Best Score!" + NL + NL + "Using " + Str$(CurrentMoves) + MoveWord
  268.     Msg$ = Msg$ + NL + NL + "Please enter your name: "
  269.     ScoreArrayName(Xa%, Ya%) = InputBox$(Msg$, "Your're a Winner!", "Name")
  270.  
  271. 'If new score beats old score or no old score then save new score
  272.     KeyWord$ = "Score" + LTrim$(Str$(NumberXSquares%)) + "x" + LTrim$(Str$(NumberYSquares%))
  273.     Temp% = WritePrivateProfileString(SelectHeader, KeyWord$, Str$(ScoreArray(Xa%, Ya%)), IniFile)
  274.     KeyWord$ = KeyWord$ + "Name"
  275.     Temp1% = WritePrivateProfileString(SelectHeader, KeyWord$, ScoreArrayName(Xa%, Ya%), IniFile)
  276.     If Temp% = 0 Or Temp1% = 0 Then
  277.         MsgBox "Error Writing Scores", MB_OK, "Profile Error"
  278.     End If
  279.  
  280. End Sub
  281.  
  282. Sub MyProfile ()
  283.     KeyWord$ = "NumberXSquares"
  284.     If GetPrivateProfileInt(SelectHeader, KeyWord$, -1, SelectMy) <> -1 Then
  285.         SaveFile = SelectSaveFileMy
  286.         IniFile = SelectMy
  287.         GetMyProfile
  288.     ElseIf GetPrivateProfileInt(SelectHeader, KeyWord$, -1, SelectWEP) <> -1 Then
  289.         SaveFile = SelectSaveFileWEP
  290.         IniFile = SelectWEP
  291.         GetMyProfile
  292.     ElseIf GetPrivateProfileInt(SelectHeader, KeyWord$, -1, SelectWIN) <> -1 Then
  293.         SaveFile = SelectSaveFileWIN
  294.         IniFile = SelectWIN
  295.         GetMyProfile
  296.     Else
  297.         SaveFile = SelectSaveFileNo
  298.     End If
  299.     SaveFileStart = SaveFile
  300.  
  301. End Sub
  302.  
  303. Sub ClearAllScores ()
  304.     MousePointer = HOURGLASS
  305.     For I% = 0 To 5
  306.         For J% = 0 To 2
  307.             If ScoreArray(I%, J%) <> NoScore Then
  308.                 ScoreArray(I%, J%) = NoScore
  309.                 If SaveFile <> SelectSaveFileNo Then
  310.                     ScoreArrayName(I%, J%) = ""
  311.                     KeyWord$ = "Score" + LTrim$(Str$(I% * 2 + 8)) + "x" + LTrim$(Str$(J% * 2 + 6))
  312.                     Temp% = WritePrivateProfileString(SelectHeader, KeyWord$, "", IniFile)
  313.                     KeyWord$ = KeyWord$ + "Name"
  314.                     Temp1% = WritePrivateProfileString(SelectHeader, KeyWord$, "", IniFile)
  315.                     If Temp% = 0 Or Temp1% = 0 Then
  316.                         MsgBox "Error Writing Scores", MB_OK, "Profile Error"
  317.                         Exit Sub
  318.                     End If
  319.                 End If
  320.             End If
  321.         Next J%
  322.     Next I%
  323.     MyMemory.FieldDesc.Caption = "Field is " + LTrim$(Str$(NumberXSquares)) + "x" + LTrim$(Str$(NumberYSquares)) + "    Score to Beat: None"
  324.     MousePointer = DEFAULT
  325. End Sub
  326.  
  327.