Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Few questions about minesweeper
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
31201558




PostPosted: Sun Dec 26, 2010 10:40 pm   Post subject: 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
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


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
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Dec 26, 2010 11:25 pm   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: Mon Dec 27, 2010 3:03 pm   Post subject: 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




PostPosted: Mon Dec 27, 2010 3:46 pm   Post subject: 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




PostPosted: Mon Dec 27, 2010 3:51 pm   Post subject: 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




PostPosted: Mon Dec 27, 2010 11:25 pm   Post subject: 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




PostPosted: Tue Dec 28, 2010 12:23 am   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TokenHerbz




PostPosted: Tue Dec 28, 2010 10:02 am   Post subject: 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.

Turing:

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!
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Tue Dec 28, 2010 10:20 am   Post subject: 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




PostPosted: Tue Dec 28, 2010 1:13 pm   Post subject: RE:Few questions about minesweeper

I was thinking of a more general case, without the
Quote:

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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: Tue Dec 28, 2010 2:31 pm   Post subject: 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




PostPosted: Tue Dec 28, 2010 2:35 pm   Post subject: RE:Few questions about minesweeper

check out the function signature for Draw.Text. The "amount" has to be a string, not an integer.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
31201558




PostPosted: Tue Dec 28, 2010 3:59 pm   Post subject: 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




PostPosted: Tue Dec 28, 2010 4:31 pm   Post subject: 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




PostPosted: Wed Dec 29, 2010 4:21 pm   Post subject: 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?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 42 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: