Naeem Sarfraz

Blogging about Enterprise Architecture, ALM, DevOps & happy times coding in .Net

Random Puzzles in Scratch

Using the Super Scratch Programming Adventure examples I set our Code Club students recreating a memory game using the Mona Lisa puzzle game from the book. The completed version “hard codes” the sequence you need to memorise so one of the students set about creating a truly random sequence generator. I want to document one way of doing this in Scratch here for his benefit and anyone else who might find this useful.

Presenting the sequence to the game player is defined by a series of sequential blocks like so:

image

And judging the game players response is even more unwieldy as there is lots of duplication and is very difficult to modify if you want to extend the sequence. Go to the project hosted on the Scratch site for the full code and click “See Inside.”

image

Generating a Random Sequence

The numbers from which we want to generate our sequence represent the options available to the game player, e.g. 1 to 4. To avoid the “hard coding” we’re going to require a list variable to hold the random sequence. We can now fill this list using this block of code:

image

Sometimes this will generate a sequence where a number might repeat like “2 2 1 4”. For the game player this isn’t a nice experience so I’m going to add a check so that it will only add the random number to he list if it doesn’t match the last random number.

image

Judging the Last Move

Working out if the game player entered the correct move is really easy now that we have a list of random numbers. I chose to solve this by:

  1. Saving the game players chosen move to a lastkey variable
  2. Check that the value of the lastkey variable and the last number added to the list are the same
  3. If so then the game player got it right
    1. Let them know they got it right using the say block and
    2. Remove the last item from the list as we don’t need to check this number again

image

The Final Solution

Here’s is the new version.

 

A few things to note with this solution:

  • I haven’t implemented “lives” for the game player so that you can only get three attempts at getting the sequence correct
  • When you start you get the option of choosing a level. This simply extends the number of steps you need to memorise

Tips on Running a Code Club

It was a pleasure to give a short talk to potential volunteers at the Code Club Leeds meet-up yesterday. Here’s a summary of what I discussed.

  1. Check your motivation
    You’ve got to be doing it for the right reasons and there are many good reasons to want to volunteer. Check your intentions and set yourself personal goals for what you want to get out of the experience. At the end of the day it has to be about the children and getting them engaged and having fun whilst learning these new skills.
    I firmly believe if you are motivated for the right reasons and enthusiastic about the cause that will project on to the children. I know I was inspired most by my teachers who not only knew their subject but knew how to engage.
  2. Make life easy, use the starter projects
    The starter projects are a great place to start, ensuring that there is a level of consistency between clubs. Be sure to read through and practise the projects before hand so that you can think about potential problem areas and further areas of enhancements if students finish early.
    We did have to lead our group a little using a smart board to demonstrate the next task and then letting them get on with it. But this doesn’t work for all students as you’ll discover, get out of the way of the ones that pick it up a lot quicker!
  3. Check the equipment
    I didn’t before I arrived for the first session only to discover we couldn’t run the latest version of scratch, the version the starter projects are based on. We were seeing lots of performance issues like machines freezing and an unresponsive UI because of the pc spec. We turned to the web version which was better but again we’re running on old browsers so the experience wasn’t what it should have been. However we managed to work around those things with my IT experience coming in to play.
  4. Work with your employer
    If you’re in full time employment then you’re going to need to get time off to attend a club. Work with your employer to come to an arrangement that works for both parties. Choose a school close to your office which will reduce the travel time and in the end you may only need a couple of hours off each week (3pm-5pm) but be prepared to make up that time if need be. An alternative could be to start a pre-school club which means you’ll get to work slightly later than usual but doesn’t disrupt your work so much.

I highly recommend it to anyone looking to give something back to their community and hoping to inspire young people about a career in IT.