NaaLaa
Bomb Sweeper - N5 to N7 - Printable Version

+- NaaLaa (https://www.naalaa.com/forum)
+-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html)
+--- Forum: NaaLaa 7 Code (https://www.naalaa.com/forum/forum-4.html)
+--- Thread: Bomb Sweeper - N5 to N7 (/thread-14.html)



Bomb Sweeper - N5 to N7 - Marcus - 11-25-2023

I found the source code of a minsweeper game on a backup drive. I think it's for n5, but it might be even older than that. It's a short program, so translating it line by line to n7 only took me a couple of minutes. As with the Robowack translation, this code doesn't take advantage of the new stuff in n7. The original n5 source code is included.


RE: Bomb Sweeper - N5 to N7 - 1micha.elok - 11-30-2023

(11-25-2023, 08:14 AM)Marcus Wrote: I found the source code of a minsweeper game on a backup drive. I think it's for n5, but it might be even older than that. It's a short program, so translating it line by line to n7 only took me a couple of minutes. As with the Robowack translation, this code doesn't take advantage of the new stuff in n7. The original n5 source code is included.

The minesweeper game is an old memory for me. At that time, I was still a highschool student playing the minesweeper in Windows 3.1 ( ? ). After 35 years, finally I have known how to code the minesweeper  Big Grin Big Grin Big Grin ... It's time to study the logic of this game in 4-8 weeks to come and how to always win  Cool  ... The shortest way to always win is by detecting the bomb when I click the left mouse and directly put a flag  Tongue Tongue Tongue

Code:
' ================
'  MAIN PROGRAM
' ================
do
    ' Transform from mouse to field coordinates.
    xm = int(mousex()/16)
    ym = int(mousey()/16)

    ' Left Button Mouse
    if mousebutton(0, true)
        if HasBomb(xm, ym)
            PutFlag(xm,ym) 'You always win
        else
            Sweep(xm, ym)
        endif
        RedrawGrid()
    endif
               
    'ESC to quit
     if keydown(KEY_ESCAPE) then end
     wait 1
     redraw
loop



RE: Bomb Sweeper - N5 to N7 - Marcus - 11-30-2023

Best solution ever Big Grin


RE: Bomb Sweeper - N5 to N7 - 1micha.elok - 12-13-2023

(11-25-2023, 08:14 AM)Marcus Wrote: I found the source code of a minsweeper game on a backup drive. I think it's for n5, but it might be even older than that. It's a short program, so translating it line by line to n7 only took me a couple of minutes. As with the Robowack translation, this code doesn't take advantage of the new stuff in n7. The original n5 source code is included.

The source code is very useful. Here is attached an e-book entitled [ Bombsweeper for Dummy.pdf ]. It was my journey to understand your source code of Bomb Sweeper. I documented a step by step tutorial from scratch when I rewrote the code (and sometimes I looked back at your source code when I forgot some lines ) :

Step 1. Make a skeleton of the program, i.e : Initialization, Main Program, Functions Collection
Step 2. Make a simple grid as a platform for Bomb Field
Step 3. Add bombs randomly inside the Bomb Field
Step 4. Detect a cell with a bomb
Step 5. Calculate number of close bombs for each cell
Step 6. Mark the bomb when you press mouse button
Step 7. May be next time ....  Big Grin

Let's the fun begin !

Thanks a lot, Marcus  Smile