Kojo Wiki

docs for Kojo

View source on GitHub

ArrayBuffers and HashMaps for gaming

This activity has the following desired goals:

  • Learning to use ArrayBuffers and HashMaps
  • Putting ArrayBuffers and HashMaps to use – to restructure the game from the previous lesson, so that adding new hunters becomes easy (A, M, T).

Step 1

Read about ArrayBuffers.

Q1a. What is an ArrayBuffer?

Q1b. What operations can you do with an ArrayBuffer?

Exercise 1a. Put the three hunters in the code from the previous lesson inside an ArrayBuffer. Remove the code for the bouncing of the hunters off the stage. We are just interested in moving the hunters around for now.

Q1c. Why would we want to put the hunters inside an ArrayBuffer?

Step 2

Read about HashMaps.

Q2a. What is a HashMap?

Q2b. What operations can you do with a HashMap?

Exercise 2a. In the code from Exercise 1a, make the hunters bounce off the stage.


In your code from the previous step, change the number of hunters to 5 by changing just one line of code. Then change the number of hunters to 10, and then 15. Make sure the game works fine for these different numbers of hunters.

Contribute Content
Copyright © Kogics Foundation