Source

pygamegsoc12 / alchemymadness / potion.py

"""Mixing potion"""

from pygame.locals import Rect

class Potion():
    chems = 0  # Chem count
    formula = (0,0,0)  # Target formula
    col = (0,0,0)  # Current formula
    max_chems = 0  # Target number of chems
    rect = Rect(300, 300, 300, 200)

    def set_formula(self, r=0, g=0, b=0):
        """Set the target formula for the level."""
        self.chems = 0
        self.formula = (r, g, b)
        self.max_chems = sum(self.formula)

    def add_color(self, col):
        """
        Add a colour from a player's board.

        Args:
          col: tuple containing rgb colour.

        """
        self.chems += 1
        n = ((self.chems-1) / float(self.chems))
        self.col = (self.col[0] * n, self.col[1] * n, self.col[2] * n)
        self.col = (self.col[0] + col[0]/float(self.chems),
                    self.col[1] + col[1]/float(self.chems),
                    self.col[2] + col[2]/float(self.chems))

    def get_score(self):
        """Returns a score based on accuracy of the formula."""
        pass