Big problem small steps 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: We need to use the random function. We want the computer to be both unpredictable and unbiased [it won’t cheat] Create a list of possible choices [rock, paper, or scissors] Human chooses a R,P, or S Computer chooses randomly between R,P, or S
Tasks Define a function recognizing user’s input 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 There needs to be an order / timing (control flow) for gameplay Human chooses first Computer chooses second Choices are compared / evaluated If human chooses ‘R’ and comp chooses ‘P’: comp wins… If human chooses ‘P’ and comp chooses ‘S’: comp wins… If human chooses ‘S’ and comp chooses ‘R’: comp wins… Else: HUMAN WINS!!! Winner declared Win recorded / counted
Tasks Rules! What beats what? R > S P > R S > P
Tasks Win is recorded Keeping Score! How will we know who wins User win or computer win After x wins, computer or human wins match (best of x matches)