Computer Science Canada

Help, MineSweeper!!

Author:  B-Man 31 [ Tue Mar 31, 2009 10:11 pm ]
Post subject:  Help, MineSweeper!!

Im trying to make a minesweeper game for fun. but im having trouble getting the selected square to dissapear, any help will be appreciated. this is still in its very early stages.

Turing:

import GUI

var menuItem : array 1 .. 7 of int
var menuName : array 1 .. 7 of string := init ("New", "---", "Begginer", "Intermediate", "Expert", "---", "Quit")
var square, mines : array 1 .. 16, 1 .. 30 of int
var x, y, my, mx, file, Minesweeper, lineFrame : int := 0

Minesweeper := Window.Open ("position:25;150,title:Minesweeper EXTREME!,graphics:950,475,nobuttonbar")

GUI.SetBackgroundColor (8)
lineFrame := GUI.CreateFrame (12, 0, 936, 412, GUI.INDENT)
lineFrame := GUI.CreateFrame (12, 418, 936, 450, GUI.INDENT)

%Procedures
proc reveal
    GUI.Dispose (square (1, 1)) %THIS IS WHERE I NEED IT TO DISSAPEAR THE SELECTED BLOCK BUT I DONT KNOW HOW!!
end reveal

proc NewGame
end NewGame

proc doNothing
end doNothing

proc menuSelected
end menuSelected

%Boxes
x := 25
y := 7
for i : 1 .. 16
    for j : 1 .. 30
        square (i, j) := GUI.CreateButtonFull (x, y, 5, "", reveal, 5, "r", true)
        x += 30
    end for
    x := 25
    y += 25
end for

%Menu
file := GUI.CreateMenu ("Game")
menuItem (1) := GUI.CreateMenuItem (menuName (1), NewGame)
menuItem (2) := GUI.CreateMenuItem (menuName (2), doNothing)
menuItem (3) := GUI.CreateMenuItem (menuName (3), doNothing)
menuItem (4) := GUI.CreateMenuItem (menuName (4), doNothing)
menuItem (5) := GUI.CreateMenuItem (menuName (5), doNothing)
menuItem (6) := GUI.CreateMenuItem (menuName (6), doNothing)
menuItem (7) := GUI.CreateMenuItem (menuName (7), GUI.Quit)

%Mines
for i : 1 .. 99
    randint (mx, 1, 30)
    randint (my, 1, 16)
end for

loop
    exit when GUI.ProcessEvent
end loop

GUI.CloseWindow (Minesweeper)

[/syntax]

Author:  Tony [ Tue Mar 31, 2009 10:31 pm ]
Post subject:  RE:Help, MineSweeper!!

well your reveal procedure has no way of knowing what button the call came from. That sounds like a problem.

Are you sure that the GUI module is the best way to implement this?

Author:  B-Man 31 [ Tue Mar 31, 2009 10:36 pm ]
Post subject:  Re: Help, MineSweeper!!

No, i just thought it be easy is there any way of keeping it with the Gui, thx

Author:  Tony [ Wed Apr 01, 2009 1:32 am ]
Post subject:  RE:Help, MineSweeper!!

you'd have to read the documentation, to understand how the GUI module works. What it offers, and its limitations.

Also, what's up with this for loop?
code:

%Mines
for i : 1 .. 99
    randint (mx, 1, 30)
    randint (my, 1, 16)
end for

Author:  B-Man 31 [ Wed Apr 01, 2009 3:38 pm ]
Post subject:  Re: Help, MineSweeper!!

thats for 99 mines, it gives it a random X and y value for the placing

Author:  Tony [ Wed Apr 01, 2009 3:51 pm ]
Post subject:  RE:Help, MineSweeper!!

don't you think that having
code:

for i : 1 .. 1

would have the same net result?

Author:  B-Man 31 [ Wed Apr 01, 2009 3:53 pm ]
Post subject:  Re: Help, MineSweeper!!

no, cuz i need 99 mines

Author:  Tony [ Wed Apr 01, 2009 3:55 pm ]
Post subject:  RE:Help, MineSweeper!!

but you are changing the same mx variable 99 times.

Author:  B-Man 31 [ Wed Apr 01, 2009 3:56 pm ]
Post subject:  Re: Help, MineSweeper!!

right, i nevr realized that thks, i might make a type for the mines and boxes. that would help a lot i think. this si just the first time im actually using multi dimensional arrays, but, if i make a array of say
Turing:
type aBox
record
x,y :int
shown: boolean
end record

type aMine
record
mx, my :int
end record

var mines: array 1..16,1..30 of aMine
var box: array 1..16,1..30 of aBox


can i turn those into multi dimensional arrays?

Author:  Tony [ Wed Apr 01, 2009 4:10 pm ]
Post subject:  RE:Help, MineSweeper!!

you could have arrays of type, yes. (perhaps not flexible arrays... those have certain limitations).

Don't you think that the box should know if it has a mine inside of it?

Author:  B-Man 31 [ Wed Apr 01, 2009 4:12 pm ]
Post subject:  RE:Help, MineSweeper!!

