
-----------------------------------
31201558
Sun Dec 26, 2010 10:40 pm

Few questions about minesweeper
-----------------------------------
What is it you are trying to achieve?
Homework from school     Teacher wants us to make a game       We just finished one semester      so I'm not that good or pro as you do     please do not use some code that's hard to be understood      you can use some hard code      but easy to understand
What is the problem you are having?
(my code is underneath)
1)  The biggest problem I'm having right now is : how to make the number "2" appear when I click an area that have two of the green(mine area) are beside one box.   I think if you answered this     I can make the etcetera myself
2)  A another one: how can I finish the program by winning (found all the mines)
3) How would I make a number clock keep on going in second on the top left corner.
4) No idea how to draw a flag in the middle of green (mine box).   
5) When I was indenting the code. It won't let me      a box appear says "not enough memory to indent file"
Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




var mx, my, mb, font : int
var x, y : array 1 .. 10 of int
var dead := false
setscreen ("graphics:max,max")
buttonchoose("multibutton")
for i : 1 .. 10
    x (i) := Rand.Int (0, maxx - 40)
    y (i) := Rand.Int (0, maxy - 40)
    x (i) := x (i) - x (i) mod 40
    y (i) := y (i) - y (i) mod 40
end for
for x1 : 0 .. maxx - 40 by 40
    for y1 : 0 .. maxy - 40 by 40
        drawfillbox (x1, y1, x1 + 38, y1 + 38, 7)
    end for
end for
loop
    font := Font.New ("serif:36")
    mousewhere (mx, my, mb)
    mx := mx - mx mod 40
    my := my - my mod 40
    locate (1, 1)
    put mx : 4, my : 4 ..
    for i : 1 .. 10
        drawfillbox (x (i) + 1, y (i) + 1, x (i) + 37, y (i) + 37, 10)
        if  mx = x (i) and  my = y (i) and mb = 1 then
            dead := true
        elsif mx = x (i) + 40 and my = y (i) + 40 and mb = 1 or mx = x (i) - 40 and my = y (i) + 40 and mb = 1 or mx = x (i) + 40 and my = y (i) - 40 and mb = 1 or mx = x (i) - 40 and my = y (i) - 40 and mb = 1 or mx = x (i) and my = y (i) + 40 and mb = 1 or mx = x (i)  and my = y (i) - 40 and mb = 1 or mx = x (i) + 40 and my = y (i)  and mb = 1 or mx = x (i) - 40 and my = y (i)  and mb = 1 then
            Draw.Text ("1", mx, my, font, white)
            %it only appears on the corner of the green   I know it's because of the mod but how to solve it.
    elsif mx=x(i) and my = y(i) and mb=100 then
    drawfillbox(mx-1,my-5,mx+1,my+5,7)
for n:0..10 by 1
for n1:0..6 by 1
for n2:0..12 by 1
drawline(mx-1,my+n2,mx+9-n,my+10+n1,4)
end for
end for
end for
end if            
end for
    if dead then
        Pic.ScreenLoad ("images.jpg", 0, 0, picCopy)
    end if
    exit when dead
end loop



Please specify what version of Turing you are using


-----------------------------------
Tony
Sun Dec 26, 2010 11:25 pm

RE:Few questions about minesweeper
-----------------------------------
You know where all the mines are. You can figure out how many of those mines are next to any one cell.

The winning is typically defined as "opening all cells that are not mines".

3) are you asking about the time or positioning of it?

4) once again, which part are you asking about: positioning, drawing the shape, etc?

5) I would guess that this happens when any particular line has too many elements on it.

-----------------------------------
31201558
Mon Dec 27, 2010 3:03 pm

RE:Few questions about minesweeper
-----------------------------------
You've only answered question 5..... which is a question not even related to my program

I think you are trying to hint me or something.  But I'm really strugling here.   I said that I only took one semeter.  I'm not good enough to make it your way by myself. Would you please show me some code or something?

Or you don't understand my question? I' ll repeat them in your way.

1) But how?

2) Yes what your are saying is right   but it's for the windows minesweeper    My minesweeper sucks     I'm not pro enough to do anything like that     Did you try my program?   You'll see what I MEAN.   YOU can't really open anything.   so I'll just make it so that it finishes when all the mines boxes have a flag on it.

3) I'm asking that in Windows minesweeper on the top left corner there is a clock keep on going. I want to make that clock.

4) Once you tried my program    You'll know that when you right click one of the green box the flag only appears on one corner of a green box      I know it 's because of the mod     But I've got no idea how to fix it       How would make it in the middle?

-----------------------------------
31201558
Mon Dec 27, 2010 3:46 pm

RE:Few questions about minesweeper
-----------------------------------
Ok I messed up.

First time ask a question online  please forgive me

For question 2 please tell me what to do

I tried this to open all cells that are not mines:

I changed the font colour of the numbers from white to black

I added some code

elsif mx > x (i) + 80 and my > y (i) + 80 and mb = 1 or mx < x (i) - 80 and my > y (i) + 80 and mb = 1 or mx > x (i) + 80 and my < y (i) - 80 and mb = 1 or mx < x (i) - 80 and my < y (i) - 80 and mb = 1 or mx = x (i) and my > y (i) + 80 and mb = 1 or mx = x (i)  and my < y (i) - 80 and mb = 1 or mx > x (i) + 80 and my = y (i)  and mb = 1 or mx < x (i) - 80 and my = y (i)  and mb = 1 then 
    drawfillbox(mx,my,mx+38,my+38,0)

The problem is  when I click on a cell that has mines beside them. The number "1" some times appear and sometimes not. Please just tell me what to do. Not what's wrong with it. I basicly knows everything I did wrong. But no idea how to fix it.

Just forget about question #4

-----------------------------------
TokenHerbz
Mon Dec 27, 2010 3:51 pm

RE:Few questions about minesweeper
-----------------------------------
okay first thing is first. 

in order to solve each tile, we have to check the areas around that square.

lets assume all the values start at ZERO.
for each time we check the mine tile, we check around that time, and every one of those tiles get a +1 because its near a mine.  So if there are 2 mines side by side, if that tile that was +1 from zero from mine 1, will get another +1 making it a +2 from the 2nd mine.

so code wise, you want to run threw your tiles row,columns and check for mines, if ones found you want to search all grid tiles around that 1 tile, making that 0 value +1. make sure you exclude the mine tiles.

Now, Dont worry about the cutesy things like score/timers etc yet. Lets get your main program working first. its worth more marks for sure.

