Esempio n. 1
0
 def __setitem__(self,key,value):
     """
     This wraps dict's __setitem__, ensuring that the key is an instance of
     Coords. (You can pass in a regular 2-tuple and it will be converted.)
     It also ensures the coords are within the bounds of the board.
     """
     coords = Coords.make(key) # Make sure everything is a Coord
     if not self.checkWithinBounds(coords):
         raise Exception, "{0} out of bounds.".format(coords)
     else:
         dict.__setitem__(self,coords,value)
Esempio n. 2
0
 def displaySize(self):
     return Coords.make(self.screen.rect.size)
Esempio n. 3
0
 def checkWithinBounds(self,coords):
     """Returns true if the given coords are within the board's bounds."""
     trueCoords = Coords.make(coords)
     withinXBounds = (self.width == None) or (trueCoords.x >= 0 and trueCoords.x < self.width)
     withinYBounds = (self.height == None) or (trueCoords.y >= 0 and trueCoords.y < self.height)
     return withinXBounds and withinYBounds
Esempio n. 4
0
 def __getitem__(self,key):
     coords = Coords.make(key)
     if not self.checkWithinBounds(coords):
         raise Exception, "{0} out of bounds.".format(coords)
     else:
         return dict.__getitem__(self,coords)