Hello,
First a brief intro: I decided to learn to program about 1 month ago and did some research and decided I liked DBPro.
I have since then been doing tutorials voraciously and been through many including most of the ones on TDK's tutorial thread
http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10
Now I am moving on to start a "learning phase" where I take ideas from the tutorials and try to implement them in ways that will eventually permit me to make a game that I have in mind.
The first task is to learn to work with multi dimensional arrays and I need to perform the following tasks:
1) Create an 8,8 array
2) Populate the array with random integer numbers ranging from 1 to 7 (no zeros)
3) Print the array out as if you were looking at a game board
NOTE: I'm doing all this in text output ; later graphics will come - I feel learning the text end lets me focus on code not on glitz.
After the first 3 goals are done I have a second set of goals:
4: Develop a method to elimate numbers (replace them with 0's);
5: Then do a bubble sort on each column to "sink" any numerical value down and replace 0s' (aka empty squares),
6: Create a process to then top fill the blanks left at the top.
I say that to understand my end goal but its not the question I'm focusing on first (confirm my current process is good then move on right? )
So all that said I do not come empty handed!
My first code seemed sucessful in that I was able to create the array, and print out 8 random numbers between 1-7.
Randomize Timer(): Rem Initialise the random number generator
DIM GameBoard (7,7) ; Rem intialize the GameBoard Array
For x = 1 to 8
GameBoard(x)=rnd(6)+1
Print GameBoard(x)
Next x
Wait key
This outputs a list on the screen like so:
3
7
2
1
3
1
1
4
So it suited my needs.. success for step 1!
What I then attempted to was a nested loop to try and fix in the y element of the array like so:
Randomize Timer(): Rem Initialise the random number generator
DIM GameBoard (7,7) ; Rem intialize the GameBoard Array
For x = 0 to 7
GameBoard(x)=rnd(6)+1
Print GameBoard(x)
For y = 0 to 7
GameBoard(x,y)=rnd(6)+1
Print GameBoard(x,y)
Next y
Next x
Wait key
This outputs such a long string of numbers on my screen (top to bottom) and there is no scroll bar -- so I can not tell if its doing 64 total items (7,7) array should be 8x8 elements right?
So I tried changing my print command to Print GameBoard(x,y) and there is no difference.
So I have some questions given what I've done.
1) Is my nested loop doing what I want it to do?
2) Any advice (tutorial based or otherwise) on how to print my output that resembles a grid instead of linear output
3) Are these values actually getting stored in the array?
I think so because I made a print loop at the end as such:
Rem ***** Main Source File *****
Randomize Timer(): Rem Initialise the random number generator
DIM GameBoard (7,7) ; Rem intialize the GameBoard Array
For x = 0 to 7
GameBoard(x)=rnd(6)+1
Print GameBoard(x)
For y = 0 to 7
GameBoard(x,y)=rnd(6)+1
Print GameBoard(x,y)
Next y
Next x
Rem Print Array
For p = 0 to 7
Print GameBoard(p,0); GameBoard(p,1); GameBoard(p,2); GameBoard(p,3);GameBoard(p,4);GameBoard(p,5);GameBoard(p,6);GameBoard(p,7)
Next p
Wait key
And it outputs like so:
14345671
23548787
65498878
46456545
And so on (appropriate size)
But I don't want to assume this is really 'saved in the array' because I'm new and dont know if there was a command I needed to 'save' it into the array?
Thanks in advance for any feedback and advice!
PS: I sure wish there was a preview post button so I could edit this a few times -- with the new member 'your not allowed to post' without review feature I may have to edit this a couple of times