COP 3503 FALL 2012 Shayan Javed Lecture 10
description
Transcript of COP 3503 FALL 2012 Shayan Javed Lecture 10
![Page 1: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/1.jpg)
1 / 301
COP 3503 FALL 2012SHAYAN JAVED
LECTURE 10
Programming Fundamentals using Java
![Page 2: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/2.jpg)
2 / 30
In-Class Exercise
![Page 3: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/3.jpg)
3 / 30
Extra Credit
2% extra credit
![Page 4: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/4.jpg)
4 / 30
Angry Birds
How many of you have played it?
![Page 5: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/5.jpg)
5 / 30
Angry Birds
Well-designed, simple game
![Page 6: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/6.jpg)
6 / 30
Angry Birds
Well-designed, simple game
Throw birds at pigs
![Page 7: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/7.jpg)
7 / 30
Angry Birds
Well-designed, simple game
Throw birds at pigs Physics!
![Page 8: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/8.jpg)
8 / 30
Angry Birds
Well-designed, simple game
Throw birds at pigs Physics!
Made millions
![Page 9: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/9.jpg)
9 / 30
Angry Birds
Well-designed, simple game
Throw birds at pigs Physics!
Made millions
Available on pretty much every platform
![Page 10: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/10.jpg)
10 / 30
Angry Birds
Well-designed, simple game
Throw birds at pigs Physics!
Made millions
Available on pretty much every platform Even Google Chrome!
![Page 11: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/11.jpg)
11 / 30
Angry Birds
Exercise:
Design the class structure for the game (UML diagram)
![Page 12: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/12.jpg)
12 / 30
Angry Birds
Exercise:
Design the class structure for the game (UML diagram)
Try to use everything we have learned so far: Classes/Inheritance/Abstract Classes Interfaces Interaction between classes
![Page 13: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/13.jpg)
13 / 30
Angry Birds
Quick look at some of the “objects” in the game: Different types of birds:
Red (Regular) Blue (explodes into 3 smaller ones) Yellow (accelerates mid-air) Black (explodes)
3 more but we can skip those...
![Page 14: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/14.jpg)
14 / 30
Angry Birds
Different types of pigs:
![Page 15: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/15.jpg)
15 / 30
Angry Birds
Different barriers
![Page 16: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/16.jpg)
16 / 30
Angry Birds
Possible solution:
Start off with a class which forms the basis of every object in the world
![Page 17: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/17.jpg)
17 / 30
Angry Birds
abstract class Sprite implements Cloneable {Point position;Image bitmapFile; // JPEG, PNG, etc...
double sizeX;double sizeY;
public Object clone() {} // clone method}
![Page 18: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/18.jpg)
18 / 30
Angry Birds
abstract class Bird extends Sprite implements Cloneable {double strength;public Object clone() {} // clone method
}
![Page 19: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/19.jpg)
19 / 30
Angry Birds
abstract class Bird extends Sprite implements Cloneable {double strength;public Object clone() {} // clone method
}
class RedBird extends Bird implements Cloneable { // inherits properties from superclasspublic Object clone() {} // clone method
}
![Page 20: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/20.jpg)
20 / 30
Angry Birds
abstract class Bird extends Sprite implements Cloneable {double strength;public Object clone() {} // clone method
}
class RedBird extends Bird implements Cloneable { // inherits properties from superclasspublic Object clone() {} // clone method
}
abstract class SpecialBird extends Bird implements Cloneable {abstract specialMove(); // {abstract method} executed on tap
}
![Page 21: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/21.jpg)
21 / 30
Angry Birds
class BlueBird extends SpecialBird implements Cloneable {specialMove() { }
}
class YellowBird extends SpecialBird implements Cloneable {specialMove() { }
}
class BlackBird extends SpecialBird implements Cloneable {specialMove() { }
}
![Page 22: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/22.jpg)
22 / 30
Angry Birds
abstract class Pig extends Sprite implements Cloneable {double health;public Object clone() {} // clone method
}
![Page 23: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/23.jpg)
23 / 30
Angry Birds
abstract class Pig extends Sprite implements Cloneable {double health;public Object clone() {} // clone method
}
class SmallPig extends Pig implements Cloneable { // inherits properties from superclass
}
![Page 24: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/24.jpg)
24 / 30
Angry Birds
abstract class Pig extends Sprite implements Cloneable {double health;public Object clone() {} // clone method
}
class SmallPig extends Pig implements Cloneable { // inherits properties from superclass
}
class MediumPig, BigPig, HelmetPig, KingPig, etc.
![Page 25: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/25.jpg)
25 / 30
Angry Birds
abstract class Pig extends Sprite implements Cloneable {double health;public Object clone() {} // clone method
}
class SmallPig extends Pig implements Cloneable { // inherits properties from superclass
}
class MediumPig, BigPig, HelmetPig, KingPig, etc.
// each have their own images, sizes, etc.
![Page 26: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/26.jpg)
26 / 30
Angry Birds
abstract class Barrier extends Sprite implements Cloneable {double strength, density, etc..;public Object clone() {} // clone method
}
class IceBarrier, WoodBarrier, StoneBarrier, etc.
// each have their own images, sizes, etc.
![Page 27: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/27.jpg)
27 / 30
AngryBirds
One last class...
![Page 28: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/28.jpg)
28 / 30
AngryBirds
One last class...
class Level implements ? {// what properties?
}
![Page 29: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/29.jpg)
29 / 30
AngryBirds
One last class...
class Level implements Cloneable {// what properties?
public Object clone() {…} }
![Page 30: COP 3503 FALL 2012 Shayan Javed Lecture 10](https://reader034.fdocuments.us/reader034/viewer/2022051402/56816223550346895dd250ae/html5/thumbnails/30.jpg)
30 / 30
AngryBirds
One last class...
class Level implements Cloneable {ArrayList<Bird> birds;ArrayList<Pig> pigs;ArrayList<Barrier> barriers;
public Object clone() {…} }