Top Down Design Big problem small steps We
Top Down Design Big problem small steps
We have a problem! § Making a video game or making a small program Mr. Hastings has asked you to make, every program solves some problem § Starting with a big picture idea (“This is what I want to make”). What do you want to happen? § Take that big problem and break it into smaller steps § Take those smaller steps break into manageable steps.
Outline = A Plan § Now that we know what specific tasks we need to accomplish before solving our problem we have a plan of action. § Just like building a house, some steps are necessary to complete first before doing anything else (drawing blueprint for house, getting permits, hiring contractors, etc…) § Just like building a house, some steps are independent of others (painting once walls are up, independent of landscaping outside)
Rock Paper Scissors game Let’s use our RPS game program as an example: Top down design begins with a BIG PROBLEM (I want to make a game) Breaks that down into sections (I will need to keep score… I will want to know who wins a match… I want some sort of dialogue in the game) Let’s look at what we did as a class with our game design:
Tasks: 1. We need to use the random function. We want the computer to be both unpredictable and unbiased [it won’t cheat] A. Create a list of possible choices [rock, paper, or scissors] B. Human chooses a R, P, or S C. Computer chooses randomly between R, P, or S
Tasks 2) Define a function recognizing user’s input a. We don’t want to have to repeat typing code create a game function (asks What your choice is, chooses, then evaluates and repeats)
Tasks 3) There needs to be an order / timing (control flow) for gameplay a. Human chooses first b. Computer chooses second c. Choices are compared / evaluated i. If human chooses ‘R’ and comp chooses ‘P’: comp wins… ii. If human chooses ‘P’ and comp chooses ‘S’: comp wins… iii. If human chooses ‘S’ and comp chooses ‘R’: comp wins… 1. Else: HUMAN WINS!!! d. Winner declared e. Win recorded / counted
Tasks 4) Rules! What beats what? a. R > S b. P > R c. S > P
Tasks 5) Keeping Score! How will we know who wins a. Win is recorded i. User win or computer win ii. After x wins, computer or human wins match (best of x matches)
- Slides: 9