to draw something in the middle of your mine, you need to know a few things.  one being the SIZE of your mine tile. then from there we can just position the "?" or picture to draw over that mine at the location of that mine (x,y) and center it using the size of that tile.
ex: Draw.Oval(tileX5 + (tileXsize div 2),tileY5 + (tileYsize div 2), size of oval(or pic x, and Y) etc.

Tony covered the Q5, lets see what else i see here, hmmz, ahh yes, To know that you "beat" the game, you need to uncover or "know" all the tiles.  so you uncover all the NON MINE TILES and you win.  otherwise i guess you could also add, if you "FLAG ALL CORRECT MINES" you win to, im not sure the correct real minesweeper winning terms, but its a simple check to see, and if it is then you exit your main loop displaying the correct results of losing/winning.

ALSO: Please don't jump to this part yet, as your currect program needs the effort here, but what your looking for is the "" Time.Elapsed "" feature of turing. this returns back the amount if miliseconds since the program started to run, so with some math, you can get your "seconds" "mins" "hours" etc from it.

basic setup would be to decalre your time variable to use like
var game_time : int
then in your loop have it check each time and update your game_time like this
game_time := Time.Elapsed --this returns MILISECONDS

do some math here and you can display it.
ex: instead of showing 70seconds. make it go 1MIN and 10seconds. 

I guess thats all you need im pretty sure to get a heads start. if you need more assistance feel free to post, i want to see some effort code first!

GOOD LUCK!

-----------------------------------
31201558
Mon Dec 27, 2010 11:25 pm

RE:Few questions about minesweeper
-----------------------------------
TokenHerbz

Your answers for Q1,Q2 AND Q3 are helpful

Could you please answer question 1 for me by showing me some code?

Just to make sure if you know what I'm asking.

You see that my codes are made so that when you click a cell that has one mine tile beside it the number"1" will appear.  But if there's a cell that has two mine tiles beside it. The number appear is still "1". How can I make it to "2".

-----------------------------------
Tony
Tue Dec 28, 2010 12:23 am

RE:Few questions about minesweeper
-----------------------------------
If there are at least 2 mines around a cell, then there is also at least 1 mine around the same cell. That should be enough of a hint to address your particular code flow.

The code could be much simpler than you are going for right now -- you don't care where the mines around the cell are, just the number of them. There's an 8 or 9 cell block (@TokenHerbz -- you actually don't have to exclude the center block itself; if there's a mine, the player loses before that number shows up), you just care about how many mines are in that set. Count them.

-----------------------------------
TokenHerbz
Tue Dec 28, 2010 10:02 am

RE:Few questions about minesweeper
-----------------------------------
i suppose i could, i make a program but then i realized, "Maybe i shouldn't of done so with classes" lol -> heres some code tho, the idea is the same, so i think should be usefull.


proc SOLVE
    var amount : int := 0
    for r : 2 .. ROWS - 1 %these 2 fors are my extended grid (as i mentioned to do above)
        for c : 2 .. COLUMNS - 1
            if grid (r, c) -> is_a_mine = false then (we need VALUES for NON MINES)
                for cr : r - 1 .. r + 1  %these 2 fors CHECKS around each NON MINE value, 
                    for cc : c - 1 .. c + 1
                        if grid (cr, cc) -> is_a_mine = true then    %if theres a mine around this tile, number goes UP
                            amount += 1
                        end if
                    end for
                end for
                grid (r, c) -> setValue (amount)  %the number we end up with is the amount of that TILE
                amount := 0
            end if
        end for
    end for
end SOLVE
%%Please note: r, c = row column
%%Please note: cr, cc = check row, check columns.
SOLVE


010
2X0
001
-------> See the X is the tile, -1 .. 1 goes top to bottom, left to right of that X when used like it is in the above.  It's important to grow your array (use blank /NIL values) **Turing dont support NIL tho** for your grids extra border so that this check wont error when checking say, your first TILE.  instead of it going -1 of its 1st tile and going ERROR, it goes, 0,1,2 -- 1,2 being your game tiles, 0 being the buffer NIL space to let it work, if that makes sense lol... i hope it does. let me know.
After we SOLVE THE GRID, we have all our info we need, so we check the tiles thats checked to see what we display or happens.

EDIT: ADDED COMMENTS TO MY CODE TO HELP EXPLAIN IT FOR YOU!

-----------------------------------
TokenHerbz
Tue Dec 28, 2010 10:20 am

RE:Few questions about minesweeper
-----------------------------------
@Tony - I did it anyways tho to show it after if its what your saying im thinking is the same thing.

-----------------------------------
Tony
Tue Dec 28, 2010 1:13 pm

RE:Few questions about minesweeper
-----------------------------------
I was thinking of a more general case, without the

if grid (r, c) -> is_a_mine = false

but since you're using the same data structure for both the mines and the counters, that check is required. Still, you have clear 3x3 for-loops for the counter, so I approve.

-----------------------------------
31201558
Tue Dec 28, 2010 2:31 pm

RE:Few questions about minesweeper
-----------------------------------
I see what you are doing 

But once you got the number "amount" how would I out put that number. 

I mean : if mx = x (i) + 40 and my = y (i) + 40 and mb = 1 or mx = x (i) - 40 and my = y (i) + 40 and mb = 1 or mx = x (i) + 40 and my = y (i) - 40 and mb = 1 or mx = x (i) - 40 and my = y (i) - 40 and mb = 1 or mx = x (i) and my = y (i) + 40 and mb = 1 or mx = x (i)  and my = y (i) - 40 and mb = 1 or mx = x (i) + 40 and my = y (i)  and mb = 1 or mx = x (i) - 40 and my = y (i)  and mb = 1 then 

then what?  Draw.Text?

Is it something like:
Draw.Text(amount,mx,my,font,colour)

That's what I was asking in Q3. I just want to make a number keep on going by 1 by using the Draw.Text code

Is it something like:
var font:int
font := Font.New ("serif:36")
for x:0..999 by 1
Draw.Text(x,1,maxy-36,font,7)

Well, of course it doesn't work this way

but what can I do to make it work

-----------------------------------
Tony
Tue Dec 28, 2010 2:35 pm

RE:Few questions about minesweeper
-----------------------------------
check out the function signature for [tdoc]Draw.Text[/tdoc]. The "amount" has to be a string, not an integer.

-----------------------------------
31201558
Tue Dec 28, 2010 3:59 pm

RE:Few questions about minesweeper
-----------------------------------
How many times do I have to say this    

I know what's wrong with my program

But I'm not pro enough to fix the problem I have.

If Draw.Text doesn't work. Which code will?

Please tell me

-----------------------------------
jcollins1991
Tue Dec 28, 2010 4:31 pm

Re: Few questions about minesweeper
-----------------------------------
http://compsci.ca/holtsoft/doc/intstr.html

Tony told you what your problem was, there's a link to a function to solve it. You'll never be taught everything in class, sometimes you're gonna have to search google and language documentation for answers.

-----------------------------------
31201558
Wed Dec 29, 2010 4:21 pm

RE:Few questions about minesweeper
-----------------------------------
Never used a 2d array before

How can I use the 2d array for this?

If there is a tutorial   
where is it?

-----------------------------------
31201558
Wed Dec 29, 2010 4:28 pm

RE:Few questions about minesweeper
-----------------------------------
........


Never mind 

I found the tutorial

-----------------------------------
31201558
Wed Dec 29, 2010 5:34 pm

RE:Few questions about minesweeper
-----------------------------------
var counter : array 0 .. 16, 0 .. 16 of int    
for n : 0 .. 600 by 40
    for j : 0 .. 16
        for k : 0 .. 16
            var boxx : array 1 .. 15 of int := init (n)
            var boxy : array 1 .. 15 of int := init (n)
            drawfillbox (boxx (j), boxy (k), boxx (j) + 40, boxy (k) + 40, 7)
            counter (j, k) := 0
        end for
    end for
end for


Here's my code for my counter(it can count the mine around it) and to draw all the grid in minesweeper.

I'm trying to set all the cell's counter at 0

But I don't know how to set values for an array

Is that even possible?

-----------------------------------
Tony
Wed Dec 29, 2010 5:56 pm

RE:Few questions about minesweeper
-----------------------------------
First of all, I don't understand why you are even creating boxx and boxy arrays 4000+ times, but to answer your question regarding setting values for an (entire) array -- the error message you receive should be descriptive enough. If not, the correct question to ask would be about that particular message.

-----------------------------------
31201558
Wed Dec 29, 2010 8:13 pm

RE:Few questions about minesweeper
-----------------------------------
I guess I'm really bad at explain questions

The question I want to ask is how do I give values for each variables in my array

for n : 0 .. 540 by 40  %these are 15 numbers
var boxx : array 1 .. 15 of int := init (n)          %These are 15 variables
end for

see: for boxx(1) it value is 0, for boxx(2) it value is 40, for boxx(3) it value is 80. That's what I'm trying to do.

 In tutorial it says, var mensNames : array 1 .. 3 of string := init ( "Tom", "Dick", "Harry" )

I guess the init feature is for giving values to arrays.

-----------------------------------
31201558
Wed Dec 29, 2010 8:16 pm

RE:Few questions about minesweeper
-----------------------------------
The message says :

Compile time expression expected

-----------------------------------
31201558
Wed Dec 29, 2010 8:37 pm

RE:Few questions about minesweeper
-----------------------------------
Just make sure you saw both of my reply.....

-----------------------------------
Tony
Wed Dec 29, 2010 9:00 pm

RE:Few questions about minesweeper
-----------------------------------
One of the best skills you could pick up (and not just for programming) is the ability to ask the right questions. Takes time and practice though. The right questions will usually lead you to the correct documentation -- reading and interpreting that is the next important life skill to have.

The way [tdoc]init[/tdoc] works is that it initializes the entire array. In the example you've posted, there are 3 elements and so init has 3 values. 1st element gets 1st value, etc.

"Compile time expression expected" is telling you that the expression (the init statement) needs to be available at the compile time (all the values known at the time when you compile the program, not during the run-time).

To change the values in an array during the run-time, you'd have to do it one element at a time. For-loops are usually helpful.

-----------------------------------
TokenHerbz
Thu Dec 30, 2010 9:20 am

RE:Few questions about minesweeper
-----------------------------------
[code]
var numbers: array 1 .. 15 of int
for n: 1 .. 15
    numbers(n) := n * 40
    put numbers(n), " "..
end for
[/code]

-----------------------------------
31201558
Mon Jan 03, 2011 12:29 am

Re: Few questions about minesweeper
-----------------------------------
Here's my code now


var mx, my, mb, font : int
var dead := false
var cells : array 1 .. 9, 1 .. 9 of string
var value : array 1 .. 9, 1 .. 9 of int
var minex, miney : array 1 .. 10 of int
buttonchoose ("multibutton")
for a : 0 .. 320 by 40
    for b : 0 .. 160 by 20
        drawfillbox (a, b, a + 38, b + 38, 7)
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        cells (i, j) := "not mine"
        value (i, j) := 0
    end for
end for
%mines
for i : 1 .. 10
    minex (i) := Rand.Int (0, 359)
    miney (i) := Rand.Int (0, 359)
    minex (i) := minex (i) - minex (i) mod 40
    miney (i) := miney (i) - miney (i) mod 40
    drawdot (minex (i), miney (i), green)
end for
for i : 1 .. 9
    for j : 1 .. 9
        cells (minex (i) div 40, miney (i) div 40) := "mine"
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        if cells (i, j) = "mine" then
            if j + 1  0 then
                if cells (i - 1, j) not= "mine" then
                    value (i - 1, j) += 1
                end if
            end if
            if i - 1 > 0 and j + 1  0 then
            cells (i, j) := "num cells" + intstr (value (i, j))
        end if
    end for
end for

loop
    mousewhere (mx, my, mb)
    mx := mx - mx mod 40
    my := my - my mod 40
    for i : 1 .. 10
        if mx = minex (i) and my = miney (i) and mb = 1 then
            dead := true
        end if
    end for
    var a : int
    var b : int
    a := mx div 40
    b := my div 40
    if cells (a, b) = "num cells" and mb = 1 then
        font := Font.New ("serif:36")
        Draw.Text (intstr (value (a, b)), mx, my, font, red)
    end if
    if cells (a, b) = "not mine" and mb = 1 then
        drawfillbox (mx + 1, my + 1, mx + 37, my + 37, white)
    end if
    exit when dead
    delay (100)
end loop


When I run this it says "Array subscript is out of range. Why?

The code is have problem is : cells (minex (i) div 40, miney (i) div 40) := "mine"

Well, it's the midnight. The due time is 15 hours later. Please just tell me the answer completely( Please just give me some code and tell me where do I put it. I know this is not good, but.... I've got no time.....)

