Lecture10-Oct12

advertisement
1 / 30
1
COP 3503 FALL 2012
SHAYAN JAVED
LECTURE 10
Programming Fundamentals using Java
2 / 30
In-Class Exercise
3 / 30
Extra Credit

2% extra credit
4 / 30
Angry Birds
How many of you have played it?
5 / 30
Angry Birds

Well-designed, simple game
6 / 30
Angry Birds

Well-designed, simple game

Throw birds at pigs
7 / 30
Angry Birds

Well-designed, simple game

Throw birds at pigs
 Physics!
8 / 30
Angry Birds

Well-designed, simple game

Throw birds at pigs
 Physics!

Made millions
9 / 30
Angry Birds

Well-designed, simple game

Throw birds at pigs
 Physics!

Made millions

Available on pretty much every platform
10 / 30
Angry Birds

Well-designed, simple game

Throw birds at pigs
 Physics!

Made millions

Available on pretty much every platform
 Even
Google Chrome!
11 / 30
Angry Birds

Exercise:

Design the class structure for the game (UML
diagram)
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
 Interfaces
 Interaction
between classes
Classes
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...
14 / 30
Angry Birds

Different types of pigs:
15 / 30
Angry Birds

Different barriers
16 / 30
Angry Birds

Possible solution:

Start off with a class which forms the basis of every
object in the world
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
}
18 / 30
Angry Birds
abstract class Bird extends Sprite implements Cloneable {
double strength;
public Object clone() {} // clone method
}
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 superclass
public Object clone() {} // clone method
}
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 superclass
public Object clone() {} // clone method
}
abstract class SpecialBird extends Bird implements Cloneable {
abstract specialMove(); // {abstract method} executed on tap
}
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() { }
}
22 / 30
Angry Birds
abstract class Pig extends Sprite implements Cloneable {
double health;
public Object clone() {} // clone method
}
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
}
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.
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.
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.
27 / 30
AngryBirds

One last class...
28 / 30
AngryBirds

One last class...
class Level implements ? {
// what properties?
}
29 / 30
AngryBirds

One last class...
class Level implements Cloneable {
// what properties?
public Object clone() {…}
}
30 / 30
AngryBirds

One last class...
class Level implements Cloneable {
ArrayList<Bird> birds;
ArrayList<Pig> pigs;
ArrayList<Barrier> barriers;
public Object clone() {…}
}
Download