App Lab

Stick Game

I created one of my favorite games in the App Lab in order to fulfill the requirements for our first App Lab assignment.

In the game, players can select buttons and claim them as their own by clicking their color box.

The game is won by leaving the last stick for the opponent.

The ONE EVENT block was especially important in the code, as it allows for the buttons on the screen to be clicked and have a function run after doing so.

<------CLICK THE PICTURE TO PLAY THE GAME!!!

CIRCUit playground CLASSROOM VOLUME MONITOR

Using the sound sensor input value, I created an app that allows teachers to monitor the sound level in their classroom.

The most difficult part of writing this code was making he buttons show or not show depending on the level of the input from the sound sensor.

I first mapped the raw values from (0 - 1023) to (0 - 90) then set "if" statements that said if sound levels were above a certain point, then the colored buttons would show.

Here is the code that I wrote:


soundSensor.setScale(0, 90);
onBoardEvent(soundSensor, "data", function(event) {
  if (soundSensor.value > 80) {
    setProperty("highSound9", "hidden", false);
    setProperty("highSound8", "hidden", false);
    setProperty("highSound7", "hidden", false);
    setProperty("mediumSound6", "hidden", false);
    setProperty("mediumSound5", "hidden", false);
    setProperty("mediumSound4", "hidden", false);
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("highSound9", "hidden", true);
    setProperty("highSound8", "hidden", true);
    setProperty("highSound7", "hidden", true);
    setProperty("mediumSound6", "hidden", true);
    setProperty("mediumSound5", "hidden", true);
    setProperty("mediumSound4", "hidden", true);
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 70) {
    setProperty("highSound8", "hidden", false);
    setProperty("highSound7", "hidden", false);
    setProperty("mediumSound6", "hidden", false);
    setProperty("mediumSound5", "hidden", false);
    setProperty("mediumSound4", "hidden", false);
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("highSound8", "hidden", true);
    setProperty("highSound7", "hidden", true);
    setProperty("mediumSound6", "hidden", true);
    setProperty("mediumSound5", "hidden", true);
    setProperty("mediumSound4", "hidden", true);
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 60) {
    setProperty("highSound7", "hidden", false);
    setProperty("mediumSound6", "hidden", false);
    setProperty("mediumSound5", "hidden", false);
    setProperty("mediumSound4", "hidden", false);
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("highSound7", "hidden", true);
    setProperty("mediumSound6", "hidden", true);
    setProperty("mediumSound5", "hidden", true);
    setProperty("mediumSound4", "hidden", true);
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 50) {
    setProperty("mediumSound6", "hidden", false);
    setProperty("mediumSound5", "hidden", false);
    setProperty("mediumSound4", "hidden", false);
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("mediumSound6", "hidden", true);
    setProperty("mediumSound5", "hidden", true);
    setProperty("mediumSound4", "hidden", true);
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 40) {
    setProperty("mediumSound5", "hidden", false);
    setProperty("mediumSound4", "hidden", false);
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("mediumSound5", "hidden", true);
    setProperty("mediumSound4", "hidden", true);
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 30) {
    setProperty("mediumSound4", "hidden", false);
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("mediumSound4", "hidden", true);
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 20) {
    setProperty("lowSound3", "hidden", false);
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("lowSound3", "hidden", true);
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 10) {
    setProperty("lowSound2", "hidden", false);
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("lowSound2", "hidden", true);
    setProperty("lowSound1", "hidden", true);
  }
  if (soundSensor.value > 5) {
    setProperty("lowSound1", "hidden", false);
  } else {
    setProperty("lowSound1", "hidden", true);
  }
  console.log(soundSensor.value);
});