-----------------------------------
Tony
Mon Jan 03, 2011 12:47 am

RE:Few questions about minesweeper
-----------------------------------
You have 15 hours, that's plenty of time! Try
[code]
for i : 1 .. 9 
    for j : 1 .. 9 
        put "trying to access: ", minex (i) div 40, ", ", miney (i) div 40
        cells (minex (i) div 40, miney (i) div 40) := "mine" 
    end for 
end for 
[/code]

-----------------------------------
31201558
Mon Jan 03, 2011 1:00 am

RE:Few questions about minesweeper
-----------------------------------
I don't really understand

it just output lots of numbers

-----------------------------------
Tony
Mon Jan 03, 2011 1:12 am

RE:Few questions about minesweeper
-----------------------------------
Until it crashes. Then you know what number was out of array's bounds.

-----------------------------------
31201558
Mon Jan 03, 2011 1:29 am

RE:Few questions about minesweeper
-----------------------------------
but each time it's different

-----------------------------------
Tony
Mon Jan 03, 2011 1:31 am

RE:Few questions about minesweeper
-----------------------------------
What's the value of minex (i) ?

-----------------------------------
31201558
Mon Jan 03, 2011 1:33 am

RE:Few questions about minesweeper
-----------------------------------
Oh~~~~~    I see, but still don't know what to do. Should I change all the 1..9 to 0..8?

