300 likes | 402 Views
COP 3503 FALL 2012 Shayan Javed Lecture 10. Programming Fundamentals using Java. In-Class Exercise. Extra Credit. 2% extra credit. Angry Birds. How many of you have played it?. Angry Birds. Well-designed, simple game. Angry Birds. Well-designed, simple game Throw birds at pigs .
E N D
COP 3503 FALL 2012ShayanJavedLecture 10 Programming Fundamentals using Java
Extra Credit • 2% extra credit
Angry Birds How many of you have played it?
Angry Birds • Well-designed, simple game
Angry Birds • Well-designed, simple game • Throw birds at pigs
Angry Birds • Well-designed, simple game • Throw birds at pigs • Physics!
Angry Birds • Well-designed, simple game • Throw birds at pigs • Physics! • Made millions
Angry Birds • Well-designed, simple game • Throw birds at pigs • Physics! • Made millions • Available on pretty much every platform
Angry Birds • Well-designed, simple game • Throw birds at pigs • Physics! • Made millions • Available on pretty much every platform • Even Google Chrome!
Angry Birds • Exercise: • Design the class structure for the game (UML diagram)
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
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...
Angry Birds • Different types of pigs:
Angry Birds • Different barriers
Angry Birds • Possible solution: • Start off with a class which forms the basis of every object in the world
Angry Birds abstract class Sprite implementsCloneable { Point position; ImagebitmapFile; // JPEG, PNG, etc... doublesizeX; doublesizeY; public Object clone() {} // clone method }
Angry Birds abstract class Bird extendsSpriteimplementsCloneable { double strength; public Object clone() {} // clone method }
Angry Birds abstract class Bird extendsSpriteimplementsCloneable { double strength; public Object clone() {} // clone method } class RedBirdextendsBirdimplementsCloneable { // inherits properties from superclass public Object clone() {} // clone method }
Angry Birds abstract class Bird extendsSpriteimplementsCloneable { double strength; public Object clone() {} // clone method } class RedBirdextendsBirdimplementsCloneable { // inherits properties from superclass public Object clone() {} // clone method } abstract class SpecialBirdextendsBirdimplementsCloneable { abstractspecialMove(); // {abstract method} executed on tap }
Angry Birds class BlueBirdextendsSpecialBirdimplementsCloneable { specialMove() { } } class YellowBirdextendsSpecialBirdimplementsCloneable { specialMove() { } } class BlackBirdextendsSpecialBirdimplementsCloneable { specialMove() { } }
Angry Birds abstract class Pig extendsSpriteimplementsCloneable { double health; public Object clone() {} // clone method }
Angry Birds abstract class Pig extendsSpriteimplementsCloneable { double health; public Object clone() {} // clone method } class SmallPigextendsPigimplementsCloneable { // inherits properties from superclass }
Angry Birds abstract class Pig extendsSpriteimplementsCloneable { double health; public Object clone() {} // clone method } class SmallPigextendsPigimplementsCloneable { // inherits properties from superclass } class MediumPig, BigPig, HelmetPig, KingPig, etc.
Angry Birds abstract class Pig extendsSpriteimplementsCloneable { double health; public Object clone() {} // clone method } class SmallPigextendsPigimplementsCloneable { // inherits properties from superclass } class MediumPig, BigPig, HelmetPig, KingPig, etc. // each have their own images, sizes, etc.
Angry Birds abstract class Barrier extendsSpriteimplementsCloneable { double strength, density, etc..; public Object clone() {} // clone method } class IceBarrier, WoodBarrier, StoneBarrier, etc. // each have their own images, sizes, etc.
AngryBirds • One last class...
AngryBirds • One last class... class Level implements ? { // what properties? }
AngryBirds • One last class... class Level implementsCloneable { // what properties? publicObject clone() {…} }
AngryBirds • One last class... class Level implementsCloneable { ArrayList<Bird> birds; ArrayList<Pig> pigs; ArrayList<Barrier> barriers; publicObject clone() {…} }