class Entity: def __init__(self, e): self.entity_type = e[0] self.owner = e[1] self.x = e[2] self.y = e[3] self.param_1 = e[4] self.param_2 = e[5] class Field: def __init__(self, width, height): self.w = width self.h = height self.m = [['x' for i in xrange(self.w)] for i in xrange(self.h)] def __str__(self): for row in range(len(self.m)): print self.m[row] return "done" def copy_row(self, row, num): if num >= self.h: print >> sys.stderr, "ERROR Field:copy_row num too big" elif len(row) != self.w: print >> sys.stderr, "ERROR Field:copy_row row size not matching" else: self.m[num] = list(row)[:] def num_of_boxes(self): x = 0 for line in range(self.h): x = x + self.m[line].count(0) return x #TEST CODE r1 = ['.', 0, '.', 0] x = Field(3, 4) print x.m x.copy_row(r1, 2) print x.m
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question