Tower defense (OOP4Fun Book)

5. Association

6h 25min
  • TS 5.1. Greenfoot Objects on a Mission: Exploring Methods and Associations
  • TS 5.2. Greenfoot Objects on a Mission: Exploring Associations and Advanced Method Calls
  • TS 5.3. Greenfoot Objects on a Mission: Towers, Bullets, and Strategic Interactions
  • TS 5.4. Greenfoot Objects on a Mission: Bullets, Enemies, and Game Dynamics

Understanding the basic principles of object-oriented programming (30%)
Understanding the basics of algorithmisation (30%)
Understanding the syntax of the Java programming language (10%)
The ability of creating own programs with the use of OOP (30%)
TS 5.1. Greenfoot Objects on a Mission: Exploring Methods and Associations
Investigation
1 Task 5.1

Discuss what should happen when enemy reaches orb.


10 min
Investigation
2 Task 5.2

Discuss how instance of class Enemy should interact with the relevant objects using messages when hitting instance of class Orb.


15 min
Acquisition
3 Task 5.3

Attribute Enemy.attack and Orb.hp.


10 min
Discussion
4 Method

The teacher begins by explaining the concept of methods as encapsulated actions or behaviors within a class. Using practical examples, the teacher demonstrates the syntax and structure of method definitions, illustrating how methods are invoked on objects. Students learn about different types of methods, including those that perform actions (void methods) and those that return values (return type methods). The teacher explains how parameters are passed to methods, highlighting the importance of parameter types and order.  Through guided coding exercises, students practice defining methods with various parameter and return types, and invoking these methods on object instances. They explore scenarios where methods perform actions, modify object states, or return specific values, solidifying their understanding of method functionality within a class.


15 min
Production
5 Task 5.4

Getter of attribute Enemy.attack.


5 min
Production
6 Task 5.5

Create and test method Arena.respawn(Enemy).


10 min
Practice
7 Task 5.6

Create and test method Orb.hit(Enemy).


10 min
TS 5.2. Greenfoot Objects on a Mission: Exploring Associations and Advanced Method Calls
Discussion
1 Association

The lesson begins with a brief review of associations between classes in object-oriented programming. The teacher engages students in a discussion to clarify how objects interact with each other through associations, using practical examples from the Greenfoot environment to illustrate these concepts.Students delve into understanding that associations define how classes collaborate, such as how an Enemy can affect an Orb in a game scenario.


10 min
Practice
2 Task 5.7

Call method Orb.hit(Enemy) from Enemy.


15 min
Discussion
3 Explanation of the code for methods Greenfoot.stop() and World.getWorldOfType(_cls_)

15 min
Practice
4 Task 5.8

Students starts implementing the Orb.hit(Enemy) method, a crucial step in defining the interaction between an enemy and the orb within their game scenario.


30 min
TS 5.3. Greenfoot Objects on a Mission: Towers, Bullets, and Strategic Interactions
Production
1 Task 5.9

Create classes Bullet and Tower.


10 min
Practice
2 Task 5.10

Discuss how the instance of class Bullet should move and what should happen when it reaches instance of class Enemy or edge of the arena.


10 min
Practice
3 Task 5.11

Implement movement of instance of class Bullet


30 min
Practice
4 Task 5.12

Discuss how the instance of class Tower will shoot instance of class Bullet.


15 min
Practice
5 Task 5.13

Discuss how instance of class Tower should interact with the relevant objects using messages when shooting-


15 min
Production
6 Task 5.14

Implement shooting of instance of class Tower


30 min
Production
7 Task 5.15

Towers in Arena (20 minutes)


20 min
TS 5.4. Greenfoot Objects on a Mission: Bullets, Enemies, and Game Dynamics
Discussion
1 Task 5.16

Discuss how instance of class Bullet should interact with the relevant objects using messages.


15 min
Production
2 Task 5.17

Implement instance of class Bullet hitting instance of class Enemy (30 minutes)


30 min
Acquisition
3 Explanation of the code

Explanation of the code for methods Greenfoot.showText(String, int, int), Greenfoot.getRandomNumber(int) and World.act()


15 min
Production
4 Task 5.18

Spawn of enemies and end of the game (30 minutes)


30 min
Discussion
5 Revision of Associations

20 min