Unit 4: Day 7

START DATE:DUE DATE:STATUS:Open

Tasks

46.1 Boolean Quick Check #4 (same difficulty level as #3)

  • Be sure to remind them that capitals do matter
  • A copy can be found in the Resources folder 1.4  - Year 1: Programming Part 2
  • Or you can see a student version of the quiz here.

46.2 Marvel Character Guesser Example

  • Review/discuss the use of Boolean Variables.
  • use a sceneNum variable to change questions, just like in yesterday’s slideshow example. 
  • This is one of the longest examples we do. I STRONGLY suggest giving them at least half the code to start.
  • It is also the leaping off point for the next assignment.  For that assignment, students continue this example by adding more characters and thus demonstrating they understand the logic.
  • To make it easier for you to read, all the code is on the next page.
  • New: Introduce the concept of ‘passing in a parameter’ by adding a variable that will control the red value of the color of the text in each function.  Truly, this is not necessary but the idea of Argument/Parameter passing is an important concept so introducing it subtly is helpful.  Parameters are variables used to pass data INTO a function to help it do its job.
  • Discuss the following AP Knowledge statements about functions (aka procedures)
    • AAP3.A.1- A procedure is a named group of programming instructions that may have parameters and return values.
    • AAP3.A.2 - Procedures are referred to by different names, such as method or function, depending on the programming language.
    • AAP3.A.3 - Parameters are input variables of a procedure/function. Arguments specify the values of the parameters when a procedure is called.
    • AAP4.A.1 - A procedure/function call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing. Once the last statement in the procedure (or a return statement) has executed, flow of control is returned to the point immediately following where the procedure was called
    • AP-3.B.5 Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.

46.3 Assignment 3 - Marvel Characters Assignment

  • Instructions for this assignment can be found in the folder: 1.4  - Year 1: Programming Part 2
  • This assignment is an extension of the example.  The example code is provided at the end of the instructions doc for those that missed it.

Marvel Game Example

//Ironman, Groot, Thanos, Spiderman

let scenenum = 1;

let isHuman = false;

let isGood = false;

let isBitten = false;

let isFemale = false;

function preload() {

}//end preloading of images and fonts

function setup() {

let sketch = createCanvas(600, 400);

sketch.parent("mycanvas");

background(255, 255, 0);

textSize(24);

}//end setup

function draw() {

    if (scenenum === 1) {

        scene1(5);  //the 5 will affect the red value of the text

    } else if (scenenum === 2) {

        scene2(25);

    } else if (scenenum === 3) {

        scene3(5);

    } else if (scenenum === 4) {

        scene4(25);

    }else if (scenenum === 999) {

        endscene(50);

    } 

}//end draw

function keyPressed() {

    //Human question

    if (key === 'y' && scenenum === 1) {

        scenenum = 2;

        isHuman = true;

    }

    else if (key === 'n' && scenenum === 1) {

        scenenum = 2;

    }

    //Good guy question

    else if (key === 'y' && scenenum === 2) {

        scenenum = 3;

        isGood = true;

    }

    else if (key === 'n' && scenenum === 2) {

        scenenum = 3;

    }

    //Spider question

    else if (key === 'y' && scenenum === 3) {

        scenenum = 4;

        isBitten = true;

    }

    else if (key === 'n' && scenenum === 3) {

        scenenum = 4;

    }

//Female question

    else if (key === 'y' && scenenum === 4) {

        scenenum = 999;

        isFemale = true;

    }

    else if (key === 'n' && scenenum === 4) {

        scenenum = 999;

    }

}//end keyPressed

function mousePressed() {

}//end mousePressed

function scene1(red) {

    background(255, 255, 0);

    fill(red, 50, 150);

    text("Is your character from earth? (y or n)", 50, 100);

}

function scene2(red) {

    background(255, 255, 0);

 fill(red, 50, 150);

    text("Is your character a goodguy? (y or n)", 50, 120);

}

function scene3(red) {

    background(255, 255, 0);

 fill(red, 50, 150);

    text("Has your character been bitten by a radioactive insect? (y or n)", 50, 140);

}

function scene4(red) {

    background(255, 255, 0);

 fill(red, 50, 150);

    text("Is your character female? (y or n)", 50, 140);

}

function endscene(red) {

    background(255, 255, 0);

 fill(red, 50, 150);

    if (isHuman && isGood && !isBitten && !isFemale) {

        text("Ironman!", 50, 350);

    } else if (isHuman && isGood && isBitten && !isFemale) {

        text("Spiderman!", 50, 350);

    } else if (!isHuman && !isGood && !isBitten && !isFemale) {

        text("Thanos!", 50, 350);

    } else if (!isHuman && isGood && !isBitten && !isFemale) {

        text("Groot!", 50, 350);

    } else if (!isHuman && isGood && !isBitten && isFemale) {

        text("Gamora!", 50, 350);

    } else if (isHuman && isGood && !isBitten && isFemale) {

        text("Captain Marvel!", 50, 350);

    }

    else {

        print("Testing Boolean variables");

        print("isHuman"+ isHuman);

        print("isGood"+ isGood);

        print("isBitten"+ isBitten);

        print("isFemale"+ isFemale);

    }

}//endscene


Continue to Unit 4: Day 8 »