## Creature Project ## CSC323 ## 4/17/10 ## Direction.py: Contains the Direction enumerated type: N,NE,E,SE,S,SW,W,NW,C. class Direction: """Static method used for defining the positions at which a cell can be located""" @staticmethod def fromString(string): if string=="N": return N elif string=="NE": return NE elif string=="E": return E elif string=="SE": return SE elif string=="S": return S elif string=="SW": return SW elif string=="W": return W elif string=="NW": return NW else: #Not a Direction raise Error("Not a Direction") def getDirection(x, y): """This method takes an x and y coordinator and returns proper direction Direction is based on 3 x 3 grid where (0,0) is NW and (2,2) is SE""" x = x%3 y = y%3 if x == 0: if y == 0: return NW elif y == 1: return N elif y == 2: return NE elif x == 1: if y == 0: return W elif y == 1: return C elif y == 2: return E elif x == 2: if y == 0: return SW elif y == 1: return S elif y == 2: return SE class N: x = 0 y = -1 def __str__(): return "N" class NE: x = 1 y = -1 def __str__(): return "NE" class E: x = 1 y = 0 def __str__(): return "E" class SE: x = 1 y = 1 def __str__(): return "SE" class S: x = 0 y = 1 def __str__(): return "S" class SW: x = -1 y = 1 def __str__(): return "SW" class W: x = -1 y = 0 def __str__(): return "W" class NW: x = -1 y = -1 def __str__(): return "NW" class C: x = 0 y = 0 def __str__(): return "C"