yeah, that will come,im mainly concerned about making the right box dissapear right now, i only started this yesterday and i will continue

Author:  corriep [ Wed Apr 01, 2009 5:52 pm ]
Post subject:  Re: Help, MineSweeper!!

Tony wrote:

you could have arrays of type, yes. (perhaps not flexible arrays... those have certain limitations).
It works perfectly.
Turing:
type foo :
    record
        bar : string
    end record

var baz : flexible array 1 .. 4 of foo

% and to access an item it would be
put baz (1).bar

Author:  Tony [ Wed Apr 01, 2009 5:55 pm ]
Post subject:  RE:Help, MineSweeper!!

Oh, wait... you could have a flexible array of type, but you can't have type with a flexible array inside. Thx corriep.

Author:  saltpro15 [ Wed Apr 01, 2009 5:58 pm ]
Post subject:  RE:Help, MineSweeper!!

corriep, I think what Tony means is
Turing:

type foo:
record
bar : string
baz : flexible array 1..4 of foo
end record


I think you guys are going a little bit off topic with this though :p

Author:  B-Man 31 [ Wed Apr 01, 2009 8:53 pm ]
Post subject:  Re: Help, MineSweeper!!

i know about flexible arrays pretty well, i did some adjustments but the error that i get now I dont gat, if someone could explain this to me, that would be appreciated. This is it now:

Turing:

import GUI

type abox :
    record
        bX, bY : int
        shown : boolean
    end record

var menuItem : array 1 .. 7 of int
var menuName : array 1 .. 7 of string := init ("New", "---", "Begginer", "Intermediate", "Expert", "---", "Quit")
var square : array 1 .. 16, 1 .. 30 of abox
var x, y, file, Minesweeper, lineFrame : int := 0

Minesweeper := Window.Open ("position:25;150,title:Minesweeper EXTREME!,graphics:950,475,nobuttonbar")

GUI.SetBackgroundColor (8)
lineFrame := GUI.CreateFrame (12, 0, 936, 412, GUI.INDENT)
lineFrame := GUI.CreateFrame (12, 418, 936, 450, GUI.INDENT)

%Procedures
proc reveal (o : abox)
    square (o.bX, o.bY).shown := false
end reveal

proc drawBox (o : abox, shown : boolean)
    if o.shown then
        x := 25
        y := 7
        for i : 1 .. 16
            for j : 1 .. 30
                square (i, j) := GUI.CreateButtonFull (o.bX + x, o.bY + y, 5, "", reveal, 5, "", true)
                x += 30
            end for
            x := 25
            y += 25
        end for
    end if
end drawBox

proc NewGame
end NewGame

proc doNothing
end doNothing

proc menuSelected
end menuSelected



%Menu
file := GUI.CreateMenu ("Game")
menuItem (1) := GUI.CreateMenuItem (menuName (1), NewGame)
menuItem (2) := GUI.CreateMenuItem (menuName (2), doNothing)
menuItem (3) := GUI.CreateMenuItem (menuName (3), doNothing)
menuItem (4) := GUI.CreateMenuItem (menuName (4), doNothing)
menuItem (5) := GUI.CreateMenuItem (menuName (5), doNothing)
menuItem (6) := GUI.CreateMenuItem (menuName (6), doNothing)
menuItem (7) := GUI.CreateMenuItem (menuName (7), GUI.Quit)


drawBox

loop
    exit when GUI.ProcessEvent
end loop

GUI.CloseWindow (Minesweeper)

Author:  Dusk Eagle [ Wed Apr 01, 2009 10:04 pm ]
Post subject:  Re: Help, MineSweeper!!

Error #1: "Argument is the wrong type".
This error is caused because you are trying to pass a procedure (which by definition cannot represent a value) as a value to the CreateButtonFull procedure. You must first change the procedure to a function so that it returns a value, then you must pass an actual parameter to the "reveal" procedure, as it requires one. If you don't know what I'm talking about, I suggest you read the following tutorial on functions and procedures: Functions and Procedures. Once you've corrected your current errors, you may have more errors before your program will run, but that's for you to solve.

BTW - global variables are generally not a recommended programming practice - use parameters instead. Visit the link above to learn more.

Error #2: "Missing parameters in call to drawBox".
Again, see the link above for help in solving this problem.

Author:  Tony [ Wed Apr 01, 2009 10:40 pm ]
Post subject:  Re: Help, MineSweeper!!

Dusk Eagle @ Wed Apr 01, 2009 10:04 pm wrote:
Error #1: "Argument is the wrong type".
This error is caused because you are trying to pass a procedure (which by definition cannot represent a value) as a value to the CreateButtonFull procedure. You must first change the procedure to a function so that it returns a value...

He's not passing the result of a procedure, but a reference to procedure itself. Which is a legal type, and exactly what the GUI module expects.

The problem is that his procedure definition expects an argument. Which is not there. The GUI module was not build for calling procedures with arguments; although it might be possible to modify the framework to allow for that.


: