Skip to content

Atividade

Pedra, papel e tesoura audível

Avançado | MakeCode | Acelerômetro, Som, Visor LED | Randomização, Seleção, Variáveis

O que é?

Jogue pedra, papel e tesoura com seu micro:bit e ouça efeitos sonoros para os diferentes objetos. Os estudantes aprenderão sobre aleatoriedade e seleção criando este projeto divertido.

Pedra, papel e tesoura

Como funciona:

  • Pedra, papel e tesoura é um jogo de sorte para duas pessoas. You and a partner shake your fists three times and then make a random gesture to show either a rock (fist), paper (flat hand) or scissors (scissor shape). Rock beats scissors, scissors beat paper, and paper beats rock.
  • This program allows the micro:bit to choose either rock, paper or scissors for you. Download the program onto two micro:bits and attach two battery packs. You and your partner should then shake your micro:bits to see two random images appear, one on each micro:bit.
  • You will also hear different sound effects for rock, paper and scissors. A rock makes a 'sad' sound, paper makes a 'hello' sound, and scissors makes a 'mysterious' sound.
  • The program uses a variable called ‘tool’. Variables are containers for storing data, which can be accessed and updated while a program is running. The variable ‘tool’ is used to store random numbers.
  • When the micro:bit accelerometer detects a shake movement, it sets the variable ‘tool’ to a random number: 0, 1 or 2. The program uses 0 because computers start counting at 0.
  • The program uses selection to decide what image to show on the LED display and what expressive sound to play.
  • If the random number was 0, it shows a rock icon (a small square) and plays the ‘sad’ sound. If it was 1, it shows the icon representing paper (a square) and plays the ‘hello’ sound. If it wasn’t 0 or 1, it must be 2 because we instructed the micro:bit to only pick random numbers between 0 and 2, so in that case it shows scissors and plays the 'mysterious' sound.

Itens necessários:

  • um micro:bit V2
  • Editor MakeCode;
  • Conjunto de baterias;

Instruções passo a passo

Abra o projeto para encontrar os blocos necessários usando os botões acima.

Step-by-step instructions

  1. Open the project to find the blocks you need using the buttons above.
  2. Find the pick random 0 to 2 block and put it onto the 0 in the set tool to 0 block.
  3. Get the set tool to pick random 0 to 2 block and put it inside the on shake block. Now when you shake your micro:bit, it will pick a random number between 0 and 2 and store it in the tool variable.
  4. Now you need to write the code that relates to selection. Get the if then else block and put it inside the on shake block under the set tool to pick random 0 to 2 block.
  5. Get the show icon small square block and put it under if tool = 0 then in the if then else block.
  6. Then find the play sad until done block and put it directly under the show icon small square block. Now your micro:bit will show a small square or rock and play the ‘sad’ sound if the random number chosen is 0.
  7. Now find the show icon square block and put it under else if tool = 1 then in the if then else block.
  8. Get the play hello until done block and put it directly underneath the show icon square block. Now your micro:bit will show a square and play the ‘hello’ sound if the random number chosen is 1.
  9. Next get the show icon scissors block and put it under else in the if then else block. Put the play mysterious until done block directly underneath that. Agora seu micro:bit mostrará um ícone de tesoura e tocará um som “misterioso” quando o número aleatório escolhido for 2.

Personalize

  • Escolha seus próprios sons expressivos para tocar para os diferentes objetos usando o menu suspenso nos blocos tocar som até terminar. Há 10 para escolher.
  • Use outros ícones do bloco mostrar ícone, como a girafa, o pato, a caveira e o fantasma, usando a opção suspensa. Invente novas regras para o jogo.

Exemplo de um projeto concluído

Dê uma olhada em um código concluído.

Projetos relacionados

Este projeto faz parte de uma coleção de projetos inclusivos com sons e imagens.