Tower defense (OOP4Fun Book)

3. Branching

3h 35min
  • TS 3.1. Exploring Branching through Game Development with Greenfoot – Incomplete code branching 
  • TS 3.2. Exploring Branching through Game Development with Greenfoot 

Understanding the basic principles of object-oriented programming (10%)
Understanding the basics of algorithmisation (60%)
Understanding the syntax of the Java programming language (10%)
Analysing program execution based on the source code (10%)
The ability of creating own programs with the use of OOP (10%)
TS 3.1. Exploring Branching through Game Development with Greenfoot – Incomplete code branching
Discussion
1 Introduction

The teacher discusses with the students the concepts that were covered in the previous lesson. Teacher introduces goals for this teaching session.


5 min
Acquisition
2 Code explanation

The teacher downloads the latest version of the project:

·       From Moodle platform

·       Fromgit repository

The teacher creates and places an Enemy class object somewhere on the board. It explains some methods of the Actor class:

·       move(int)

·       turn(int)

·       setRotation()

While explaining the methods, the teacher also shows how certain properties of the class are changed (for example, the position of the object on the board, ie the x and y values). The teacher discusses with the students how to supplement the act() method so that every time the act() method is called, the Enemy class object should move two steps forward.


15 min
Acquisition
3 Incomplete branching

The teacher continues to work on the project. The teacher places an Enemy class object on the board. The teacher explains to the students how they can check if the object is in the upper half of the board and displays the message "Found".


10 min
Investigation
4 Observing the players’

The teacher creates an instance of the Enemy class and places it in the center of the board. The teacher opens a window with the internal state of the instance and positions it so that it is visible while the application is running. Then run the application and observe how the values of the x, yandrotationattributes in the Enemyclass change when call different methods. How do these values change as you move (up, down, left, and right) and turn?


10 min
Practice
5 Adding world edge detection

Task 3.2: Teacher asignt task to students to add code to the body of the act() method to rotate the enemy 180° by calling the setRotation() property, when it reaches the edge of the world.


10 min
TS 3.2. Exploring Branching through Game Development with Greenfoot
Production
1 Add classes Direction and Orb

Task 3.3: Create two new classes, descendants of the Actor class. The first class will be Direction class and the second class will be Orb. Prepare suitable (max. 50x50 pixel) images in a graphical editor. Then assign these images to the newly created classes.


30 min
Investigation
2 Collision detection explanation

The teacher put an instance of the Enemy class on the World, and an instance of the Direction class in the same row. The teacher adds code to the act() method so that the object moves one step forward.

The teacher explains to the students how to determine whether two or more objects ("characters") on the World are in the same position (on the same cell). The teacher explains the method: isTouching().

The teacher and students modify the act() method of the Enemy class to ensure that the enemy rotates 90° clockwise when it is in the same cell that contains an instance of the Direction class.

Together with the students, the teacher observes what happens with the rotation attribute.


30 min
Practice
3 Task 3.4

Add code to the act() method of the Enemy class to ensure that:

    • the player turns 90° counter clockwise when he enters a cell the contains an instance of the Orb class.

10 min
Practice
4 Task 3.5

Prepare different configurations, inspiration can be found in the figures below. Guess how the enemy will move? Run the application. Does your prediction match what you observe? What caused differences in prediction and reality?


10 min
Practice
5 Task 3.6

The teacher assigns the students the task of describing on paper how a pedestrian crosses the street.


15 min
Acquisition
6 Code explanation: Complete branching

Complete branching


15 min
Practice
7 Task 3.7

Teacher adds assignment to students to work on task 3.7. Teacher follows the students activities, and in the end he asks one student to present his work.  The student describes and presents his work.


20 min
0
Investigation
8 Task 3.8

Predict enemy movement on custom setup.
The teacher puts objects arbitrarily in the World, and the students explain their movement and behavior (independently or in pairs).

 


30 min
Discussion
9 Revision

The teacher summarizes the lesson.


5 min