Class hours: 9:40 – 2:05
Mr. Bohmann
wbohmann@ewsd.org
Week Thirty Two

Today’s Notes
- Today is an EHS A Day
- Hello May!
- Next vacation is summer vacation!
- Web Professionals Exam – We’ll take it again this year to earn updated certification before graduation.
- 20% are back on – you’ll give us an update of your side projects next Monday.
- Breakout – How did it go?
- One Button Games – some nice ideas, want to make any?
- Vermont Highway Safety Alliance – any emails?
- Vote – VHSA
9:40 Monday Mail

9:45 Flow Control continued

Before break we were building a lunar lander. Now, not much of a game (yet), but we did get a chance to do some flow control – game events determined by if statements.
The if() statement is not the only way to control your program flow. The switch has decision-making power similar to an if / else-if / else chain. Switch statements are useful when you want to compare one value against a series of other values and execute different code on each “equal to” match.
“if” Versus “switch”
You can use any logical expression inside an if() or else if() statement. So, you can ask complex questions like “is score greater than 100 AND is playerHealth less than or equal to 0?” You can also ask very simple questions such as “is shipStatus equal to 1″? In fact, you may frequently want to ask a series of “equal to” questions about one variable or expression and take some different action with each result.
if (shipStatus == 1)
{
messageText.text = "All Systems Green";
}
else if (shipStatus == 2)
{
messageText.text = "Yellow Alert";
}
else if (shipStatus == 3)
{
messageText.text = "Getting Toasty in Here";
}
else
{
messageText.text = "Head for the Life-pods!";
}
While this if / else-if / else chain will work fine, C# provides a cleaner way to test if one variable or expression is “equal to” many different values.
The “switch” statement
The switch() statement will accept one variable or expression to test, and then allow you to write different blocks of code for each possible value or “case“. Let’s rewrite our example using the switch statement.
switch (shipStatus)
{
case 1:
messageText.text = "All Systems Green";
break;
case 2:
messageText.text = "Yellow Alert";
break;
case 3:
messageText.text = "Getting Toasty in Here";
break;
default:
messageText.text = "Head for the Life-pods!";
break;
}
What’s going on here? The switch statement begins with the switch keyword, followed by an expression in parentheses. The expression must evaluate to an integer number such as byte, int or long, or a char or string. In our example, we simply used the variable shipStatus, which has been declared elsewhere as some integer type. Important – You cannot switch on a fractional data type such as a float.
Let’s open the Lunar Lander project and see how this works.
The entire body of the switch statement is contained within the opening and closing curly braces.
Within the switch, curly braces are one or more case statements. A case represents one possible value of the switch expression and the code you want to run when the expression is “equal to” that value.
You can add as many case statements as you like; one for each value you want to check. You can also add a default case at the very end. This is similar to the else statement after an if() expression. The default case will be executed if no other case value matches (see above code example for a default case)
switch (health)
{
case 3:
Debug.Log("Your Health is Excellent");
break;
case 2:
Debug.Log("Your Health is declining");
break;
case 1:
Debug.Log("Your are almost finished!");
break;
case 0:
Debug.Log("You are dead");
break;
}
Now that we have seen this done. Let’s look at the if / else statements we made in our Lunar Lander and clean them up with a switch statement. Remember when I said we cannot use floats?. A float is a (fractional) value, and you can’t use fractional data types directly in a switch statement.
So, the first thing you’ll do is convert the float to an integer data type. You can cast (convert) a fractional data type to an integer type by placing the new data type in parentheses in front of the fractional value.
// explicitly cast fractional value to integer
int speed = (int)relativeVelocity;
10:35 Break

10:45 English with Mx. Yopp

Mx. Yopp is out sick today.
We’ve completed reading many books in class as you can see by the book covers printed around the room. I’m guilty of passing on a book if the cover is not of great interest to me. See a good book cover sets the tone of the book. A good book cover can showcase character(s), the plot, the setting, symbolism and conflict.
What did the book(s) you’ve read get you thinking about / visualizing? Images are powerful ways of communicating.
Task:
- Create a Book Cover (front cover only) of a book you read (or a favorite book)
- Create a design that reflects the books themes, symbols, characters, plot
- Digital or Hand Drawn
- 6″ x 9″ or 5.5″ x 8.5″
- Clear title and author name
- You may use Photoshop, Illustrator, Blender, Procreate or go Analog or combo of both
- Book Covers will be due next Monday, May 8th.
11:30 Breakout – Check-in

I’m going to circle around and have a look at your Breakout games. This is a chance to show me how you worked through the project, where you got stuck or what worked for you.
If you are all set with your breakout game, start thinking about or tackling your 20% work for this week. Today is very much a catch up day and get back to looking at our code and thinking about what we were doing before break (I don’t know about you, but I need a slow re-introduction back to what we were doing before break)
12:15 Lunch

12:45 Independent Reading

1:10 Break

1:20 Independent Project Worktime of Individual Support
- Overdue work – Breakout / One Button / TileMaps level / Sprite Sheet / Exploring Game Careers
- 20% for this week