Marble_Pile, class

# Marble_Pile, class

class Marble_Pile:
  def __init__(self, x, z, h, m):
    self.x = 0
    self.z = z
    self.h = h
    self.m = m    
    self.build()

  def build(self):
    column(self.x, self.z, self.h, self.m)

  def putOnce(self, n, color):
    self.x += 2
    self.h = n
    self.m = color
    self.build()

  def putTwice(self, n, color):
    self.putOnce(n, color)
    self.putOnce(n, color)

Class Marble_Pile is similar to previous class Marble_bag. We can see in CodeCraft how the objects of the Marble_Pile behaves:

~ Marble_Pile object has some marbles as base when created and initialized;

~ Method putOnce(n, color) can add n marbles with specific color;

~ Method putTwice(n, color) can add two more piles in another color: each has n marbles;

~ Method build() is to be called in all other methods (including __init__) to build the current pile.

~ Object property (which indicates the x location of the current pile), is updated as self.x += 2 in method putOnce(n, color) to make sure a newly build pile is shifted two blocks to the right of the existing piles.

((??~ We use an instance variable n to keep track of the x location of the newly build column. ))

results matching ""

    No results matching ""