Teacher's Guide

Chapter 9 / Level 2: Class members

Teaching Objective:

  • Student learns how to create a class members, multiple objects using the same class
  • Understands the __init__ syntax when creating a class
  • Learns how to construct objects and use them modularly

Guide

For this level you need to complete the roads using the materials in the field. Classes are used to create the objects in order to use the build() function.

class road:
    cost = 4

    def __init__(self, material):
        self.material = material

Grab all the planks and stones in the field and set up the class, then create objects in order to be used with the build() function.

wood_road = road("wood")
stone_road = road("stone")

Once you grab all the planks, walk to the X marks and build up the wooden road, then do the same for the stone items in the field.

player.build(wood_road)

........

player.build(stone_road)

Map overview and path

Map overview and path

Code Solution

import player
class road:
    number = 4
    def __init__(self, material):
       self.material = material
wood_road = road("wood")
stone_road = road("stone")
player.turn_left()
player.move_forward(5)
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward(3)
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(6)
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward()
player.turn_left()
player.move_forward(5)
player.build(wood_road)
player.turn_left()
player.move_forward()
player.turn_right()
player.build(wood_road)
player.turn_left()
player.move_forward()
player.turn_left()
player.move_forward(8)
player.turn_left()
player.move_forward(2)
player.turn_right()
player.build(stone_road)
player.turn_left()
player.move_forward()
player.turn_right()
player.build(stone_road)
Chapter 9 / Level 2: Class members | Teacher's Guide