This is a simple explanation of how to make a small and fast MineSweeper game for your 83+/84+ calculator in PURE.BASIC!
In order to make a minesweeper game you have to make a few decisions about how you will present your masterpiece to your users, for this example we'll use the homescreen as it is the easiest and fastest.
To start off we need to set up our feild, the maximum for the homescreen is 16w by 8h so...
:Input "WIDTH - ",W ;Input how wide it'll be
:Input "HIGHT - ",H ;and how tall it's going to be
:Input "MINES - ",M ;and how many mines you want
These set up our feild with the width, hight, and number of mines, but what if out user is being silly and entered numbers like 200,300, and 40000 or something like 0,0,0? Well let's fix that.
:W-(/-/16+W)(W>16)+abs(/-/2-W)(W<2/->/W ;Boolean logic ;) if W>16 it makes W 16, and if W<2 it makes W 2. /-/ is negative, and /->/ is sto
:H-(/-/8+H)(H>8)+abs(/-/2-H)(H<2/->/H ;Does the same for H, but 8 instead of 16
:M-((/-/HW-1)+M)(M>HW-1)+abs(/-/1-M)(M<1/->/M ;Similar for the mines, if M is greater than HM-1 it stores that value to the M
Okay, now we have our values set up and squared away we have to make the feild :o this is the hardest part in my opinion, and took me well over 12 tries to perfect and optimize, so let us dive right in!
:ClrHome ;Meh, you don't NEED this, but it's good
:{H,W/->/dim([A] ;Makes the dimensions of [A] user specified
:Fill(10,[A] ;Fills [A] with all 10s
:For(X,1,M ;Repeats until X>M increases by 1 each time
:Output(1,1,iPart(100/MX ;Outputs a precentage loaded
:Repeat .9!=fPart([A](C,Ans ;Repeats until .9 isn't equal to the fPart of [A](C,Ans. != is not-equal-to
:randInt(1,H/->/C ;Random integer between 1 and H stored to C
:randInt(1,W/->/D ;Random integer between 1 and W stored to D
:End ;If the repeat statement is true, it'll move on, if it's untrue then it'll repeat.
:10.9/->/[A](C,Ans ;Stores 10.9 to [A](C,Ans. 10.9 is a mine space
:For(E,C-(C!=1),C+(C!=H ;Another for loop, goes from the space minus 1 (if C isn't 1) to the space plus one (if C isn't H)
:For(F,D-(D!=1),D+(D!=W ;Same as above, except with D and W this time
:[A](E,F)+.1(.9!=fPart([A](E,F/->/[A](E,F
:End ;Ends the F for loop
:End ;Ends the E for loop
:End ;Ends the X for loop
Woo! Okay, now we have a matrix that will suffice as out feild, now to set up the screen...
:Output(1,1," ;Get's rid of the 100
:Repeat .9!=fPart([A](C,Ans
:randInt(1,H/->/C
:randInt(1,W/->/D
:End
:For(E,1,H
:For(F,1,W
:Output(E,F,"/N/ ;/N/ is the large N that is in the Finace menu under apps
:End
:End
Okay, easy, simple straighforward. Now the engine, just as easy as a walking engine with tiles really.
:" 12345678*/N/F/->/Str1 ;Our tileset!
:HW-M/->/M ;M is now the number of nonmine spaces
:Repeat X=45 or 9=[A](C,D) or not(M ;Checks if the getKey is "clear" or if you hit a mine or if yu've won
:Output(C,D,"?
:Repeat Ans ;Repeats until Ans is nonzero
:getKey/->/X ;Stores the getKey value to X
:End
:Output(C,D,sub(Str1,1+iPart([A](C,D)),1 ;Outputs the correct "tile"
:C+(X=34 and C!=H)-(X=25 and C!=1/->/C ;Adds 1 to C if you press down and C isn't equal to H, subtracts 1 from C if you pressed up and C isn't 1
:D+(X=26 and D!=W)-(X=24 and D!=1/->/D ;Same goes for D
:If X=21 and 10=iPart([A](C,Ans
:Then
:For(E,C-(C!=1),C+(C!=H ;Looking familar?
:For(F,D-(D!=1),D+(D!=W
:If 10=iPart([A](C,D)) and .9=fPart([A](C,D
:Then
:M-1/->/M
:10fPart([A](E,F/->/[A](E,F ;The fPart is now the iPart
:Output(E,F,sub(Str1,1+And,1 ;Tiles again
:End
:End
:End
:[A](C,D)+8.1(.9=fPart([A](C,D/->/[A](C,D ;If fPart([A](C,D is .9 then it makes [A](C,D 9
:End
:[A](C,D
:If X=31 and max({10,11}=iPart(Ans
:fPart(Ans)+(10=iPart(Ans))-(11=iPart(Ans/->/[A](C,D ;Does the flag magic
:End ;End of the engine loop
After this, it's all up to you. If M is 0 then you've won, and if X is 45 you quit, everything else means you lost ^^ have fun!