Snakes and Ladders help

geezer12
12-28-2005, 06:39 AM
Hey,
I am making a snakes and ladders board game, so far:

I have a created a board using GDI+ consisting of 100 squares.
Two dice creating random numbers when a button is clicked.

I have a couple of questions:
I have created my board inside one panel is this correct? Or shall I created 100 panels instead, this way would seem easier to me.

Another problem is that I cannot find a way of getting my board to include data, like which ones hold snakes/ladders and how to move the counters to the corresponding squares when a dice is rolled. My counters do not need to be animated, just moved to each square.
I think I need to create an array to hold the data for the squares, but I have done this to draw the board. This is my code I have put inside the panel to create the board.

Dim Square As New SizeF(0.075F * Me.ClientRectangle.Width, 0.075F * Me.ClientRectangle.Height)
Dim solidb As New SolidBrush(Color.White)
Dim toggle As Boolean = False
Dim y As Integer
For y = 0 To 9
Dim x As Integer
For x = 0 To 9

If toggle Then
solidb.Color = Color.Red
Else
solidb.Color = Color.Black
End If
Dim rect As New RectangleF(x * Square.Width, y * Square.Height, Square.Width, Square.Height)
e.Graphics.FillRectangle(solidb, rect)
toggle = Not toggle

Next x
toggle = Not toggle
Next y
solidb.Dispose()


Thanks in advance,
G

Iceplug
12-30-2005, 05:07 AM
It would be more correct to use one panel... or, preferably, no panels, and just draw on the form. 100 panels might *seem* easier, but once you learn GDI+, you'll know better ;) - besides if you were going to use 100 panels, you'd have no reason to use GDI+ and you could just stick pictures in each panel.

For the including data part, you can make your own square structure. Make it have an X and Y coordinate, give it a Boolean that determines if it has a snake or a ladder, give it a final destination tile index that tells where the ladder goes, and feel free to add other stuff.

geezer12
12-30-2005, 05:50 AM
Hmmm, I'm still a bit confused.

At the moment I want to first make counters move according to the value on the dice. I had it work to move once. When the value was 1 I used the move.right(33,33) thingy but I then I am stuck as to what to do when it needs to go up etc.

Drawing snakes and ladders I am not too worried about, I am thinking if i can just get the counter to move accordingly i am on the right tracks.

I am thinking I need loops and arrays somewhere in this, but just cannot see how they will work with this.

Thanks, G

Iceplug
12-30-2005, 05:53 AM
Well, aren't you using an array for holding each tile's location? Since you do have to eventually go up, I would just set each coordinate in an array. To move the character to the next tile, just set his coordinates to the next array index coordinates. :)

geezer12
12-30-2005, 06:03 AM
Sorry for being Dumb, but how do I set each coordinate in a array?
G

Iceplug
12-30-2005, 06:09 AM
'Declaration
Dim Points() As Point
'or
Dim Points As ArrayList 'you don't need this unless you plan on making the board bigger at runtime.
Initialization:
Points = New Point() { _
New Point(0, 300), New Point(30, 300), etc.
or if you look at it a little, you could use some For Loops
For LV = 0 to 9
Points(LV) = New Point(30 * LV, 300)
Next
For LV = 10 to 19
Points(LV) = New Point(30 * (19 - LV), 270)
Next
'270 is the top values for the second row.
'The subtraction from 19 is so that the 19th square is at the left end (0), and the 10th square is at the right end above the 9th square, which is at left = 9 * 30, or left = 270.

geezer12
12-30-2005, 06:15 AM
Thanks a lot for your fast responses, I will look at this and hopefully get somewhere with it.
Thanks again.
G

geezer12
12-30-2005, 08:26 AM
Ok, I am ditching using graphics a graphics interface to make the board game.
Instead I am just going to write the results into a textbox.
I am still struggling though, when I roll a dice I am thinking I need a loop to write the result out line by line when the roll dice button is clicked. I cannot seem to get my head round this.
G

Iceplug
12-30-2005, 05:18 PM
Unfortunately, when you 'ditched' using 'graphics a graphics interface'... I didn't understand anything afterwards :p. How can you do a snakes and ladders game without the interface? And what result are you after?

geezer12
12-31-2005, 11:21 AM
Dont worry about my last statement, looks like i've sorted it, thanks.
G

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum