Memory Lösung: Unterschied zwischen den Versionen

Aus microbit - Das Schulbuch
Wechseln zu: Navigation, Suche
(Detailschritte)
Zeile 20: Zeile 20:
 
</pre>
 
</pre>
  
* Anzeige bei "wahr" - steht für Kopf
+
* Ereignis "wenn Logo berührt"
* Anzeige bei "falsch" - steht für Zahl
+
* Soundeffekt wird gespielt
* Anzahl muss mitgezählt werden
+
* Das Symbol blinkt 5 mal, damit man weiß, welcher micro:bit gedrückt wurde
 
<pre id="01">
 
<pre id="01">
let anzahl_kopf = 0
+
input.onLogoEvent(TouchButtonEvent.Touched, function () {
let anzahl_zahl = 0
+
     soundExpression.sad.play()
input.onGesture(Gesture.Shake, function () {
+
    for (let index = 0; index < 5; index++) {
     if (Math.randomBoolean()) {
 
        anzahl_kopf += 1
 
 
         basic.showLeds(`
 
         basic.showLeds(`
             . # . . #
+
             # . . . #
             . # . # .
+
             # # . # #
             . # # . .
+
             # . # . #
             . # . # .
+
             # . . . #
             . # . . #
+
             # . . . #
 
             `)
 
             `)
    } else {
+
         basic.pause(10)
         anzahl_zahl += 1
 
 
         basic.showLeds(`
 
         basic.showLeds(`
             . # # # #
+
             . . . . .
             . . . . #
+
             . . . . .
             . . # # .
+
             . . . . .
             . # . . .
+
             . . . . .
             . # # # #
+
             . . . . .
 
             `)
 
             `)
 +
        basic.pause(10)
 
     }
 
     }
})
 
 
</pre>
 
</pre>
  

Version vom 6. Dezember 2021, 16:53 Uhr

Hilfestellung

  • Für die Kopf-Seite der Münze kann der Wert "wahr" oder "falsch" genommen werden.
  • Annahme: Kopf entspricht "wahr", Zahl entspricht "falsch"

Detailschritte

  • Ereignis "beim Start"
  • Zeige LEDs
basic.showLeds(`
    # . . . #
    # # . # #
    # . # . #
    # . . . #
    # . . . #
    `)
  • Ereignis "wenn Logo berührt"
  • Soundeffekt wird gespielt
  • Das Symbol blinkt 5 mal, damit man weiß, welcher micro:bit gedrückt wurde
input.onLogoEvent(TouchButtonEvent.Touched, function () {
    soundExpression.sad.play()
    for (let index = 0; index < 5; index++) {
        basic.showLeds(`
            # . . . #
            # # . # #
            # . # . #
            # . . . #
            # . . . #
            `)
        basic.pause(10)
        basic.showLeds(`
            . . . . .
            . . . . .
            . . . . .
            . . . . .
            . . . . .
            `)
        basic.pause(10)
    }
  • Anzahl wird jeweils ausgegeben
input.onButtonPressed(Button.A, function () {
    basic.showNumber(anzahl_kopf)
})
input.onButtonPressed(Button.AB, function () {
    basic.showNumber(anzahl_kopf + anzahl_zahl)
})
input.onButtonPressed(Button.B, function () {
    basic.showNumber(anzahl_zahl)
})
  • Nicht vergessen - Variablen auf 0 stellen
let anzahl_kopf = 0
let anzahl_zahl = 0



Zurück zur Aufgabe