Hangman

Hangman

You know the game "hangman". In a number of attempts you try to guess a word.
When the person on the drawing is complete, the attempts are exhausted and you "hang".

You learn:
• Create your own blocks
• Define own blocks
• Design a "helper"
• Create an auxiliary variable
• Change the appearance of a variable

Press the start button to play the game. Enter one letter per attempt to try to guess the word.

STEP 1.

Open the online editor and delete the cat. Do you know what to start with?

1

STEP 2.

Thanks to your prior knowledge, it is already possible to (partially) program the backgrounds and some sprites (hangman, start button, "new game" button). Decide for yourself what you want the sprite has to execute to make the game work as in the example.

STEP 3.

In this step we learn to create and define a block. You can do this at the 'code' tab and then 'My blocks'. Create the block "Begin". Of course you will have to explain to the computer step by step what you mean by this block (define "Begin).

3

Do you know the purpose of creating such a block? It ensures that a longer code remains clear. The blocks under "define" are merged into just one block, namely the "start" block.

Define the "start" block as follows:

4

Please note: a "glossary" list is included in the code. Make up words of your own that can be guessed (about 10). Keep in mind that the words must contain the same number of letters as the boxes you provide in the game (5 in the example).

Can you find out how to add words to the glossary yourself?

toelichting

5

Not every variable has to be visible in the playing field. You can make a variable invisible by removing the check mark. In the example, the variable "attempts" will be invisible, the variable "number of attempts" is checked and therefore visible in the playing field.

Can you explain in your own words what will be the result of the program 'Define beginning'?

Now you can insert the starting block in the code that you assign to the "new game" signal. Just ask yourself what's still attached to this signal. Again, dare to convert a longer code into one new self-created block.

Of course, it is very difficult to  define the purple blocks. Below you get an idea of ​​what the codes should look like:

Define 'process response':

Define 'process wrong answer':
When the player enters a letter that does not appear in the word, the "wrong letter" signal is sent. The hangman takes on a different appearance and the player has now lost an attempt. When the player has lost all his attempts, the correct word appears, as well as the message "lost". The game is now over. When not all attempts have been used up, an "update" signal is sent.

Define 'process correct answer':
When the player enters a letter that does appear in the word, the "update" signal is sent. When all letters have been guessed, the message "won" appears. The game is now over.

Create the variables you  need. The variables in "attempts" and "show word" may apply to all sprites; the others "just for this sprite".

STEP 4.

The last step is to program the helper. The helper is a self-selected sprite, which we make invisible during the game. We set up this sprite to separate the code from the other sprites, because the code basically applies to the entire game and not to one sprite. You do this like this:
Add a sprite. Name him "Helper". Click on the "i" of information.

helperinfo

Click the check mark at "show". The helper is no longer visible.

10

At the helper we create a program that ensures that the guessed letters of the secret word appear in the correct variable / column. Can you think of what you need to shape this code?

uitdaging

Which things could you add yourself to make the playing experience optimal? Just think of a high score, the layout of several levels, ...

goed gedaan!     Goed gedaan!