4. package foo
{
public class Person
{
private var name:String;
public function Person(name:String)
{
this.name = name;
}
public function introduce():String
{
return "My name is " + name;
}
}
}
1
2
3
4
5
Class
6. package foo
{
public class Rapper extends Person
{
public function Rapper(name:String)
{
super(name);
}
}
}
import foo.Rapper;
var snoopDog:Rapper = new Rapper("Snoop Dogg");
snoopDog.introduce(); //My name is Snoop Dogg
1
2
3
Inheritance
7. package foo
{
public class Rapper extends Person
{
public function Rapper(name:String)
{
super(name);
}
override public function introduce():String
{
return "YO! " + super.introduce();
}
}
}
import foo.Rapper;
var snoopDog:Rapper = new Rapper("Snoop Dogg");
snoopDog.introduce(); //YO! My name is Snoop Dogg
2
3
Polymorphism
1
8. Enakpsulaton
Hiding implementaton and exposing only desired API
Access modifiers:
● public – for everyone
● protected – only for the same class or subclasses
● internal – only for the same package
● private – only the same class
14. Task 1
Moving a Giant:
● Giant can move horizontally and vertcally
● smoothing
15. Task 2
Enemies:
● Two classes should inherit from Enemy
● Enemy_1 moves quickly, along straight line
● Enemy_1 need single hit to be destroyed
● Enemy_2 moves slowly, along sine wave
● Enemy_2 needs double hit to be destroyed
enemy_1 enemy_2
16. Task 3
Giant – Enemy collision:
● Collision causes showing boom animaton
● Collision takes one Giant's life
17. Task 4
Shootng enemies:
● Enemies can shoot with random frequency
● Hitting Giant with bullet takes one life