Download presentation
Presentation is loading. Please wait.
1
Chapter 9 Using Decisions to
Make Games
2
LESSON: Prepare a new Chapter 9 folder on your flash drive to store the programs for this chapter. We are going to start preparing to create our very own game. Think about some themes that you would like, but do not worry about how to do it, yet, as we will go through a great deal of instructions, techniques, and ideas before you actually have to create it.
3
The If/ElseIf Ladder: Very useful
The If/ElseIf Ladder: Very useful! Especially when you have a “cascading effect.” That is, if it does not fall within the first comparison, it tests the second, then the third, etc., though! Type this in EXACTLY as you see it and press RUN {Be careful that > and < cascades in the correct direction!} {Last comparison is just “Else.”} {Last line is “EndIf.”} (Price, 2015)
4
Let’s look at a program, line by line:
Type this in EXACTLY as you see it and press RUN. (Price, 2015)
5
Remember our Truth Tables:
AND & OR Operators Remember our Truth Tables: (Price, 2015) (Price, 2015)
6
Here’s another example from page 116:
AND Operators We use AND when we want to compare items that have to BOTH be true at the same time. For example: “I have to have all A’s AND do my chores in order to go to Dallas this weekend.” Here’s another example from page 116: (Price, 2015) Why use AND here? Because our poor little kitty has to go through Door 1, AND Door 2, AND Door 3 to get his treat!
7
“I can hang with my friends tonight OR I can go to the movies with my
OR Operators We use OR when we want to compare items where only at least is true. For example: “I can hang with my friends tonight OR I can go to the movies with my sister.” From page 116: Why use OR here? Because as long as our little kitty goes through Door 1, OR Door 2, OR Door 3, he will get his treat! (Price, 2015)
8
How would we express this situation?
(Price, 2015) Little kitty can go through Door 1 AND Door 2, OR he can go through Door 3 to get his treat.
9
Sometimes, the AND statement is more efficient.
The last three lines replaced: (Price, 2015)
10
Also, the OR statement is more efficient.
The last three lines replaced: (Price, 2015)
12
Now, for fun stuff! Let’s practice getting shapes and images into our program (because we want our game to look great!) To start, we will go to GOOGLE IMAGES and get a cute picture of a pet: puppy, kitten, bunny, fish, bird, etc. Make note of the size. Try to get images that are not too small (blowing it up makes it fuzzy.) However, if you get a really large image, we will be going into PAINT and we can resize it, there. Click on the image and then on “View image”
13
Right click to copy image to get it and paste it into PAINT.
IF it is too large, we will have to re-size it: -Select image, if not already selected, and choose to Re-size it Change the “Resize by” to Pixels. -Type “600” or smaller into the Horizontal box—the Vertical box will magically conform, as long as the “Maintain aspect ratio” is checked. -Press “OK”
14
Once we have saved to our flash drive, we can use it.
In either case (re-sized or not), we want to save it to our flash drive. SAVE under a simple name. Remember how you spelled it, capital letters, etc.! I am using Kitten. Once we have saved to our flash drive, we can use it. Double check as to which port your flash drive is in—it is usually either E:\ or F:\. Let’s see if we can get our image onto the output. {Creates variable to trace the picture’s path.} {Assigns the Shapes OBJECT.} {Moves the Shape.} (Price, 2015)
15
We can also use the Shapes OBJECT get a rectangle.
{Width and height.} {Gives you a chance to see it move.} (Price, 2015) {Moved to these coordinates.} Type this in EXACTLY as you see it and press RUN. The rectangle’s width is 100 pixels and the height is 50 pixels. If we wanted to move it so that the CENTER is at 200,200, We would use: Can you figure out why? Try it!
16
The default Graphics Window is ~620 x 440.
200 300 400
17
This is similar to what your program will look like when you finish.
18
This next program is called Guess my Coordinates
This next program is called Guess my Coordinates. We will type it in three segments, as we go over what the commands are doing. The program is on pages You may type it in from the book. But, only type up to line 9. SAVE: GUESS MY COORDINATES. (Prce, 2015)
19
I will/have already put the STAR and GRID on the CEB Student Data (Q) Drive. Access it and SAVE it to your flash drive. Type this in EXACTLY as you see it and press RUN. (Price, 2015)
20
Add inside the While loop. REM the While/EndWhile commands
Add inside the While loop. REM the While/EndWhile commands. This is Listing 9-7.
21
This is Listing 9-8. Add inside the While loop, right after Listing Don’t forget your indentations!
22
Chapter 9 Programming Assignment
Use your SHELL and SAVE AS 5 LEVEL GAME Using the coding from the previous slides, put in both a GraphicsWindow and a TextWindow Have the first user input his/her name. Use the Cursor METHODS to give instructions and readability. Use the Random METHODS pick a number from 1 (worse) to 5 (best) For five events, as each number is chosen, a message and a picture (commensurate with the message) will appear and keep a running sum. Request that the user press any key to make each one appear. Allow the second user to replay the game. Keep his/her total Compare the two totals and declare a winner. I will check via Vision. Due __________
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.