Mine sweep.

SYS 64738
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Mine sweep.

Post by Shaun_B »

Here is a very quick Mine Sweeper program written with CBM prg Studio

Code: Select all

0 rem -donkeysoft mmxiv  donkeysoft mmxiv  donkeysoft mmxiv  donkeysoft mmxiv  donkeysoft mmxiv  donkeys--
1 dim a,b,c,i,n,s,t,x,y,z,a$,n$:poke 53280,z:poke 53281,z:print"{clear}{gray} {reverse on} minesweep mini  (c) donkeysoft mmxiv {reverse off}"chr$(13)"{down} ";:a$="----------":a=rnd(z):b=2055:c=65:n=48:x=45:y=44:t=98:for i=z to t:poke b+i,x:next
2 s=1145:for i=z to 9:print chr$(n+i);:next:print:for i=z to 9:print chr$(c+i);a$:next:for i=z to 9
3 a=rnd(z)*t:on-(peek(b+a)=y) goto 3:poke b+a,y:next:print:a=40:i=32:t=y
4 print"enter row then column"chr$(13)">  {left}{left}{reverse on} {reverse off}{left}";
5 get a$:on-(a$<"a" or a$>"j")goto 5:y=asc(a$)-c:print a$;"{reverse on} {reverse off}{left}";:n$=chr$(asc(a$)-17)
6 get a$:on-(a$<"0" or a$>"9")goto 6:x=val(a$):print a$
7 n$=n$+a$:on (peek(b+val(n$))-43) gosub 12,8:print"{up}{up}";:goto 4
8 n=z:poke s+x+y*a,32:for i=y-1 to y+1: for t=x-1 to x+1:if i=>z and i<=9 and t=>0 and t<=9 then n=n-(peek(b+i*10+t)<>45)
9 next t,i:if n then poke s+x+y*a,49+n
10 return
12 poke s+x+y*a,86:return
Basically, you don't die yet in this listing, the logic for that hasn't been added on the basis that I need to make it more modular and do some refactoring.

It generates the Minefield 'map' in the REM statement in line zero, so that needs to stay the same or some of the listing will be over-written with some characters. Or at least keep it to 101 characters after the REM statement.

After a quick test, I think it works.

Regards,

Shaun.


BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: Mine sweep.

Post by Shaun_B »

Here's a slightly refactored and bug-fixed version:

Code: Select all

0 rem"donkeysoft mmxiv  donkeysoft mmxiv  donkeysoft mmxiv  donkeysoft mmxiv  donkeysoft mmxiv  donkeyso "
1 z=0:poke 53280,z:poke 53281,z:print"{clear}{gray} {reverse on} minesweep mini  (c) donkeysoft mmxiv {reverse off}";chr$(13);"{down} ";:gosub 63990
2 print: a=40: t=y
3 print"enter column then row";chr$(13);">  {left}{left}{reverse on} {reverse off}{left}";
4 get a$: on-(a$<"a" or a$>"j") goto 4: y=asc(a$)-c: print a$;"{reverse on} {reverse off}{left}";: n$=chr$(asc(a$)-17)
5 get a$: on-(a$<"0" or a$>"9") goto 5: x=val(a$): print a$: n$=n$+a$: n=z
6 on-(peek(b+val(n$))=160) goto 10: poke s+x+y*a,32
7 for i=y-o to y+o: for t=x-o to x+o: if i=>z and i<=9 and t=>z and t<=9 then n=n-(peek(b+i*10+t)=160)
8 next t,i:if n then poke s+x+y*a,48+n
9 print"{up}{up}";: goto 3
10 poke s+x+y*a,86:print"you hit a mine! game over":end
63990 dim a, b, c, i, n, o, s, t, x, y, a$, n$
63991 a$="----------": a=rnd(z): b=2055: c=65: n=48: o=1: x=32: y=160: t=98: s=1145
63992 for i=z to t: poke b+i,x: next
63993 for i=z to 9: print chr$(n+i);: next: print
63994 for i=z to 9: print chr$(c+i);a$
63995 a=rnd(z)*t:on-(peek(b+a)=y) goto 63995: poke b+a,y: next: return
Some changes:

* The REM statement is filled with spaces which are 'poked' there inbetween the quotation marks. Mines are poked in as shift+space so that you can't list -1 and cheat ;-)
* The listing is slightly cleaner (easy now, I said slightly)
* There are no separate sub routines for the field checker as it's only testing the memory location against the value 160 - if that's true then it's game over (line 10)
* The numbers are now outputted correctly

To do:

* Logic for adding flags
* UDGs and maybe a simple explosion sound
* Add joystick logic instead of keyboard interactions (or alongside keyboard interactions)
* Go to bed as it's nearly 1am here

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 6 guests