Liberty BASIC Community Forum
« Winter fun 2016 Minesweeper »

Welcome Guest. Please Login or Register.
Aug 16th, 2017, 10:42pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 sticky  Author  Topic: Winter fun 2016 Minesweeper  (Read 227 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5471
xx Winter fun 2016 Minesweeper
« Thread started on: Nov 1st, 2016, 04:21am »

This is a bit more of a challenge in that the entire game is relatively complex but well within Liberty BASIC v4.50's capabilities.

Here is a link to Minesweeper reference page. That's the game we want to see.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5471
xx Re: Winter fun 2016 Minesweeper
« Reply #1 on: Nov 3rd, 2016, 07:15am »

Some graphics if you need them, 30x30 pixel grid. Either getbmp and drawbmp the marker you need or create masked sprites, drawbmp should be sufficient.

http://gamebin.webs.com/Liberty/Mines.zip
User IP Logged

GaRPMorE
Senior Member
ImageImageImageImage


member is offline

Avatar

"Not everything that counts can be counted, and not everything that can be counted counts." - Albert Einstein


PM


Posts: 288
xx Re: Winter fun 2016 Minesweeper
« Reply #2 on: Nov 3rd, 2016, 4:49pm »

Created my own version years ago, the better to display the statistics I wanted. Gradually eliminated those grids in which only a lucky guess would win, and collected those which were most challenging.
User IP Logged

from the world according to GaRPMorE
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5471
xx Re: Winter fun 2016 Minesweeper
« Reply #3 on: Nov 5th, 2016, 09:48am »

This is a quick and dirty minesweeper using the graphics posted previously. They will need to be unzipped to the program folder.

It only serves to remind me how powerful and easy to use Liberty is.

It has bugs and I have to get the graphics sticking and some other stuff. I really would like to see alternative versions. Plain text, using my graphics, isometric! Lets see what you got.

OH! and if you can do it in less than the 170 lines of code I used I will be mightily impressed :)

