/** * 情報T 拡張ブロック */ enum ButtonNames { //% block="A" A, //% block="B" B, //% block="A+B" AB, //% block="AかB" AorB, //% block="AかA+B" AorAB, //% block="BかA+B" BorAB, //% block="AかBかA+B" AorBorAB, //% block="いずれか" ANY } //% weight=100 color=#0fbc11 icon="\uf0c3" namespace Joho1ext { /** * @param b 入力要求ボタン eg : "A" * 選択されたボタンが押されるまで待つブロック * Aボタンが押されたら戻り値:1 * Bボタンが押されたら戻り値:2 * ABボタンが押されたら戻り値:3 */ //% block="%b=ButtonNames|のボタンが押されるまで待つ" export function 押されるまで待つ(b: ButtonNames): number { if (b == ButtonNames.A) { return Aのボタンが押されるまで待つ() } else if (b == ButtonNames.B) { return Bのボタンが押されるまで待つ() } else if (b == ButtonNames.AB) { return ABのボタンが押されるまで待つ() } else if (b == ButtonNames.AorB) { return AかBのボタンが押されるまで待つ() } else if (b == ButtonNames.AorAB) { return AかABのボタンが押されるまで待つ() } else if (b == ButtonNames.BorAB) { return BかABのボタンが押されるまで待つ() } else if (b == ButtonNames.AorBorAB || b == ButtonNames.ANY) { return AかBかABのボタンが押されるまで待つ() } else { return -1 } } function Aのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.A))) { basic.pause(10) } if (input.buttonIsPressed(Button.A)) { while(input.buttonIsPressed(Button.A)){ } return 1 } else { return -1 } } function Bのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.B))) { basic.pause(10) } if (input.buttonIsPressed(Button.B)) { while (input.buttonIsPressed(Button.B)) { } return 2 } else { return -1 } } function ABのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.AB))) { basic.pause(10) } if (input.buttonIsPressed(Button.AB)) { while (input.buttonIsPressed(Button.AB)) { } return 3 } else { return -1 } } /** * AまたはA+Bボタンが押されるまで待つブロック * Aボタンが押されたら戻り値:1 * ABボタンが押されたら戻り値:3 */ //% block="A:1かAB:3のボタンが押されるまで待つ" function AかABのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.A)) && !(input.buttonIsPressed(Button.B)) && !(input.buttonIsPressed(Button.AB))) { basic.pause(10) } if (input.buttonIsPressed(Button.AB)) { while (input.buttonIsPressed(Button.AB)) { } return 3 } else if (input.buttonIsPressed(Button.A)) { while (input.buttonIsPressed(Button.A)) { } return 1 } else { return -1 } } /** * BまたはABボタンが押されるまで待つブロック * Bボタンが押されたら戻り値:2 * ABボタンが押されたら戻り値:3 */ //% block="B:2かAB:3のボタンが押されるまで待つ" function BかABのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.A)) && !(input.buttonIsPressed(Button.B)) && !(input.buttonIsPressed(Button.AB))) { basic.pause(10) } if (input.buttonIsPressed(Button.AB)) { while (input.buttonIsPressed(Button.AB)) { } return 3 } else if (input.buttonIsPressed(Button.B)) { while (input.buttonIsPressed(Button.B)) { } return 2 } else { return -1 } } /** * AまたはBまたはABボタンが押されるまで待つブロック * Aボタンが押されたら戻り値:1 * Bボタンが押されたら戻り値:2 * ABボタンが押されたら戻り値:3 */ //% block="A:1かB:2かAB:3のボタンが押されるまで待つ" function AかBかABのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.A)) && !(input.buttonIsPressed(Button.B)) && !(input.buttonIsPressed(Button.AB))) { basic.pause(10) } if (input.buttonIsPressed(Button.AB)) { while (input.buttonIsPressed(Button.AB)) { } return 3 } else if (input.buttonIsPressed(Button.A)) { while (input.buttonIsPressed(Button.A)) { } return 1 } else if (input.buttonIsPressed(Button.B)) { while (input.buttonIsPressed(Button.B)) { } return 2 } else { return -1 } } /** * AまたはBボタンが押されるまで待つブロック * Aボタンが押されたら戻り値:1 * Bボタンが押されたら戻り値:2 */ //% block="A:1かB:2のボタンが押されるまで待つ" function AかBのボタンが押されるまで待つ(): number { while (!(input.buttonIsPressed(Button.A)) && !(input.buttonIsPressed(Button.B))) { basic.pause(10) } if (input.buttonIsPressed(Button.A)) { while (input.buttonIsPressed(Button.A)) { } return 1 } else if (input.buttonIsPressed(Button.B)) { while (input.buttonIsPressed(Button.B)) { } return 2 } else { return -1 } } /** * 入力を待つブロック * @param s 入力要求文字列 eg : "abc" */ //% block="〇〇と聞いて待つ %s" export function 〇〇と聞いて待つ(s: string): number { basic.showString(s) let 答え = 0 basic.showNumber(答え) while (!(input.buttonIsPressed(Button.B))) { basic.pause(10) if (input.buttonIsPressed(Button.A)) { 答え = (答え + 1) % 10 basic.pause(200) basic.showNumber(答え) } } basic.clearScreen() return 答え } }