Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Wirf einen Würfel? Nein, nur eine Münze ...
- # Copyright 2023, 2024 Roland Richter [Mu: BBC micro:bit]
- import microbit
- import random
- while True:
- # Als ich hier is_gesture() verwendet habe, hat einmal Schütteln mehrere
- # "Münzwürfe" ausgelöst (d.h. Gesten werden zwischengespeichert); mit
- # was_gesture() wird nur ein "Münzwurf" ausgelöst.
- while not microbit.accelerometer.was_gesture("shake"):
- pass
- # PROBIERE, welche Gesten hier noch Sinn machen.
- # Zeige fünf Mal Kopf und Zahl -- als würde die Münze sich drehen.
- for k in range(5):
- microbit.display.show(microbit.Image.HAPPY)
- microbit.sleep(300)
- microbit.display.show("1")
- microbit.sleep(300)
- microbit.display.clear()
- microbit.sleep(500)
- # Erzeuge eine zufällige ganze Zahl zwischen 1 und 2: also 1 oder 2 ...
- randomvalue = random.randint(1, 2)
- # ... und zeige entweder "Kopf" 🙂 oder "Zahl" ① an.
- if randomvalue == 1:
- microbit.display.show(microbit.Image.HAPPY)
- else:
- microbit.display.show("1")
- microbit.sleep(1000)
- # PROBIERE, statt einer Münze einen Würfel ⚀,⚁,⚂,⚃,⚄,⚅ anzuzeigen.
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment