Changeset 112:2d048c0ed5e3
- Timestamp:
- 12/20/10 12:58:45 (5 years ago)
- Branch:
- default
- Parents:
- 110:763c07539658 (diff), 111:9486211ec334 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
snake.py
- Property exe set to *
r109 r112 ˆà 66 66 for cell in self.cells:ˆà 67 67 cell.snake = selfˆà ˆà 68 for cell in self.cells:ˆà ˆà 69 cell.type = 'body'ˆà 68 70 self.cells[0].type = 'head'ˆà 69 ˆà for cell in self.cells[1:-1]:ˆà70 ˆà cell.type = 'body'ˆà71 71 self.cells[-1].type = 'tail'ˆà 72 72 returnˆà -
snake.py
r111 r112 ˆà 9 9 line = line.rstrip()ˆà 10 10 return lineˆà ˆà 11 ˆà ˆà 12 class File(object):ˆà ˆà 13 """Wrapper around file that saves the current line number."""ˆà ˆà 14 def __init__(self, file):ˆà ˆà 15 self.file = fileˆà ˆà 16 self.name = file.nameˆà ˆà 17 self.line_no = 0ˆà ˆà 18 def __iter__(self):ˆà ˆà 19 for line_no, line in enumerate(self.file, self.line_no):ˆà ˆà 20 self.line_no = line_noˆà ˆà 21 yield lineˆà 11 22 ˆà 12 23 class Snake(object):ˆà òÀæ òÀæ ˆà 32 43 See program design docs for file syntax.ˆà 33 44 """ˆà ˆà 45 file = File(file)ˆà ˆà 46 try:ˆà ˆà 47 self._load(file)ˆà ˆà 48 except Exception, e:ˆà ˆà 49 raise Exception("%s:%s: %s" % (file.name, file.line_no, e))ˆà ˆà 50 ˆà ˆà 51 def _load (self, file):ˆà ˆà 52 """Actually do the loading."""ˆà 34 53 for line in file:ˆà 35 54 magic, self.name = preprocess(line).split(' ', 1)ˆà
Note: See TracChangeset
for help on using the changeset viewer.