-----------------------------------
31201558
Mon Jan 03, 2011 1:35 am

RE:Few questions about minesweeper
-----------------------------------
I know I should not......

But what I need to do ?

-----------------------------------
Tony
Mon Jan 03, 2011 1:41 am

RE:Few questions about minesweeper
-----------------------------------
You need to make sure those values are in the same range as the array. Trace back to where the value comes from, and change your expressions to guarantee that the answer will be in a particular range of values.

-----------------------------------
31201558
Mon Jan 03, 2011 1:45 am

RE:Few questions about minesweeper
-----------------------------------
add one to both?

cells (minex (i) div 40+1, miney (i) div 40+1) := "mine"

-----------------------------------
Tony
Mon Jan 03, 2011 1:50 am

RE:Few questions about minesweeper
-----------------------------------
That will guarantee the low bound of 1, yes. It will also increase your upper bound value by 1 as well. Coincidentally this might still work, but I'll leave the prove of that up to you.

-----------------------------------
31201558
Mon Jan 03, 2011 2:01 am

Re: Few questions about minesweeper
-----------------------------------


var mx, my, mb, font : int
var dead := false
var cells : array 1 .. 10, 1 .. 10 of string
var value : array 1 .. 9, 1 .. 9 of int
var minex, miney : array 1 .. 10 of int
buttonchoose ("multibutton")
for a : 0 .. 320 by 40
    for b : 0 .. 320 by 40
        drawfillbox (a, b, a + 38, b + 38, 7)
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        cells (i, j) := "not mine"
        value (i, j) := 0
    end for
