Step 3: Choosing a Random Hole Part 1

Goal:


Awesome! We now have a working timer!

However, we still don’t have any moles showing up yet, which isn’t very good. Let’s fix that next!

First be sure you are still coding on the backdrop/stage as all this next code will also go here

This code will choose a random number from 1 to 6 (because we have 6 holes!) and use that to decide where to place a mole

Steps:

  1. From Events place a when I receive block and set the message to be “MoleDisappeared!”
  2. From Variables place a set to block
  3. Inside the set to block on the left side, set the variable to be “positionChooser”
  4. From Operators place a pick random block on the right side of the set to block
  5. On the left side of the pick random block, type in the number 1, on the right side type in the number 6
  6. From Control place an if then block
  7. From Operators place an = block and place it inside the if then block
  8. From Variables place a round “positionChooser” block on the left side of the = block
  9. Type in the number 1 on the right side of the = block
  10. From Variables place a set to block
  11. In this set to block, set the variable to be “nextX” and the number to -130
  12. From Variables place a set to block under the previous one
  13. In this set to block, set the variable to be “nextY” and the number to 60

Code: