-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.py
More file actions
42 lines (32 loc) · 1.2 KB
/
Screen.py
File metadata and controls
42 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Screen(object):
def __init__(self, x_length, y_length):
self.screen = self.create_screen(x_length, y_length)
def __repr__(self):
return '\n'.join(str(self.screen)[1:-1].split(','))
def __iter__(self):
self.iter_screen = [row[:] for row in self.screen]
return self
def next(self):
if len(self.iter_screen) > 0:
return self.iter_screen.pop(0)
else:
raise StopIteration
def create_screen(self, x_length, y_length):
return [[0 for x in xrange(x_length)] for y in xrange(y_length)]
def copy_array(self):
return [row[:] for row in self.screen]
def plot(self, xcor, ycor, new_value=1):
self.screen[ycor][xcor] = new_value
def get(self, xcor, ycor):
return self.screen[ycor][xcor]
def contains(self, xcor, ycor):
try:
self.get(xcor, ycor)
return True
except IndexError:
return False
def clear(self, xcor=None, ycor=None):
assert xcor is None ^ ycor is None, 'You need to pass both arguments!'
if xcor is None and ycor is None:
self.screen = self.create_screen
self.screen[ycor][xcor] = 0