rem MineSweeper for the PS2 by Brett Circosta main() sub main() open window 640,512 dim grid(1,1) dim speeda$(1) dim speedb$(1) done = 0 cr = 16384 ci = 8192 tr = 4096 sq = 32768 l = 128 r = 32 u = 16 d = 64 menu() end sub sub menu() zc=12 hm=zc+10 draw=1 for xc=-100 to 250 step 10 yc=100 if (200-xc)>-49 then zc=200-(xc/2) hm=zc+10 fi setdispbuf draw draw = 1-draw setdrawbuf draw clear window setrgb 1,0,0,0 setrgb 2,0,0,0 gtriangle 450-xc,50 to 450-xc+200,50 to 450-xc,350 setrgb 1,255,255,255 text 50,75,"M I N E S W E E P E R" setrgb 1,0,0,255 line xc,yc to xc+zc,yc+zc line xc,yc+zc to xc+zc,yc setrgb 1,255,255,255 text xc+zc+10,yc+zc,"E A S Y" yc = yc+hm setrgb 1,255,0,0 circle xc+(zc/2),yc+(zc/2),(zc/2)+1 setrgb 1,255,255,255 text xc+zc+10,yc+zc,"M E D I U M" yc = yc+hm setrgb 1,0,255,0 triangle xc+(zc/2),yc to xc,yc+zc to xc+zc,yc+zc setrgb 1,255,255,255 text xc+zc+10,yc+zc,"H A R D" yc = yc+hm setrgb 1,255,100,100 rectangle xc,yc to xc+zc,yc+zc setrgb 1,255,255,255 text xc+zc+10,yc+zc,"H E L P" next xc repeat if (and(peek("port1"),cr)>0) then clear window setdispbuf 1 clear window easy() startgame() done = 1 elsif (and(peek("port1"),ci)>0) then clear window setdispbuf 1 clear window medium() startgame() elsif (and(peek("port1"),tr)>0) then clear window setdispbuf 1 clear window hard() startgame() elsif (and(peek("port1"),ci)>0) then clear window setdispbuf 1 clear window help() fi until(done = 1) end sub sub easy() xsize = 8 ysize = 8 rangen(xsize,ysize,10,grid()) difficulty = 1 end sub sub medium() xsize = 16 ysize = 16 rangen(xsize,ysize,40,grid()) difficulty = 2 end sub sub hard() xsize = 30 ysize = 16 rangen(xsize,ysize,99,grid()) difficulty = 3 end sub sub help() scr_width = 450 scr_height = 450 win_x = 95 win_y = 31 l_margin = 20 r_margin = 20 t_margin = 20 b_margin = 20 text$ = "MineSweeper is a game of skill. The aim is to work your way through a grid. In that grid there is a certain number of mines, 10 on Easy, 40 on Medium, 99 on Hard. At the begining all the squares are covered up. You then have to uncover them all by selecting them with the X button. That will reveal a number. That number tells you how many mines are in the 8 squares surrounding that square. If you have already uncovered some squares around that square it will give you a better idea of the squares that contain mines. If you are sure that a certain square contains a mine then you can select it with the Triangle button which marks that square and stops you from accidently selecting that square and being blown up. You can unmark a marked square by pressing Triangle on it. If you uncover a square that contains a mine you will be blown up. Squares that contain a mine have a 9 on them when uncovered. There are no second chances. If you succesfully uncover everysquare that does not contain a mine you win and will be given the time in took you to complete it. At first it might take a while to complete it but as you get better you will get quicker and could even get a compitition going with some friends. As you get more expirienced you will start to remember certain patterns of numbers and everytime you see that pattern you will know where the mines are. An example of one of these is 2 3 2 going along the side of a line of squares. Well thats about all you need to know to play MineSweeper. Good luck, you'll need it." p_count = 1 while(len(text$)>0) setrgb 0,0,0,0 clear window setrgb 1,220,220,220 setrgb 2,220,220,220 setrgb 3,100,100,100 gtriangle win_x,win_y to win_x,win_y+scr_height to win_x+scr_width,win_y setrgb 1,100,100,100 gtriangle win_x+scrwidth,win_y to win_x,win_y+scr_height to win_x+scr_width,win_y+scr_height setrgb 1,50,0,0 text$ = TextEx$(text$,1,win_x+l_margin,win_y+r_margin,scr_width-(r_margin+l_margin),scr_height-(t_margin+b_margin),10,15) pagenr$ = "Page "+str$(p_count) setrgb 1,0,0,0 text win_x+scr_width-(len(pagenr$)*10)-5,win_y+scr_height-5,pagenr$ wait 0.1 inkey$ p_count = p_count+1 wend menu() end sub sub rangen(xsize,ysize,totmines,grid()) redim grid(xsize,ysize) repeat x = int(ran(xsize)+1) y = int(ran(ysize)+1) if grid(x,y)<1 then grid(x,y) = grid(x,y)+1 num_mines = num_mines+1 fi until(num_mines=totmines) for y=1 to ysize for x=1 to xsize xx = (max((x-1),1)) yy = (max((y-1),1)) if grid(xx,y)>=1 then grid(x,y) = grid(x,y)+0.1 fi if grid(x,yy)>=1 then grid(x,y) = grid(x,y)+0.1 fi xx = (min((x+1),xsize)) yy = (min((y+1),ysize)) if grid(xx,y)>=1 then grid(x,y) = grid(x,y)+0.1 fi if grid(x,yy)>=1 then grid(x,y) = grid(x,y)+0.1 fi tl = 1 ts = 1 bl = 1 br = 1 if x=1 then tl = 0 bl = 0 fi if x=xsize then ts = 0 br = 0 fi if y=1 then tl = 0 ts = 0 fi if y=ysize then bl = 0 br = 0 fi if tl=1 then if grid(x-1,y-1)>=1 then grid(x,y) = grid(x,y)+0.1 fi fi if ts=1 then if grid(x+1,y-1)>=1 then grid(x,y) = grid(x,y)+0.1 fi fi if bl=1 then if grid(x-1,y+1)>=1 then grid(x,y) = grid(x,y)+0.1 fi fi if br=1 then if grid(x+1,y+1)>=1 then grid(x,y) = grid(x,y)+0.1 fi fi if grid(x,y)>=1 then grid(x,y) = 9 fi next next for y=1 to ysize for x=1 to xsize if grid(x,y)>0 and grid(x,y)<1 then grid(x,y) = grid(x,y)*10 fi next next return grid() end sub sub TextEx$(text$,justify,win_x,win_y,width,height,char_spacing,line_spacing) ch_p_line = width/char_spacing avail_lines = int(height/line_spacing)+1 L = 1 while (len(text$)>ch_p_line and avail_lines>L) sp_index = ch_p_line c$ = mid$(text$,sp_index,1) if c$<>" " and c$<>"-" then while (c$<>" " and c$<>"-") c$ = mid$(text$,sp_index,1) sp_index = sp_index-1 wend else sp_index = sp_index-1 fi line$ = mid$(text$,0,sp_index+1) if justify=1 then j_char_spacing = width/len(line$) j_char_spacing = j_char_spacing + ((j_char_spacing-10)/len(line$)) else j_char_spacing = char_spacing fi for c=1 to len(line$) text (c-1)*j_char_spacing+win_x,L*line_spacing+win_y,mid$(text$,c,1) next text$ = mid$(text$,len(line$)+2,len(text$)-len(line$)+2) L = L+1 wend if L=avail_lines then return text$ else for c=1 to ch_p_line text (c-1)*char_spacing+win_x,L*line_spacing+win_y,mid$(text$,c,1) next fi end sub sub startgame() setdrawbuf 0 clear window setdrawbuf 1 clear window if difficulty = 1 then lrboarder = 230 tbboarder = 166 totmines = 10 elsif difficulty = 2 then lrboarder = 150 tbboarder = 86 totmines = 40 elsif difficulty = 3 then lrboarder = 10 tbboarder = 86 totmines = 99 fi for y=1 to ysize for x=1 to xsize setrgb 1,255,255,255 rectangle lrboarder+(20*x),tbboarder+(20*y) to lrboarder+(20*x)+20,tbboarder+(20*y)+20 setrgb 1,100,100,100 fill rectangle lrboarder+(20*x)+2,tbboarder+(20*y)+2 to lrboarder+(20*x)+18,tbboarder+(20*y)+18 next next setrgb 1,0,110,110 fill rectangle lrboarder+22,tbboarder+22 to lrboarder+38,tbboarder+38 numa = token(time$,speeda(),"-") gameloop() end sub sub gameloop() dim gridinfo(xsize,ysize) xpos = 1 ypos = 1 oldxpos = 1 oldypos = 1 repeat pressx = 0 presstri = 0 emptysquares = 0 wait 0.1 if (and(peek("port1"),l)>0) then xpos = (max((xpos-1),1)) elsif (and(peek("port1"),r)>0) then xpos = (min((xpos+1),1)) elsif (and(peek("port1"),u)>0) then ypos = (max((ypos-1),1)) elsif (and(peek("port1"),d)>0) then ypos = (min((ypos+1),1)) elsif (and(peek("port1"),cr)>0) then pressx = 1 elsif (and(peek("port1"),tr)>0) then presstri = 1 fi if xpos<>oldxpos or ypos<>oldypos then setrgb 1,100,100,100 fill rectangle lrboarder+(20*oldxpos)+2,tbboarder+(20*oldypos)+2 to lrboarder+(20*oldxpos)+18,tbboarder+(20*oldypos)+18 setrgb 1,0,110,110 fill rectangle lrboarder+(20*xpos)+2,tbboarder+(20*ypos)+2 to lrboarder+(20*xpos)+18,tbboarder+(20*ypos)+18 if gridinfo(oldxpos,oldypos)=1 then setrgb 1,0,0,0 text lrboarder+(20*oldxpos)+15,tbboarder+(20*oldypos)+15,str$(grid(oldxpos,oldypos)),"cc" fi if gridinfo(oldxpos,oldypos)=2 then setrgb 1,200,0,0 fill triangle lrboarder+(20*oldxpos)+2,tbboarder+(20*oldypos)+2 to lrboarder+(20*oldxpos)+2,tbboarder+(20*oldypos)+18 to lrboarder+(20*oldxpos)+18,tbboarder+(20*oldypos)+18 fi fi if pressx=1 then if gridinfo(xpos,ypos)<>2 then setrgb 1,0,0,0 text lrboarder+(20*xpos)+15,tbboarder+(20*ypos)+15,str$(grid(xpos,ypos)),"cc" gridinfo(xpos,ypos) = 1 if grid(xpos,ypos)=0 then opensquares(xpos,ypos) fi if grid(xpos,ypos)=9 then numb = token(time$,speedb(),"-") setrgb 1,100,0,0 for y=1 to ysize for x=1 to xsize if grid(x,y)=9 then text lrboarder+(20*x)+15,tbboarder+(20*y)+15,str$(grid(x,y)),"cc" fi next next delay = 1.4 repeat beep wait delay delay = delay-0.04 until(delay<0) clear window setrgb 1,255,50,50 text 320,256,"B O O M ! ! !","cc" text 320,277,"T r y h a r d e r n e x t t i m e","cc" text 320,298,"Y o u l o s t i n : "+str$((val(speedb$(4))-val(speeda$(4))))+" s e c o n d s ! !","cc" wait 5 finnished = 1 fi if finnished<>1 then for y=1 to ysize for x=1 to xsize if grid(x,y)<>9 and gridinfo(x,y)=1 then emptysquares = emptysquares + 1 fi next next if emptysquares=((xsize*ysize)-totmines) then numb = token(time$,speedb$(),"-") setrgb 1,0,150,150 wait 1 clear window text 320,256,"C O N G R A T U L A T I O N S ! !","cc" text 320,277,"Y o u a r e a s u c c e s f u l M i n e S w e e p e r","cc" text 320,298,"Y o u w o n i n : "+str$((val(speedb$(4))-val(speeda$(4))))+" s e c o n d s ! !","cc" wait 5 finnished = 1 fi fi fi if presstri=1 then if gridinfo(xpos,ypos)=0 then setrgb 1,200,0,0 fill triangle lrboarder+(20*xpos)+2,tbboarder+(20*ypos)+2 to lrboarder+(20*xpos)+2,tbboarder+(20*ypos)+18 to lrboarder+(20*xpos)+18,tbboarder+(20*ypos)+18 gridinfo(xpos,ypos) = 2 elsif gridinfo(xpos,ypos)=2 then setrgb 1,0,110,110 fill triangle lrboarder+(20*xpos)+2,tbboarder+(20*ypos)+2 to lrboarder+(20*xpos)+2,tbboarder+(20*ypos)+18 to lrboarder+(20*xpos)+18,tbboarder+(20*ypos)+18 gridinfo(xpos,ypos) = 0 fi fi oldxpos = xpos oldypos = ypos until(finnished = 1) end sub sub opensquares(xpos,ypos) local tl tl = 1 local ts ts = 1 local bl bl = 1 local br br = 1 local t t = 1 local b b = 1 local p p = 1 local s s = 1 if x=1 then tl = 0 p = 0 bl = 0 fi if x=xsize then ts = 0 s = 0 br = 0 fi if y=1 then tl = 0 t = 0 ts = 0 fi if y=ysize then bl = 0 b = 0 br = 0 fi if tl=1 then text lrboarder+(20*xpos-1)+15,tbboarder+(20*ypos-1)+15,str$(grid(xpos-1,ypos-1)),"cc" gridinfo(xpos-1,ypos-1) = 1 fi if ts=1 then text lrboarder+(20*xpos+1)+15,tbboarder+(20*ypos-1)+15,str$(grid(xpos+1,ypos-1)),"cc" gridinfo(xpos+1,ypos-1) = 1 fi if bl=1 then text lrboarder+(20*xpos-1)+15,tbboarder+(20*ypos+1)+15,str$(grid(xpos-1,ypos+1)),"cc" gridinfo(xpos-1,ypos+1) = 1 fi if br=1 then text lrboarder+(20*xpos+1)+15,tbboarder+(20*ypos+1)+15,str$(grid(xpos+1,ypos+1)),"cc" gridinfo(xpos+1,ypos+1) = 1 fi if t=1 then text lrboarder+(20*xpos)+15,tbboarder+(20*ypos-1)+15,str$(grid(xpos,ypos-1)),"cc" gridinfo(xpos,ypos-1) = 1 fi if b=1 then text lrboarder+(20*xpos)+15,tbboarder+(20*ypos+1)+15,str$(grid(xpos,ypos+1)),"cc" gridinfo(xpos,ypos+1) = 1 fi if p=1 then text lrboarder+(20*xpos-1)+15,tbboarder+(20*ypos)+15,str$(grid(xpos-1,ypos)),"cc" gridinfo(xpos-1,ypos) = 1 fi if s=1 then text lrboarder+(20*xpos+1)+15,tbboarder+(20*ypos)+15,str$(grid(xpos+1,ypos)),"cc" gridinfo(xpos+1,ypos) = 1 fi end sub