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

Username:   Password: 
 RegisterRegister   
 Help, MineSweeper!!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
B-Man 31




PostPosted: 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]
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
B-Man 31




PostPosted: 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
Tony




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




PostPosted: 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
Tony




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
B-Man 31




PostPosted: Wed Apr 01, 2009 3:53 pm   Post subject: Re: Help, MineSweeper!!

no, cuz i need 99 mines
Tony




PostPosted: Wed Apr 01, 2009 3:55 pm   Post subject: RE:Help, MineSweeper!!

but you are changing the same mx variable 99 times.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
B-Man 31




PostPosted: 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?
Tony




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
B-Man 31




PostPosted: 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
corriep




PostPosted: 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
Tony




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




PostPosted: 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
B-Man 31




PostPosted: 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)
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 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: