Put code between <VBCODE> and </VBCODE> (< = [ and > = ]) to preserve indentation and keep it readable.
How is this board supposed to work?VB Code:
For d = 1 To 100 'for all values in the array board(d) = 0 'turn them into 0 Next d 'complete initialisation of array no_of_snakes = 10 'the number of snakes = 10 no_of_ladders = 10 'the number of ladders = 10 snakecount = 0 'set snake counter to 0 Do Until snakecount = no_of_snakes Do size_of_snake = InputBox("Enter size of snake between 10 and 30 for snake number " & snakecount + 1) If size_of_snake < 10 Or size_of_snake > 30 Then MsgBox ("The size of the snake has to be between 10 and 30, please retry") End If Loop Until size_of_snake > 9 And size_of_snake < 31 Do position_of_snake = InputBox("Enter start position of snake for snake number " & snakecount + 1) If position_of_snake < 11 Or position_of_snake > 99 Then MsgBox ("Invalid position, try again") End If Loop Until position_of_snake > 10 And position_of_snake < 100 [COLOR=Orange]board(position_of_snake) = size_of_snake * -1[/COLOR] snakecount = snakecount + 1 Loop
I see a one-dimensional array, shouldn't that be two-dimensional?
Why didn't you declare the Board?
VB Code:
Private Board(100) As Long 'is it a long? Private 2D_Board(100,100) As Long 'this one is twodimensional
What you are doing in your orange statement is store the size of the current snake (minus 1) in the element of Board where the index is the snake's position.
What do you expect/want to happen?
If I have a snake with a length of 10 and a position of 20, should the elements Board(10) to Board(30) be filled with the snake's number?
In that case you sould make a For Next loop.
But what if the next snake starts at 20 with a length of 5?VB Code:
For d = position_of_snake To position_of_snake + size_of_snake If d > 100 Then Exit For Board(d) = snakecount Next d
It would overwrite some of the elements filled by the previous snake and cut it in half.




Reply With Quote