Download presentation
Presentation is loading. Please wait.
Published byAlban Curtis Modified over 8 years ago
1
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 1 Lesson 2: Pong Class Design
2
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 2 Review What classes did we identify? What behaviors does each class display?
3
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 3
4
4 Inheritance Relationships Name some features of cars What are features that all cars have? How are British cars different from American cars? How does a Mini Cooper in London differ from one in California? How is a Mini Cooper in California similar to a Ford Escort in New York?
5
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 5 Inheritance Classes may inherit features from other classes Similar classes may inherit features from a single parent class (e.g. “British cars” are Cars, “American cars” are Cars) This is a called an “is-a” relationship “Car” is a parent of “British car” and “American car”
6
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 6 Inheritance What is the difference between inheriting features from a class, and being an instance of that class?
7
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 7 Provided Classes for Pong Game –Is a parent for the Pong class GameObject –Is a parent for the Paddle and Ball class
8
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 8
9
9 Provided Methods Game –void add(GameObject o): Adds an object to the screen –boolean ZKeyPressed(), boolean XKeyPressed(), boolean NKeyPressed(), boolean MKeyPressed(): Tests whether or not a user is attempting to move a paddle
10
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 10 Provided Methods GameObject –boolean collides(GameObject o): Tests for collision with another object –int getX(), int getY(): returns the X and Y positions of an object –void setX(int x), void setY(int y): sets the X and Y positions of an object –void setSize(int width, int height): sets the size of an object
11
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 11 Explore What is Provided How can the provided methods help you implement the necessary behaviors of each class? Which provided methods will be used in each behavior?
12
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 12 Required Methods Child classes of Game must implement: –void setup() –void act() Child classes of GameObject must implement: –void act()
13
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 13 Homework What relationships exist between objects? How do objects interact with each other?
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.