end for
%mines
for i : 1 .. 10
    minex (i) := Rand.Int (0, 359)
    miney (i) := Rand.Int (0, 359)
    minex (i) := minex (i) - minex (i) mod 40
    miney (i) := miney (i) - miney (i) mod 40
    drawfillbox (minex (i), miney (i),minex (i)+38,miney (i)+38 ,green)
end for
for i : 1 .. 10
        
        cells (minex (i) div 40+1, miney (i) div 40+1) := "mine" 
end for 
for i : 1 .. 9
    for j : 1 .. 9
        if cells (i, j) = "mine" then
            if j + 1  0 then
                if cells (i - 1, j) not= "mine" then
                    value (i - 1, j) += 1
                end if
            end if
            if i - 1 > 0 and j + 1  0 then
            cells (i, j) := "num cells" + intstr (value (i, j))
        end if
    end for
end for

loop
    mousewhere (mx, my, mb)
    mx := mx - mx mod 40
    my := my - my mod 40
    for i : 1 .. 10
        if mx = minex (i) and my = miney (i) and mb = 1 then
            dead := true
        end if
    end for
    var a : int
    var b : int
    a := mx div 40
    b := my div 40
    if cells (a, b) = "num cells" and mb = 1 then
        font := Font.New ("serif:36")
        Draw.Text (intstr (value (a, b)), mx, my, font, red)
    end if
    if cells (a, b) = "not mine" and mb = 1 then
        drawfillbox (mx + 1, my + 1, mx + 37, my + 37, white)
    end if
    exit when dead
    delay (100)
end loop



Yes, that problem has solved.

But my minesweeper is still a mess

Can you run this to see where my problem is?

Something gotta be wrong with the mousewhere...

-----------------------------------
Tony
Mon Jan 03, 2011 2:04 am

RE:Few questions about minesweeper
-----------------------------------
Same problem, "Array subscript is out of range". Turing tells you what line the problem is at. You can use the same trick with printing the values being used for indexes, to see when and with what value the bound is broken.

-----------------------------------
31201558
Mon Jan 03, 2011 2:05 am

