Logotron educational software. Partners with the teaching profession - Pioneers in Learning
menubar search this site my shopping cart support products about home
 

Stop the Dice

Stop the Dice| Designing the Project | Programming
Improving the Project
| Assignments | Download the Project

Task

  • to create a simple game. The game will consist of three die that appear to change their value. The player has to click on a button to stop the die from 'rolling' when they think that at least two of them show the same value.
You need to know
  • how to work with the turtles and to change their shape.
  • how to create buttons.
You will learn
  • how to run and stop processes in an activity.
  • how to increase a turtle's size.
  • how to create a counter to record the number of correct guesses.
Stop the Dice

On the screen there are 3 'rolling' die whose value keeps changing. The player's task is to click on the STOP button at the moment when at least two of them have the same value. Each time the player guesses correctly, a counter records and displays his new score. A START button begins a new game.

Designing the project

  1. Each dice is a turtle with its shape set to a six-frame .LGF, and each frame shows a different value of spots (from 1 to 6).
  2. The START button makes each dice 'animate' so that the turtle begins to display each of its six frames at random. The frames must be selected at random, or else all three die would display the same frame with the same value at the same time.
  3. The STOP button freezes the turtles and makes them display their last chosen, at random, frame.
  4. A counter records the number of correct guesses made by the player.
Programming

You must first create a six-framed .LGF of a dice in Logomotion. If you do not want to create one yourself, click here to download a graphic ready for use.

Your graphic needs to have six frames, each with a different value from 1 to 6.

You must convert all your frame items into frames (so that the six images appear in rows - as in the screenshot to the right). Only then should you save your graphic to a place on your hard drive where you can easily find it later.

   

Converting your frame items into frames is easily done in two steps.

First you must select all six of your frame items. Right-click on any of the frames, choose Edit, and then click on Select All (or use the keyboard shortcut Ctrl+A).

A purple rectangle should now appear around all six of the frame items.

   

Right-click on your frame items again. This time choose 'Convert All to Frames' from the menu.

Your frame items should now appear listed down the left-hand side of the organiser window:

Save your .LGF with a meaningful name, such as 'Dice'.

NB: Logomotion will, by default, save your file in the folder Image unless you specify otherwise. This is a subfolder of Imagine Logo which can be found here: C:\Program Files\Imagine\Image\

You are now ready to change your first turtle into dice.

Right click on the turtle t1 and select Change t1 from the menu.

Click on the Set Shape... button in the dialog window, and then browse to find your saved Dice.LGF graphic:

If you think that your dice might be a little too small, then there is an easy way of changing its scale. Go to the Shape tab and, in the Scale X: item, type how many times larger you would like the graphic to appear. In this case, the dice will be three times bigger on the screen. Once you have done this, click OK to exit the dialog.

NB: This does not change the graphic file in any way - only its appearance on the screen alters.

You can now position the turtle anywhere on the screen. Do this by right clicking on the dice and choosing Move t1 from the dropdown menu. Your cursor should now change into the shape of a hand, and you will be able to move the turtle around the screen. Click once with the mouse when you are happy with the location.

Creating the other two die can be done by copying t1. Copying also means that the new die will have the same properties, like changes made to the scale, as the first. The process involves using the Clipboard in Imagine Logo, and is a very handy shortcut to creating projects.

Right click on the turtle and select Copy to Clipboard from the dropdown menu. Now right click anywhere on the screen with your mouse. This time choose Paste from Clipboard. A copy of t1 should appear. This turtle will be called t2. In this way you can also create the third dice.

On your screen there will now be a row of three die:

Although you can only see the first frame of each dice, which happens to be the value of one, you can command the turtles to display other frames. Try this by typing the following at the command line:

? t1'setFrame 2
? t1'setFrame 3
? t1'setFrame 4

See what happens when you tell t1 to 'setFrame 7 (even though this frame does not exist).

You should find that the turtle has 'looped' back to displaying frame 1. Therefore, 'setFrame 8 will display frame 2 and so on.

Using simple commands, you can tell each turtle to loop through its frames consecutively. You can also tell the turtle how often it should change its frame. So, for example, your turtle can be made to display a new frame every 200 milliseconds like this:

? t1'every 200 [setFrame frame+1]

Similarly, run processes can be assigned to t2 and t3. Try giving them a different run time in milliseconds.

? t2'every 200 [setFrame frame+1]

? t3'every 200 [setFrame frame+1]

These processes will now run indefinitely until you tell them to stop. This is why you need to add a STOP button to your activity but, for now, click on  on the Main Toolbar, or use the keyboard shortcut F12.

To make all three die begin their run processes at the same time, you will need to type your commands as one line:

? t1'every 200 [setFrame frame+1] t2'every 200 [setFrame frame+1] t3'every 200 [setFrame frame+1]

However, you will find that this command, not only starts your die 'rolling' simultaneously, but will also make each dice display the same frame at the same time. You do not want this happen. In this game you need each dice to have the same runtime, but to pick and display a frame at random. At the moment, your command to each turtle states [setFrame frame+1]. Change this to say [setFrame any]:

? t1'every 200 [setFrame any] t2'every 200 [setFrame any] t3'every 200 [setFrame any]

To create the START button, go to the Main toolbar, click on New Button, and then place your button called b1 anywhere on the screen.

The properties of your button will need to be changed. Right click on the button and select Change b1. A dialog window will appear.

Firstly, you will need to change the caption, or words that will appear on the button. Next to Caption, type 'start'. Then give your button a command in the onPush line. This command will run every time the button is clicked.

Click on OK when you have do this.


The STOP button is created in the same way. The only different is that the Caption will read 'stop' and for the event onPush type stopAll:

Play your game to see if it works.

Improving the Project

You can add a Counter, which will show you how many times the STOP button has been clicked.

The Counter is a text box with an onPush event. Go to the Main toolbar and click New Text Box. The cursor will change into a letter 'a' with a cross beside it. Click anywhere on the screen where you want your Counter to appear. Drag out the text box to the size you want. The style, size and colour of your text is up to you.

NB: You must type a zero into the text box.

The onPush event for the STOP button needs to be changed. For each time the button is pressed, a value of +1 has to be added to the text box value.

The Counter can also be made to record only the correct attempts made at stopping the game when two die display the same value. For this to happen, the onPush event must say:

if (or (t1'frame=t2'frame)(t1'frame=t3'frame)(t2'frame=t3'frame))
     [text1'setValue text1 + 1]
stopAll

NB: The command has been split into three lines so that it can be read more easily. However, when the command is typed into the onPush event line, it must appear as one continuous sentence (like this):

if (or (t1'frame=t2'frame)(t1'frame=t3'frame)(t2'frame=t3'frame)) [text1'setValue text1 + 1] stopAll

Assignments
  • See what happens if you click on the START button over and over, without clicking on STOP in between times.
  • Make the Counter record the number of incorrect attempts at stopping the game when two die display the same value.
  • Change the runtimes for each dice and see what happens if they have different millisecond values.

Download the Project

You can download an example of the finished project by clicking here

 
   
  back to top