
-----------------------------------
Luffy123
Thu Jun 07, 2012 5:00 pm

Can't seem to apply the concept of arrays and flexible arrays.
-----------------------------------
Like I know what both of them do perfectly. I don't know at all how to apply them when making my game. I am trying to make a snake game. Regular snake, and I know you have to use arrays in it but I don't know how to apply my knowledge of arrays in this game. Any help would be appreciated. Thank you.

-----------------------------------
DemonWasp
Thu Jun 07, 2012 5:27 pm

RE:Can\'t seem to apply the concept of arrays and flexible arrays.
-----------------------------------
You could use arrays to store the location (x,y) of each segment of the snake.

You could use arrays to store the map (wall sections, non-wall sections).

You could use arrays to store high scores.

-----------------------------------
Luffy123
Thu Jun 07, 2012 5:38 pm

Re: RE:Can\'t seem to apply the concept of arrays and flexible arrays.
-----------------------------------
You could use arrays to store the location (x,y) of each segment of the snake.

You could use arrays to store the map (wall sections, non-wall sections).

You could use arrays to store high scores.

What do you mean use arrays to store the map?

And when storing the snake x'ys. how do I use an array to draw out the each segment of the snake? i mean how do i use each point of a flexible array. I'll keep adding points everytime it eats an object and to make the snake increase ill have to add 1 point to the flexible array but how do i draw the snake with the flexible array is what im confused about

-----------------------------------
Raknarg
Thu Jun 07, 2012 7:42 pm

RE:Can\'t seem to apply the concept of arrays and flexible arrays.
-----------------------------------
Well, the first thing is whether or not you're going to use graphics or make it text based, it'll change it a little bit.

-----------------------------------
Dreadnought
Thu Jun 07, 2012 8:04 pm

Re: Can't seem to apply the concept of arrays and flexible arrays.
-----------------------------------
Well, the first thing is whether or not you're going to use graphics or make it text based, it'll change it a little bit.

Text based snake???

What do you mean use arrays to store the map?
And when storing the snake x'ys. how do I use an array to draw out the each segment of the snake?

For the map, suppose your game area is a 30x30 grid. Then you can have a 30x30 array that tells you which places in the grid are walls.

To draw the snake, you can just go through the array (with a loop) and for each pair of x and y values, draw a snake segment at the appropriate place on the screen.

Note that you can store the map and snake in other ways as well.

-----------------------------------
Raknarg
Thu Jun 07, 2012 8:15 pm

RE:Can\'t seem to apply the concept of arrays and flexible arrays.
-----------------------------------
Lol I mean like the graphics are done as text, I had to do that for one of my projects.

-----------------------------------
Luffy123
Thu Jun 07, 2012 9:07 pm

Re: Can't seem to apply the concept of arrays and flexible arrays.
-----------------------------------
Well, the first thing is whether or not you're going to use graphics or make it text based, it'll change it a little bit.

Text based snake???

What do you mean use arrays to store the map?
And when storing the snake x'ys. how do I use an array to draw out the each segment of the snake?

For the map, suppose your game area is a 30x30 grid. Then you can have a 30x30 array that tells you which places in the grid are walls.

To draw the snake, you can just go through the array (with a loop) and for each pair of x and y values, draw a snake segment at the appropriate place on the screen.

Note that you can store the map and snake in other ways as well.

Oh, how would I move each segment of the snake then? When using an array?

Also I have another question. When declaring a multidimensional array and giving it a value.

var a : array 1 .. 10, 1 .. 5 of int

for i : 1 .. 10
for k : 1 .. 5 
     a(i,k) := 4 // what does this do. What is it assigning the value 4 to? I can't seem to get the picture in my head.. can someone clearly explain it?
end for
end for

-----------------------------------
Dreadnought
Thu Jun 07, 2012 9:49 pm

Re: Can't seem to apply the concept of arrays and flexible arrays.
-----------------------------------
We can visualize a 2-dimensional array as a grid of numbers.

Here's a 2x3 array. (array 1..2, 1..3 of int) I've already given it some valuesfor i: 1..2
  for j: 1..3
    myArray (i, j) = 0
  end for
end for
This is what the process might look like at each iteration of the loops (I put the values of i and j above each)
[code](1, 1)     (1, 2)     (1, 3)     (2, 1)      (2, 2)     (2, 3)      