RE:Few questions about minesweeper
-----------------------------------
You'll have to use F1 to run this because of the mousewhere.

Just in case you havn't noticed this

-----------------------------------
31201558
Mon Jan 03, 2011 2:12 am

RE:Few questions about minesweeper
-----------------------------------
I fixed it again.

And I noticed that anywhere that's suppose to have a number don't have one.

Why is this happening?

-----------------------------------
Tony
Mon Jan 03, 2011 2:18 am

RE:Few questions about minesweeper
-----------------------------------
Probably because "if cells (a, b) = "num cells" and mb = 1 then" is not true.

-----------------------------------
31201558
Mon Jan 03, 2011 2:26 am

RE:Few questions about minesweeper
-----------------------------------
Oh my god!!!!!!!!!!!!

It worked!!!!!!!!!!!

Thank you so much!!!!!!!!!!!!

Tony!!!!!!!!!!!!!!!!!!

I'll donate all my bits to you!!!!!!!!!!!!!!!

Well, some for token too......

-----------------------------------
Tony
Mon Jan 03, 2011 2:32 am

RE:Few questions about minesweeper
-----------------------------------
And with 13 hours to spare! Well done :)

-----------------------------------
31201558
Thu Jan 06, 2011 6:33 pm

Re: Few questions about minesweeper
-----------------------------------
Well, our teacher has lated the due date because he is so nice......

Therefore I now want to make the open multiboxes feature to work. 

I just notice that there's a flood fill algorithm to make it.

Here's my code:



var mx, my, mb, font : int
var dead := false
var cells : array 1 .. 10, 1 .. 10 of string
var value : array 1 .. 9, 1 .. 9 of int
var minex, miney : array 1 .. 10 of int
var totalTime : real := 0
buttonchoose ("multibutton")
for a : 0 .. 320 by 40
    for b : 0 .. 320 by 40
        drawfillbox (a, b, a + 38, b + 38, 7)
    end for
end for
for i : 1 .. 9
    for j : 1 .. 9
        cells (i, j) := "not mine"
        value (i, j) := 0
    end for
end for
%mines
for i : 1 .. 10
    minex (i) := Rand.Int (0, 359)
    miney (i) := Rand.Int (0, 359)
    minex (i) := minex (i) - minex (i) mod 40
    miney (i) := miney (i) - miney (i) mod 40
    drawfillbox (minex (i), miney (i), minex (i) + 38, miney (i) + 38, green)
end for
for i : 1 .. 10
    cells (minex (i) div 40 + 1, miney (i) div 40 + 1) := "mine"
end for
for i : 1 .. 9
    for j : 1 .. 9
        if cells (i, j) = "mine" then
            if j + 1  0 then
                if cells (i - 1, j) not= "mine" then
                    value (i - 1, j) += 1
                end if
            end if
            if i - 1 > 0 and j + 1  0 then
            cells (i, j) := "num cells" + intstr (value (i, j))
        end if
    end for
end for
loop
    mousewhere (mx, my, mb)
    mx := mx - mx mod 40
    my := my - my mod 40
    if mx < 0 then
        mx := 0
    elsif mx > 359 then
        mx := 359
    end if
    if my < 0 then
        my := 0
    elsif my > 359 then
        my := 359
    end if
    for i : 1 .. 10
        if mx = minex (i) and my = miney (i) and mb = 1 then
            dead := true
        end if
    end for
    var a : int
    var b : int
    a := mx div 40
    b := my div 40
    if cells (a + 1, b + 1) not= "num cells" and mx < 359 and my < 359 and mb = 1 then
        font := Font.New ("serif:36")
        Draw.Text (intstr (value (a + 1, b + 1)), mx, my, font, red)
    end if
    if cells (a + 1, b + 1) = "not mine" and mb = 1 then
        drawfillbox (mx + 1, my + 1, mx + 37, my + 37, white)
    end if
    locate (1, 1)
    totalTime := totalTime + 0.1
    put totalTime
    if totalTime = 999 then
        dead := true
    end if
    exit when dead
    delay (100)
end loop



The problem is, I don't think I got a reveal procedure. Will I still be able to make the flood fill without an reveal procedure?
