Anonymous avatar Anonymous committed 9b5db54

Changed potion to a class and started implementing colour changes.

Comments (0)

Files changed (2)

alchemymadness/main.py

     pygame.display.flip()
 
     # Initialise level
-    potion.set_formula(10, 20, 30)
+    pot = potion.Potion()
+    pot.set_formula(10, 20, 30)
 
     while going:
         time = clock.tick(30)
+        screen.blit(background, (0,0))
+
+        rects = []
         events = pygame.event.get()
         for e in events:
             if e.type == QUIT or e.type == KEYDOWN and e.key == K_ESCAPE:
                 going = False
 
-        screen.blit(background, (0,0))
-        rects = []
         pygame.display.update(rects)
 
     # End game
-    score = potion.get_score()
+    score = pot.get_score()
 
     pygame.quit()

alchemymadness/potion.py

 """Mixing potion"""
 
-def set_formula(r=0, g=0, b=0):
-    """Set the target formula for the level."""
-    pass
+from pygame.locals import Rect
 
-def add_color(col):
-    """
-    Add a colour from a player's board.
+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)
 
-    Args:
-      col: tuple containing rgb colour.
+    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)
 
-    """
-    pass
+    def add_color(self, col):
+        """
+        Add a colour from a player's board.
 
-def get_score():
-    """Returns a score based on accuracy of the formula."""
-    pass
+        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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.