
-----------------------------------
Memebot
Wed Apr 26, 2017 8:27 pm

How do I add multiple rows of enemies in Space Invaders using an Array or loop?
-----------------------------------


[size=14][b]Please specify what version of Turing you are using[/b][/size]
I believe we are using 4.1 in class.

-----------------------------------
Insectoid
Fri Apr 28, 2017 2:20 pm

RE:How do I add multiple rows of enemies in Space Invaders using an Array or loop?
-----------------------------------
You''re already using an array to store your enemies so you're halfway there. You already know that if you need a bunch of a thing, you keep them in an array. What do we want now? A bunch of rows. A row is a thing though, right? So if we want a bunch of rows, it makes sense to store them in an array!

Since an array can be of any type, and an array is itself a type, we can make an array of arrays!
[code]var foo : array 1..5 of array 1..5 of int[/code]

This array contains 5 cells, each of which is itself an array of length 5. You access elements in the array pretty much as you'd expect:
[code]a := foo (2)(3)[/code]

This will return the 3rd element of the 2nd element of foo.

Now you need to write some code that works on arrays of arrays. I'll leave that up to you, but I'll give you a hint: Arrays of arrays play really nice with loops inside loops.
