So I've been playing around with my calculator for the past year or so (ever since I learned I could actually program on it) and I've just finished my first 'real' program (I don't think quadratic solvers and rock-paper-scissors games count).
Like the title says, it's a minesweeper game.
Some issues:
There are some segments that are a bit too slow (like when the mines are being placed, and when it's expanding), almost a third of the program is mainly repeated code, and I keep getting the nagging feeling that my Gotos and Lbls are causing memory leaks...
Suggestions/optimizations please?
Code:
Like the title says, it's a minesweeper game.
Some issues:
There are some segments that are a bit too slow (like when the mines are being placed, and when it's expanding), almost a third of the program is mainly repeated code, and I keep getting the nagging feeling that my Gotos and Lbls are causing memory leaks...
Suggestions/optimizations please?
Code:
::"MINESWEEPER
:"VERSION 1.3.1
:If 0
:Then
:Lbl 0
:ClrHome
:DelVar ADelVar BDelVar KDelVar LDelVar NDelVar QDelVar RDelVar VDelVar WDelVar XDelVar Y
:DelVar ∟MS
:DelVar [J]
:DelVar Str1
:Output(1,1,"
:Return
:End
:Full
:Float
:4→X
:ClrHome
:1→K
:Repeat 4=X and (K=105 or K=92
:If X=5 and (K=105 or K=93
:ClrHome
:Output(X,1,"{box}
:Output(1,2,"MINESWEEPER"
:Output(2,2,"VERSION 1.3.1
:0→K
:Output(4,2,"1: PLAY!
:Output(5,2,"2: INSTRUCTIONS
:Output(6,2,"3: ABOUT
:Output(7,2,"
:Output(8,2,"
:Repeat K=22 or K=23 or K=25 or K=34 or K=45 or K=92 or K=93 or K=94 or K=105
:getKey→K
:End
:If K=22 or K=23 or K=45
:Goto 0
:If 9=iPart(K/10
:K-88→X
:If K=25
:(X>4)(X-1)+4not(X>4→X
:If K=34
:(X<6)(X+1)+6not(X<6→X
:Output(4,1,"
:Output(5,1,"
:Output(6,1,"
:If (K=105 and X=6) or 94=K
:Then
:Output(4,2,"MAY 12 2010
:Output(5,2,"BY DEFLECT
:Output(6,2,"
:Output(7,2,"DEFLECT.4444 AT
:Output(8,2,"GMAIL.COM
:End
:If (X=5 and K=105) or 93=K
:Then
:ClrHome
:Output(1,1,"PRESS 'Y='
:Output(2,2,"TO SHOW SQUARE
:Output(3,1,"PRESS 'GRAPH'
:Output(4,2,"TO FLAG
:Output(5,1,"PRESS 'TRACE'
:Output(6,2,"TO RESET
:Output(7,1,"PRESS 'DEL'
:Output(8,2,"TO EXIT
:End
:If (X=5 or X=6) and (105=K or 93=K or 94=K
:Then
:Repeat Ans
:getKey
:If Ans=22 or Ans=23 or K=45
:Goto 0
:End
:End
:End
:Lbl A
:ClrHome
:Output(1,2,"MINES1
:Output(2,2,"VERSION
:Output(3,2,"1.3.1
:Output(4,2,"LOADING
:"Output(5,2,{box}{box}{box}{box}{box}{box}{box}{box}{box}
:Output(6,2,"BY
:Output(7,2,"DEFLECT
:Output(8,2,"
:SetUpEditorMS
:6→dim(∟MS
:0→∟MS(2
:0→∟MS(3
:0→∟MS(4
:1→∟MS(5
:1→∟MS(6
:0→L
:{8,10}→dim([J]
:Fill 0,[J]
:For(X,1,randInt(13,16
:If not(fPart(X/2
:Output(5,X/2+1,"{box}
:randInt(1,8→A
:randInt(1,10→B
:getKey
:If Ans=22 or Ans=23 or Ans=45
:Goto 0
:If 9>[J](A,B
:Then
:9→[J](A,B
:1+∟MS(2→∟MS(2
:For(Q,{-}1,1)
:For(R,{-}1,1)
:If 9≤[J](A,B
:Then
:If ((A+Q)≥1)((B+R)≥1)((A+Q)≤8)(10≥(B+R
:1+[J](A+Q,B+R→[J](A+Q,B+R
:End
:End
:End
:End
:End
:∟MS(2→∟MS(1
:For(X,1,8
:Output(X,1,"++++++++++
:End
:Output(1,12,"TOTAL
:Output(2,12,"MINES
:Output(3,14,∟MS(2
:Output(4,12,"FLAGS
:Output(6,12,"MOVES
:Output(8,12,":)
:Output(∟MS(5),∟MS(6),"{box}
:While not(L
:0→Y
:∟MS(5→V
:∟MS(6→W
:0→K
:{-}1→N
:If not(fPart([J](V,W
:"+→Str1
:If .3=fPart([J](V,W
:Then
:If not(iPart([J](V,W
:Then
:" →Str1
:Else
:iPart([J](V,W→N
:End
:End
:If .1=fPart([J](V,W
:"≠→Str1
:Repeat K=11 or K=14 or K=15 or K=21 or K=22 or K=23 or K=24 or K=25 or K=26 or K=31 or K=34 or K=45
:Output(V,W,"{box}
:getKey→K
:If Ans
:Then
:If N≠{-}1
:Then
:Output(V,W,N
:Else
:Output(V,W,Str1
:End
:End
:End
:If K=22 or K=23 or K=45
:Goto 0
:If K=14
:Goto A
:If K=24
:Then
:W-1→∟MS(6
:If not(∟MS(6
:10→∟MS(6
:End
:If K=26
:Then
:1+W→∟MS(6
:If 11=∟MS(6
:1→∟MS(6
:End
:If K=25
:Then
:V-1→∟MS(5
:If not(∟MS(5
:8→∟MS(5
:End
:If K=34
:Then
:1+V→∟MS(5
:If 9=∟MS(5
:1→∟MS(5
:End
:If (K=11 or K=21) and not(fPart([J](V,W
:Then
:1+∟MS(4→∟MS(4
:If 9≤[J](V,W
:Then
:1→L
:9→[J](V,W
:End
:If 0<[J](V,W
:Then
:.3+[J](V,W→[J](V,W
:Else
:.2+[J](V,W→[J](V,W
:1+Y→Y
:End
:End
:If (K=15 or K=31) and .1≥fPart([J](V,W
:Then
:1+∟MS(4→∟MS(4
:If not(fPart([J](V,W
:Then
:∟MS(2)-1→∟MS(2
:1+∟MS(3→∟MS(3
:.1+[J](V,W→[J](V,W
:If 9≤[J](V,W
:Then
:∟MS(1)-1→∟MS(1
:Else
:1+∟MS(1→∟MS(1
:End
:Else
:1+∟MS(2→∟MS(2
:∟MS(3)-1→∟MS(3
:{-}.1+[J](V,W→[J](V,W
:If 9≤[J](V,W
:Then
:1+∟MS(1→∟MS(1
:Else
:∟MS(1)-1→∟MS(1
:End
:End
:If not(∟MS(1
:2→L
:End
:Output(5,14,"
:Output(5,14,∟MS(3
:Output(7,14,∟MS(4
:If .3=fPart([J](V,W
:Then
:If not(iPart([J](V,W
:Then
:Output(V,W,"
:Else
:If L≠1
:Then
:Output(V,W,iPart([J](V,W
:Else
:Output(V,W,"*
:End
:End
:End
:If L≠1 and .2=fPart([J](V,W
:Then
:.3→[J](V,W
:Output(8,13,"O
:Output(V,W,"
:For(A,{-}1,1
:For(B,{-}1,1
:If ((V+A)>0 and (V+A)<9) and ((W+B)>0 and (W+B<11
:Then
:If not(fPart([J](V+A,W+B
:Then
:If not(iPart([J](V+A,W+B
:Then
:.2→[J](V+A,W+B
:Y+1→Y
:Else
:.3+[J](V+A,W+B→[J](V+A,W+B
:End
:End
:End
:End
:End
:Repeat not(Y
:If Y=1
:0→Y
:For(Q,(V≤4)+8(V≥5),(V≥5)+8(V≤4),(V≤4)-(V≥5
:For(R,(W≤5)+10(W≥6),(W≥6)+10(W≤5),(W≤5)-(W≥6
:getKey
:If Ans=22 or Ans=23 or Ans=45
:Goto 0
:If Ans=14
:Goto A
:If .3=fPart([J](Q,R
:Then
:If not(iPart([J](Q,R
:Then
:Output(Q,R,"
:Else
:Output(Q,R,iPart([J](Q,R
:End
:End
:If .2=fPart([J](Q,R
:Then
:Y-1→Y
:.3→[J](Q,R
:Output(Q,R,"
:For(A,{-}1,1
:For(B,{-}1,1
:If ((Q+A)>0 and (Q+A)<9) and ((R+B)>0 and (R+B)<11
:Then
:If not(fPart([J](Q+A,R+B
:Then
:If not(iPart([J](Q+A,R+B
:Then
:.2→[J](Q+A,R+B
:Y+1→Y
:Else
:.3+[J](Q+A,R+B→[J](Q+A,R+B
:End:End:End
:End:End:End
:End:End:End
:Output(8,13,")
:End:End
:Output(1,12,"{box}{box}{box}{box}{box}
:Output(2,12," YOU
:Output(4,12,"{box}{box}{box}{box}{box}
:Output(5,14,"
:If L=1
:Then
:Output(3,12," LOSE
:Output(8,13,"(
:Output(V,W,"*
:For(A,1,8
:getKey
:If Ans=22 or Ans=23 or Ans=45
:Goto 0
:If Ans=14
:Goto A
:For(B,1,10
:If [J](A,B)≥9 and 0=fPart([J](A,B
:Output(A,B,"*
:If [J](A,B)≤9 and .1=fPart([J](A,B
:Output(A,B,"X
:End
:End
:Else
:Output(V,W,"≠
:Output(3,12," WIN!
:End
:15→K
:While K=11 or K=15 or K=21 or K=24 or K=25 or K=26 or K=31 or K=34
:getKey
:If Ans
:Ans→K
:If K=14
:Goto A
:End
:Goto 0