Teacher's Guide

Chapter 9 / Level 3: Class methods

Teaching Objective:

  • Student learns how to create and manipulate unique class methods
  • Learns how to set up object properties using the class
  • Understands how to create objects that can interface with build()

Guide

In this exercise you must collect planks and build 4 chicken houses. Using classes, you can create objects and modify their properties at will.

class chicken_house:
    color = ""
    size = ""

First create a class with two variables, color and size . Afterwards grab all the planks in the field and walk to the X marks to build the chicken houses. Create 4 different objects using the class and name them: big_green_house , small_blue_house , big_orange_house , small_red_house .

big_green_house = chicken_house()
big_green_house.color = "green"
big_green_house.size = "big"

small_blue_house = chicken_house()
small_blue_house.color = "blue"
small_blue_house.size = "small"

big_orange_house = chicken_house()
big_orange_house.color = "orange"
big_orange_house.size = "big"

small_red_house = chicken_house()
small_red_house.color = "red"
small_red_house.size = "small"

After creating each object, use the build() function to create the chicken houses while standing on the X marks and facing the empty lots to complete the level.

player.build(big_green_house)

........

player.build(small_blue_house)

........

player.build(big_orange_house)

........

player.build(small_red_house)

Map overview and path

Map overview and path

Code Solution

import player

class chicken_house:
	color = ""
	size = ""
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(2)
player.turn_left()
player.move_forward(3)
player.turn_left()
player.move_forward(3)
player.turn_right()
player.move_forward(3)
player.turn_left()
player.move_forward(7)
big_green_house = chicken_house()
big_green_house.color = "green"
big_green_house.size = "big"
small_blue_house = chicken_house()
small_blue_house.color = "blue"
small_blue_house.size = "small"
big_orange_house = chicken_house()
big_orange_house.color = "orange"
big_orange_house.size = "big"
small_red_house = chicken_house()
small_red_house.color = "red"
small_red_house.size = "small"
player.turn_right()
player.build(small_blue_house)
player.turn_right()
player.move_forward(3)
player.turn_left()
player.move_forward()
player.build(big_green_house)
player.turn_right()
player.turn_right()
player.move_forward(5)
player.turn_left()
player.move_forward(6)
player.turn_left()
player.build(small_red_house)
player.turn_left()
player.move_forward()
player.turn_right()
player.move_forward(2)
player.build(big_orange_house)
Chapter 9 / Level 3: Class methods | Teacher's Guide