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

Username:   Password: 
 RegisterRegister   
 Grid
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
awesomej01




PostPosted: Sun Mar 07, 2004 12:28 am   Post subject: Grid

I have a minor project assigned to me and it happens to be a dice game. I plan to make a snakes and ladders program. The only thing that is stopping me is how to start. Do I plan out how many boxes I want in my grid first, then draw it as a background and then make a two dimensional array? Confused I would greatly appreciate it if anyone can help me make an example of a grid using two dimensional array so that I would know how to make one for my program.
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Sun Mar 07, 2004 12:39 am   Post subject: (No subject)

something like this?

code:
const width := 10
const size := 20

var grid : array 1 .. size, 1 .. size of int

for x : 1 .. size
    for y : 1 .. size
        grid (x, y) := Rand.Int (0, 1)
        if grid (x, y) = 1 then
            drawfillbox (x * width, y * width, x * width + width, y * width + width, 7)
        else
            drawbox (x * width, y * width, x * width + width, y * width + width, 7)
        end if
    end for
end for


what exactly do you need help with?

basically in the above example, i declare the constants of the grid, create an array which reflects these constants (ie size) and then i draw a random grid... rather than assigning a value between 1 and 0 and draw a black/white box, you could assign any number of values for each type of tile you want ie snake, ladder, lose a turn etc. then when the player lands on a square you check what type it is and make the appropiate actions happen.

-zylum
awesomej01




PostPosted: Sun Mar 07, 2004 11:42 am   Post subject: Grid

Okay from the grid that you posted, say I want to do something like when you click on the top right box of the grid, the program would say, "Lose a turn." How would I do that?
Paul




PostPosted: Sun Mar 07, 2004 11:49 am   Post subject: (No subject)

Use mouse.where for clicking,
ex:
code:

loop
Mouse.Where (x, y, z)
if x > 40 and x < 280 and y > maxy - 66 and y < maxy - 34 and z = 1 then
put "Loose a turn"
exit
end if
end loop

Cervantes




PostPosted: Sun Mar 07, 2004 1:27 pm   Post subject: (No subject)

its kinda confusing Paul when you have z as a variable... that makes us think 3d. z should really be renamed "button" or "btn".

anyways, if you want it to be a customizeable grid, you should incorporate your x and y values from the 2d array in that if statement.

Or you could just use whatdotcolour Smile
awesomej01




PostPosted: Sun Mar 07, 2004 7:55 pm   Post subject: Grid

Since I am making a dice game and you guys showed me how to draw a grid and locate a position of the grid, how do I do something like if the player rolled a 2, then their marker would move two spaces.

would it be something like

if roll = 2 then
drawfilloval (on the second box location)
elsif roll=3 then
elsif...
...
for every other possiblities
end if
Cervantes




PostPosted: Sun Mar 07, 2004 8:04 pm   Post subject: (No subject)

you should have a variable for the player's spot.

then it would be
code:

player_spot += dice_roll


draw where he is on the grid by using mod and div to determine the grid location.

if he were at 10 and the grid is 7 wide..
code:

player_spot_on_grid := player_spot mod 7, player_spot div 7


I haven't tested any of this code, just so you know.
omni




PostPosted: Sun Mar 07, 2004 9:21 pm   Post subject: (No subject)

you took my idea for a dice game you go to massey and in mr.ferrara right?
jonos




PostPosted: Sun Mar 07, 2004 9:23 pm   Post subject: (No subject)

i shouldn't answer for cervantes, but he doesn't go to massey (im pretty sure), i know this because, you see, i stalk him Shocked . no i read his official hello world reply.
Mazer




PostPosted: Sun Mar 07, 2004 9:43 pm   Post subject: (No subject)

jonos wrote:
i shouldn't answer for cervantes, but he doesn't go to massey (im pretty sure), i know this because, you see, i stalk him Shocked . no i read his official hello world reply.

(He may have been talking to awesomej01)
McKenzie




PostPosted: Mon Mar 08, 2004 11:45 am   Post subject: (No subject)

Stop by my room at lunch. There are easy and hard ways to do your program. The biggest problem is that the game is no fun. As a kid the fun part is rolling the dice. On the computer all you do is hold down the enter key and see who wins (no choices at any point, just roll, read then obey)
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 1  [ 11 Posts ]
Jump to:   


Style:  
Search: