Carcigenicate

Grid

May 16th, 2014
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. width = 15
  2. length = 10;
  3.  
  4. class point:
  5.     def __init__ (self, xin, yin, dispin = '!'):
  6.         self.xpos, self.ypos = xin, yin
  7.         self.disp = dispin
  8.    
  9.     def set_pos (self, x, y):
  10.         self.xpos, self.ypos = x, y
  11.  
  12. class Data:
  13.     def __init__ (self):
  14.         self.points = []
  15.  
  16.     def search_coord (self, x, y):
  17.         for check in self.points:
  18.             if check.xpos == x and check.ypos == y:
  19.                 return check.disp
  20.         return ' '
  21.        
  22.     def display (self):
  23.         for yd in range (length):
  24.             for xd in range (width):
  25.                 occ = self.search_coord (xd, yd)
  26.                 print ("{:>3}".format (occ), end = '')
  27.             print ('\n')
  28.  
  29.     def add_point (self, x, y, d = '?'):
  30.         tpoint = point (x, y, d)
  31.         self.points.append (tpoint)
  32.        
  33. data = Data ()
  34.  
  35. data.add_point (0, 0, '$')
  36. data.add_point (5, 5, '+')
  37. data.add_point (9, 9, '()')
  38.  
  39. data.display ()
Advertisement
Add Comment
Please, Sign In to add comment