Code:
    nomainwin
    ' find how much whitespace the windows scheme is taking
    ' Anatoly's tip
    WindowWidth = 200
    WindowHeight = 200
    open "Ajusting..." for graphics_nf_nsb as #1
    #1, "home ; down ; posxy w h"
    w=200-2*w : h = 200-2*h
    close #1


    ' setup a  420 x 440 graphics view
    ' the graphic box borders are just outside the window edge
    WindowWidth  = 420+w
    WindowHeight = 440+h
    UpperLeftX   = (DisplayWidth-WindowWidth)/2
    UpperLeftY   = (DisplayHeight-WindowHeight)/2
    graphicbox #1.g, 0,0,422,442
    open "Liberty Minesweeper" for window_nf as #1
    print #1, "trapclose [quit]"
    'visible drawing coordinates are 0 to 419 ie 420 pixels
    loadbmp "mrk","markers.bmp"
    #1.g "down ; drawbmp mrk"
    #1.g "getbmp sea 0 0 30 30"
    #1.g "getbmp nu0 30 0 30 30"
    #1.g "getbmp flg 60 0 30 30"
    #1.g "getbmp nu1 90 0 30 30"
    #1.g "getbmp nu2 120 0 30 30"
    #1.g "getbmp nu3 150 0 30 30"
    #1.g "getbmp nu4 180 0 30 30"
    #1.g "getbmp nu5 210 0 30 30"
    #1.g "getbmp nu9 240 0 30 30"
    #1.g "getbmp exp 270 0 30 30"
    loadbmp "bak","minefield.bmp"
    #1.g "drawbmp bak 0 0"
    dim grid(12,12)
    dim mine(12,12)
    'sow some random mines, watch out for same cell placement
    mines=20
    while mines>0
        c=int(rnd(0)*12+1)
        r=int(rnd(0)*12+1)
        if mine(c,r)<>9 then mine(c,r)=9 : mines=mines-1
    wend

    'now for each cell calculate how many mine neighbours
    for c=1 to 12
        for r=1 to 12
            'check surrounding cells
            'get cell range
            cmin=c-(c>1)
            cmax=c+(c<12)
            rmin=r-(r>1)
            rmax=r+(r<12)
            m=0
            for cc=cmin to cmax
                for rr=rmin to rmax
                    if cc=c and rr=r then [skip]
                    if mine(cc,rr)=9 then m=m+1
                    [skip]
                next
            next
            if mine(c,r)<>9 then mine(c,r)=m
            #1.g "drawbmp nu";mine(c,r);" ";c*30;" ";r*30
        next
    next

    'hide the board
    for c=1 to 12
        for r=1 to 12
            #1.g "drawbmp sea ";c*30;" ";r*30
            grid(c,r)=7
        next
    next

    'start event checking for mouse input
    #1.g "when leftButtonDown [leftclick]"
    #1.g "when rightButtonDown [rightclick]"
    wait


    [leftclick]
    'check the cell clicked
    c=int(MouseX/30)
    r=int(MouseY/30)
    'if we clicked on a flag do nothing
    if grid(c,r)=8 then wait
    'if we found a mine then boom!
    if mine(c,r)=9 then [boom]
    'if not a flag or a mine then draw what we found
    #1.g "drawbmp nu";mine(c,r);" ";c*30;" ";r*30
    'mark it played
    grid(c,r)=-1
    'if the cell is clear find other clear cell neighbours
    'I create a stack to remember the clear cells I find
    'not true recursion but it seeks out clear cells
    'and draws the bounding edge
    if mine(c,r)=0 then
        stackctr=1
        dim stack(144,2)
        stack(stackctr,1)=c
        stack(stackctr,2)=r
        while stackctr>0
            'check surrounding cells
            'get cell range
            cc=stack(stackctr,1)
            rr=stack(stackctr,2)
            stackctr=stackctr-1
            cmin=cc-(cc>1)
            cmax=cc+(cc<12)
            rmin=rr-(rr>1)
            rmax=rr+(rr<12)
            for cc=cmin to cmax
                for rr=rmin to rmax
                    if cc=c and rr=r then [skipit]
                    if grid(cc,rr)=-1 then [skipit]
                    if mine(cc,rr)<9 then
                        if mine(cc,rr)=0 then
                            stackctr=stackctr+1
                            stack(stackctr,1)=cc
                            stack(stackctr,2)=rr
                            #1.g "drawbmp nu0 ";cc*30;" ";rr*30
                        else
                            #1.g "drawbmp nu";mine(cc,rr);" ";cc*30;" ";rr*30
                        end if
                        'mark cell played
                        grid(cc,rr)=-1
                    end if
                    [skipit]
                next
            next
        wend
    end if

    'check for success
    'there should be no sea (7) left only flagged sea(8) and played cells (-1)
    failed=0
    for c= 1 to 12
        for r= 1 to 12
            if grid(c,r)=7 then failed=1
        next
    next
    if failed =0 then notice "Success"
    wait

    'set or unset warning flag
    [rightclick]
    c=int(MouseX/30)
    r=int(MouseY/30)
    if grid(c,r)=8 then
        #1.g "drawbmp sea ";c*30;" ";r*30
        grid(c,r)=7
    else
        if grid(c,r)=7 then
            #1.g "drawbmp flg ";c*30;" ";r*30
            grid(c,r)=8
        end if
    end if
    wait

    [boom]
    'stop event checking for mouse input
    #1.g "when leftButtonDown"
    #1.g "when rightButtonDown"
    for c=1 to 12
        for r=1 to 12
            if mine(c,r)=9 then #1.g "drawbmp exp ";c*30;" ";r*30
        next
    next
    notice "Game Over"
    wait

    [quit]
    close #1
    end

 
« Last Edit: Nov 5th, 2016, 12:19pm by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5471
xx Re: Winter fun 2016 Minesweeper
« Reply #4 on: Nov 5th, 2016, 09:57am »

One from Thomas coded a while ago.

http://alycesrestaurant.com/zips/minesweeper_tww.zip
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls