def test_dots_left(): """ Test dots_left method""" ds = Dots(600, 600, 150, 450, 150, 450) dl = ds.dots_left() print(dl) assert dl == ((ds.WIDTH // ds.SPACING + 1) * 2 + (ds.HEIGHT // ds.SPACING + 1) * 2)
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) # Testing the top row dots_to_eat = [] assert len(ds.top_row) == ds.WIDTH // ds.SPACING + 1 for i in range(len(ds.top_row)): dots_to_eat.append(ds.top_row[i]) ds.eat(dots_to_eat) assert len(ds.top_row) == 0 # Testing the bottom row assert len(ds.bottom_row) == ds.WIDTH // ds.SPACING + 1 dots_to_eat = [] for i in range(ds.WIDTH // ds.SPACING + 1): dots_to_eat.append(ds.bottom_row[0]) ds.eat(dots_to_eat) assert len(ds.bottom_row) == ds.WIDTH // ds.SPACING + 1 - 1 * (i + 1) # Testing the left column dots_to_eat = [] assert len(ds.left_col) == ds.HEIGHT // ds.SPACING + 1 for i in range(len(ds.left_col)): dots_to_eat.append(ds.left_col[0]) ds.eat(dots_to_eat) assert len(ds.top_row) == 0 # Testing the right column assert len(ds.right_col) == ds.HEIGHT // ds.SPACING + 1 dots_to_eat = [] for i in range(ds.HEIGHT // ds.SPACING + 1): dots_to_eat.append(ds.right_col[0]) ds.eat(dots_to_eat) assert len(ds.right_col) == ds.HEIGHT // ds.SPACING + 1 - 1 * (i + 1)
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) ds.eat(150, 150) assert ds.top_row[2].x == 225 assert len(ds.top_row) == 8 assert ds.left_col[2].y == 225 assert len(ds.left_col) == 8
def brim_drawburron(self): color = 0 if self.radioButton_17.isChecked(): color = 0 if self.radioButton_18.isChecked(): color = 1 if self.radioButton_19.isChecked(): color = 2 width, index = self.comboBox.currentText( ), self.comboBox_2.currentText() brim_draw = Image_manipulate(self.path) brimpath = brim_draw.brim_draw(self.dots, index, color, width) img = QtGui.QPixmap(brimpath) if img.width() <= img.height(): img = img.scaledToHeight(self.graphicsView.height()) else: img = img.scaledToWidth(self.graphicsView.width()) graphicscene = QtWidgets.QGraphicsScene() graphicscene.addPixmap(img) self.graphicsView.setScene(graphicscene) self.graphicsView.show() self.lineEdit_11.setText(brimpath) window = QtWidgets.QDialog() ui = Dots() ui.setupUi(window, self.dots[int(index)], str(self.img_size)[18:]) window.exec_()
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) ds.eat(56, 150) # pacman is able to eat the dot on (75, 150) and (0, 150) print(len(ds.top_row)) for dot in ds.top_row: assert not (dot.x == 75 and dot.y == 150) assert not (dot.x == 0 and dot.y == 150) ds.eat(450, 500) # pacman is able to eat the dot on (450, 525) and (450, 450) for dot in ds.right_col: assert not (dot.x == 450 and dot.y == 525) assert not (dot.x == 450 and dot.y == 450) ds.eat(150, 570) # pacman is able to eat the dot on (150, 600) for dot in ds.left_col: assert not (dot.x == 150 and dot.y == 600) ds.eat(20, 450) # pacman is able to eat the dot on (0, 450) for dot in ds.bottom_row: assert not (dot.x == 0 and dot.y == 450)
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) # firstly, if the exactly dot in the top row, the distance between # Pacman and dot is within eat distance(50).Then execute eat method, # check the same dot is not in the top row anymore for dot in ds.top_row: if dot.x == 300 and dot.y == 150: ds.eat(305, 150) assert dot not in ds.top_row # firstly, if the exactly dot in the bottom_row, the distance between # Pacman and dot is more than eat distance(50).Then execute eat method, # check the same dot is still in the bottom_row for dot in ds.bottom_row: if dot.x == 525 and dot.y == 450: ds.eat(625, 450) assert dot in ds.bottom_row # firstly, if the exactly dot in the left_col in the bottom, # the distance between Pacman and dot is more than 550. # Then execute eat method,check the same dot is not in the left_col anymore for dot in ds.left_col: if dot.x == 150 and dot.y == 600: ds.eat(150, 50) assert dot not in ds.left_col # firstly, if the exactly dot in the right_col in the middle, # the distance between Pacman and dot is more than 50. # Then execute eat method,check the same dot is not in the left_col for dot in ds.right_col: if dot.x == 450 and dot.y == 300: ds.eat(443, 300) assert dot not in ds.right_col
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) cur = 0 for i in range(0, ds.WIDTH // ds.SPACING + 1, ds.SPACING): ds.eat(i, ds.TH) assert len(ds.top_row) == ds.WIDTH // ds.SPACING cur += 1
def __init__(self, WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ, game_controller): self.LEFT_VERT = LEFT_VERT self.RIGHT_VERT = RIGHT_VERT self.TOP_HORIZ = TOP_HORIZ self.BOTTOM_HORIZ = BOTTOM_HORIZ self.WIDTH = WIDTH self.HEIGHT = HEIGHT self.gc = game_controller self.dots = Dots(WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ)
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) ds.eat(70, 150) for dots in ds.top_row: assert dots.x != 75 ds.eat(70, 450) for dots in ds.bottom_row: assert dots.x != 75 ds.eat(150, 70) for dots in ds.left_col: assert dots.y != 75 ds.eat(450, 70) for dots in ds.right_col: assert dots.y != 75
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) ds.eat(100, 150) assert len(ds.top_row) == 8 ds.eat(150, 200) assert len(ds.left_col) == 8 ds.eat(150, 150) assert len(ds.top_row) == 7 assert len(ds.left_col) == 8
def __init__(self, wallet, counter): threading.Thread.__init__(self) self.__flag = 1 # flags >> 1=compra&venda / 2=venda somente / 0=faça nada self.__minionID = None self.__wallet = None self.__reaper = None self.__amount = 0.0 self.__wallet = wallet self.__reaper = RobotMoneyReaper(self.__wallet.getName()) self.__dots = Dots(self.__wallet.getName()) self.__wallet.setStockVector(self.__dots) self.setMinionID(self.__wallet.getName()) self.threadID = self.__wallet.getName() + '_Minion' self.name = self.__wallet.getName() + '_Minion' self.counter = counter
def test_eat(): """ Test eat method """ ds = Dots(600, 600, 150, 450, 150, 450) for x_coordinate in range(150, 451, 150): for y_coordinate in range(600): ds.eat(x_coordinate, y_coordinate) for y_coordinate in range(150, 451, 150): for x_coordinate in range(600): ds.eat(x_coordinate, y_coordinate) assert ds.dots_left() == 0
def import5x7(self, char): """Reads Dot Font from File""" self.tableRow = ord( char ) - 32 #um in 5x7.font den richtigen Eintrag zu erwischen muss man 32 vom Hex wert abziehen self.segment = [[0 for r in range(7)] for c in range(5)] #erstelle das segment (2D Liste) for c in range(5): for r in range(7): self.segment[c][r] = Dots(c, r) self.charList = self.alphabet[self.tableRow].split( ', ') #Den gelesenen String splitten #print(self.charList) for c in range(5): self.currentColumnValue = self.charList[c][ 2:] #in Abhaengigkeit von c den Hex Wert (ohne 0x) als String lesen self.currentBitarray = '{0:08b}'.format( int(self.currentColumnValue, 16) ) #aus dem Hex String ein Bin String mit festem Format erzeugen #print(self.currentColumnValue) #print(self.currentBitarray) for r in range(7): self.segment[c][r].setState(int( self.currentBitarray[7 - r])) #states in segment setzen if self.showInConsole == True: print('- - - - - - - - - - - - - - - - - - - - - - - - - - - -') for r in range(7): for c in range(5): if self.segment[c][r].state == True: print('o', end='') else: print(' ', end='') print(' ', end='') print() print('- - - - - - - - - - - - - - - - - - - - - - - - - - - -')
def test_constructor(): ds = Dots(600, 600, 150, 450, 150, 450) assert ds.WIDTH == 600 assert ds.HEIGHT == 600 assert ds.TH == 150 assert ds.BH == 450 assert ds.LV == 150 assert ds.RV == 450 assert len(ds.bottom_row) == len(ds.top_row) == ds.WIDTH//ds.SPACING + 1 assert len(ds.left_col) == len(ds.right_col) == ds.HEIGHT//ds.SPACING + 1 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH
class Maze: """Draws the maze and handles interaction between Pacman and dots""" def __init__(self, WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ, game_controller): self.LEFT_VERT = LEFT_VERT self.RIGHT_VERT = RIGHT_VERT self.TOP_HORIZ = TOP_HORIZ self.BOTTOM_HORIZ = BOTTOM_HORIZ self.WIDTH = WIDTH self.HEIGHT = HEIGHT self.gc = game_controller self.dots = Dots(WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ) # TODO: # PROBLEM 3: implement dot eating # BEGIN CODE CHANGES def eat_dots(self, pacx, pacy, pac_width, pac_height): # You might want/need to pass arguments here. """Based on pacman's location, eat dots. Also cnosider corner case: when pacman moves off the edge of the view area, then pacman should eat one more dots on the opposite side""" self.dots.eat(pacx, pacy) if pacx > self.WIDTH - pac_width/2: self.dots.eat(0, pacy) if pacx < pac_width/2: self.dots.eat(self.WIDTH, pacy) if pacy > self.HEIGHT - pac_height/2: self.dots.eat(pacx, 0) if pacy < pac_height/2: self.dots.eat(pacx, self.HEIGHT) # END CODE CHANGES def update(self): """Make necessary per-frame updates""" # Check whether the dots are all eaten if self.dots.dots_left() == 0: self.gc.player_wins = True def display(self): """Display the maze""" self.update() # Display the dots self.dots.display() # Draw the maze walls stroke(0.0, 0.0, 10) strokeWeight(5) fill(0) rectMode(CORNER) clearance = 60 overdraw = 20 # Start drawing offscreen t = -(overdraw) l = -(overdraw) border = 20 big_rad = 30 small_rad = 17 # Upper left t = -(overdraw) l = -(overdraw) w = self.LEFT_VERT - clearance + overdraw h = self.TOP_HORIZ - clearance + overdraw rect(l, t, w, h, big_rad) rect(l, t, w - border, h - border, small_rad) # Upper middle t = -(overdraw) l = self.LEFT_VERT + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t, w - border*2, h - border, small_rad) # Upper right l = self.RIGHT_VERT + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t, w - border*2, h - border, small_rad) # Middle left t = self.TOP_HORIZ + clearance l = -(overdraw) w = self.LEFT_VERT - clearance + overdraw h = (self.BOTTOM_HORIZ - clearance) - (self.TOP_HORIZ + clearance) rect(l, t, w, h, big_rad) rect(l, t + border, w - border, h - border*2, small_rad) # Middle middle l = self.LEFT_VERT + clearance t = self.TOP_HORIZ + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border*2, h - border*2, small_rad) # Middle right l = self.RIGHT_VERT + clearance t = self.TOP_HORIZ + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border*2, h - border*2, small_rad) # Lower left w = self.LEFT_VERT - clearance + overdraw h = self.TOP_HORIZ - clearance + overdraw l = -(overdraw) t = self.BOTTOM_HORIZ + clearance rect(l, t, w, h, big_rad) rect(l, t + border, w - border, h - border, small_rad) # Lower middle l = self.LEFT_VERT + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border*2, h - border, small_rad) # Lower right l = self.RIGHT_VERT + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border*2, h - border, small_rad)
class EvilMinion(threading.Thread): """ Evil Minion is a thread that will seek and destroy the action house """ def __init__(self, wallet, counter): threading.Thread.__init__(self) self.__flag = 1 # flags >> 1=compra&venda / 2=venda somente / 0=faça nada self.__minionID = None self.__wallet = None self.__reaper = None self.__amount = 0.0 self.__wallet = wallet self.__reaper = RobotMoneyReaper(self.__wallet.getName()) self.__dots = Dots(self.__wallet.getName()) self.__wallet.setStockVector(self.__dots) self.setMinionID(self.__wallet.getName()) self.threadID = self.__wallet.getName() + '_Minion' self.name = self.__wallet.getName() + '_Minion' self.counter = counter def setMinionID(self, id): self.__minionID = 'Bananaa-' + id def getMinionID(self): return self.__minionID def getStockRealtime(self): print(self.__reaper.getStock(), 'current price =', self.__reaper.getStockRealtime()) def setFlag(self, num): if num in [0, 1, 2]: self.__flag = num return True else: return False def getFlag(self): return self.__flag def getItSellByForce(self): try: self.setFlag(2) self.__amount = self.__reaper.getStockRealtime() if self.__amount is not None: if self.__amount > 0: text = self.__wallet.getName( ) + ' ' + self.__wallet.sellStock(self.__amount) self.__dots.setNewDot(self.__amount) return text except Exception as e: print( ' ' * 4, "ϟϟϟϟ", e, '\n', self.__wallet.getName(), 'during the selling force, something got wrong [EvilMinion.run]!' ) return '....:.' def run(self): time.sleep(2) while True: #try: self.__amount = self.__reaper.getStockRealtime() if self.__amount is not None: if self.__amount > 0: localtime = time.asctime(time.localtime(time.time())) text = ' ' * 10 + ' ' + localtime + ' ' + '♦' * 6 + ' ' + self.__wallet.getName( ) + ' ᴕ previous R$ %.2f Vs current R$ %.2f' % ( self.__dots.getLastPrice(), self.__amount) if self.__amount < self.__dots.getLastPrice( ) and self.__wallet.getMoney() > 0.0: if self.getFlag() == 1: text += self.__wallet.buyStock(self.__amount) self.__dots.setNewDot(self.__amount) elif self.__amount > self.__dots.getLastPrice( ) and self.__wallet.getPapers() > 0.0: if self.getFlag() in [1, 2]: text += self.__wallet.sellStock(self.__amount) self.__dots.setNewDot(self.__amount) print(text) #except Exception as e: #print(' ' * 4, "ϟϟϟϟ", e, '\n', self.__wallet.getName(), 'something is wrong here [EvilMinion.run]!') time.sleep(60)
class Maze: """Draws the maze and handles interaction between Pacman and dots""" def __init__(self, WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ, game_controller): self.LEFT_VERT = LEFT_VERT self.RIGHT_VERT = RIGHT_VERT self.TOP_HORIZ = TOP_HORIZ self.BOTTOM_HORIZ = BOTTOM_HORIZ self.WIDTH = WIDTH self.HEIGHT = HEIGHT self.gc = game_controller self.dots = Dots(WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ) def eat_dots(self, x, y): """Calls the Dots class method eat and passes Pac-Man's x and y to it""" self.dots.eat(x, y) def update(self): """Make necessary per-frame updates""" # Check whether the dots are all eaten if self.dots.dots_left() == 0: self.gc.player_wins = True def display(self): """Display the maze""" self.update() # Display the dots self.dots.display() # Draw the maze walls stroke(0.0, 0.0, 10) strokeWeight(5) fill(0) rectMode(CORNER) clearance = 60 overdraw = 20 # Start drawing offscreen t = -(overdraw) l = -(overdraw) border = 20 big_rad = 30 small_rad = 17 # Upper left t = -(overdraw) l = -(overdraw) w = self.LEFT_VERT - clearance + overdraw h = self.TOP_HORIZ - clearance + overdraw rect(l, t, w, h, big_rad) rect(l, t, w - border, h - border, small_rad) # Upper middle t = -(overdraw) l = self.LEFT_VERT + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t, w - border * 2, h - border, small_rad) # Upper right l = self.RIGHT_VERT + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t, w - border * 2, h - border, small_rad) # Middle left t = self.TOP_HORIZ + clearance l = -(overdraw) w = self.LEFT_VERT - clearance + overdraw h = (self.BOTTOM_HORIZ - clearance) - (self.TOP_HORIZ + clearance) rect(l, t, w, h, big_rad) rect(l, t + border, w - border, h - border * 2, small_rad) # Middle middle l = self.LEFT_VERT + clearance t = self.TOP_HORIZ + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border * 2, small_rad) # Middle right l = self.RIGHT_VERT + clearance t = self.TOP_HORIZ + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border * 2, small_rad) # Lower left w = self.LEFT_VERT - clearance + overdraw h = self.TOP_HORIZ - clearance + overdraw l = -(overdraw) t = self.BOTTOM_HORIZ + clearance rect(l, t, w, h, big_rad) rect(l, t + border, w - border, h - border, small_rad) # Lower middle l = self.LEFT_VERT + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border, small_rad) # Lower right l = self.RIGHT_VERT + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border, small_rad)
def test_eat(): """Tests the number of dots that will remain after Pacman reaches certain x,y coordinates""" ds = Dots(600, 600, 150, 450, 150, 450) assert len(ds.total) == 36 ds.eat(0, ds.TH) assert len(ds.total) == 35 ds.eat(0, ds.BH) assert len(ds.total) == 34 ds.eat(ds.LV, 150) assert len(ds.total) == 32 ds.eat(ds.RV, 225) assert len(ds.total) == 31 ds.eat(ds.RV, 200) assert len(ds.total) == 31 ds.eat(ds.RV, 49) assert len(ds.total) == 30
from head import Head from shape import Shape from view import View from dots import Dots from handtracker import HandTracker #from controller import Controller from key_controller import KeyController from constants import Mode from os import kill import signal if __name__ == "__main__": head = Head() shape = Shape(height=0.4, width=0.4, x=0, y=0, z=-9) dots = Dots() view = View(head=head, shape=shape, dots=dots, mode=Mode.MPU_MODE) handtracker = HandTracker(dots) #controller = Controller(head, use_phidget=False, use_MPU=True) keycontroller = KeyController(head, shape) try: view.run() finally: handtracker.shutdown() kill(handtracker.proc.pid, signal.SIGINT) handtracker.proc.wait() print("FINISHED")
def test_eat(): """Test the eat method of Dots class""" # PAC-MAN at BOTTOM ROW TESTS: # Test eating a dot at the end of bottom row # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 600 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * SPACING_multiple assert ds.bottom_row[i].y == ds.BH SPACING_multiple += 1 # Test eating a dot at the end of bottom row # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 585 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * SPACING_multiple assert ds.bottom_row[i].y == ds.BH SPACING_multiple += 1 # Test eating a dot at the beginning of bottom row # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 0 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * SPACING_multiple assert ds.bottom_row[i].y == ds.BH SPACING_multiple += 1 # Test eating a dot at the beginning of bottom row # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 37 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * SPACING_multiple assert ds.bottom_row[i].y == ds.BH SPACING_multiple += 1 # Test eating a dot at the bottom left intersection # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the bottom left intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 161 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the bottom right intersection # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the bottom right intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 443 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the bottom row # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 375 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 # Test eating a dot at the bottom row # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 365 y = 450 for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 # PAC-MAN at TOP ROW TESTS: # Test eating a dot at the end of top row # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 600 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * SPACING_multiple assert ds.top_row[i].y == ds.TH SPACING_multiple += 1 # Test eating a dot at the end of top row # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 585 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * SPACING_multiple assert ds.top_row[i].y == ds.TH SPACING_multiple += 1 # Test eating a dot at the beginning of top row # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 0 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * SPACING_multiple assert ds.top_row[i].y == ds.TH SPACING_multiple += 1 # Test eating a dot at the beginning of top row # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 37 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * SPACING_multiple assert ds.top_row[i].y == ds.TH SPACING_multiple += 1 # Test eating a dot at the top left intersection # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the top left intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 161 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the top right intersection # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the top right intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 443 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the top row # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 375 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 # Test eating a dot at the top row # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 365 y = 150 for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 # PAC-MAN at LEFT COLUMN TESTS: # Test eating a dot at the end of left column # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 600 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the end of left column # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 585 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the beginning of left column # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 0 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the beginning of left column # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 37 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the top left intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 140 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 # Test eating a dot at the bottom left intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 428 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 # Test eating a dot at the left column # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 375 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the left column # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 150 y = 365 for i in range(len(ds.left_col)): assert ds.left_col[i].x == ds.LV assert ds.left_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.left_col[dot_i].x == ds.LV assert ds.left_col[dot_i].y == ds.SPACING * i dot_i += 1 # PAC-MAN at RIGHT COLUMN TESTS: # Test eating a dot at the end of right column # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 600 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the end of right column # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 585 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the beginning of right column # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 0 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the beginning of right column # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 37 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) SPACING_multiple = 1 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * SPACING_multiple SPACING_multiple += 1 # Test eating a dot at the top right intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 140 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i for i in range(len(ds.top_row)): assert ds.top_row[i].x == ds.SPACING * i assert ds.top_row[i].y == ds.TH ds.eat(x, y) dot_i = 0 for i in [0, 1, 3, 4, 5, 6, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.top_row[dot_i].x == ds.SPACING * i assert ds.top_row[dot_i].y == ds.TH dot_i += 1 # Test eating a dot at the bottom right intersection # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 428 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i for i in range(len(ds.bottom_row)): assert ds.bottom_row[i].x == ds.SPACING * i assert ds.bottom_row[i].y == ds.BH ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 dot_i = 0 for i in [0, 1, 2, 3, 4, 5, 7, 8]: assert ds.bottom_row[dot_i].x == ds.SPACING * i assert ds.bottom_row[dot_i].y == ds.BH dot_i += 1 # Test eating a dot at the right column # (exactly at dot location) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 375 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1 # Test eating a dot at the right column # (within Pac-Man eating range) ds = Dots(600, 600, 150, 450, 150, 450) x = 450 y = 365 for i in range(len(ds.right_col)): assert ds.right_col[i].x == ds.RV assert ds.right_col[i].y == ds.SPACING * i ds.eat(x, y) dot_i = 0 for i in [0, 1, 2, 3, 4, 6, 7, 8]: assert ds.right_col[dot_i].x == ds.RV assert ds.right_col[dot_i].y == ds.SPACING * i dot_i += 1
class Maze: """Draws the maze and handles interaction between Pacman and dots""" def __init__(self, WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ, game_controller): self.LEFT_VERT = LEFT_VERT self.RIGHT_VERT = RIGHT_VERT self.TOP_HORIZ = TOP_HORIZ self.BOTTOM_HORIZ = BOTTOM_HORIZ self.WIDTH = WIDTH self.HEIGHT = HEIGHT self.gc = game_controller self.dots = Dots(WIDTH, HEIGHT, LEFT_VERT, RIGHT_VERT, TOP_HORIZ, BOTTOM_HORIZ) # TODO: # PROBLEM 3: implement dot eating # BEGIN CODE CHANGES def eat_dots(self, x, y, direction): """Given two integers representing the x, y coordinates of Pacman and another integer representing its direction, storethe dots that will be eaten in a list. Integer Integer Integer -> None""" dots_to_eat = [] for dot in self.dots.top_row: if self.within_reach(x, y, dot, direction): dots_to_eat.append(dot) for dot in self.dots.bottom_row: if self.within_reach(x, y, dot, direction): dots_to_eat.append(dot) for dot in self.dots.left_col: if self.within_reach(x, y, dot, direction): dots_to_eat.append(dot) for dot in self.dots.right_col: if self.within_reach(x, y, dot, direction): dots_to_eat.append(dot) if dots_to_eat: self.dots.eat(dots_to_eat) def within_reach(self, x, y, dot_object, direction): """Given two integer representing the x and y coordinates, and a dot object, and an integer, return a Boolean value. Integer Integer Dot Integer -> Boolean""" if dot_object.x == x: dis = dot_object.y - y if abs(dis) <= self.dots.EAT_DIST and dis * direction >= 0 \ or abs(dis) + self.dots.EAT_DIST >= \ self.HEIGHT + self.dots.radian and dis * direction < 0: return True elif dot_object.y == y: dis = dot_object.x - x if abs(dis) <= self.dots.EAT_DIST and dis * direction >= 0 \ or abs(dis) + self.dots.EAT_DIST >= \ self.WIDTH + self.dots.radian and dis * direction < 0: return True else: return False # END CODE CHANGES def update(self): """Make necessary per-frame updates""" # Check whether the dots are all eaten if self.dots.dots_left() == 0: self.gc.player_wins = True def display(self): """Display the maze""" self.update() # Display the dots self.dots.display() # Draw the maze walls stroke(0.0, 0.0, 10) strokeWeight(5) fill(0) rectMode(CORNER) clearance = 60 overdraw = 20 # Start drawing offscreen t = -(overdraw) l = -(overdraw) border = 20 big_rad = 30 small_rad = 17 # Upper left t = -(overdraw) l = -(overdraw) w = self.LEFT_VERT - clearance + overdraw h = self.TOP_HORIZ - clearance + overdraw rect(l, t, w, h, big_rad) rect(l, t, w - border, h - border, small_rad) # Upper middle t = -(overdraw) l = self.LEFT_VERT + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t, w - border * 2, h - border, small_rad) # Upper right l = self.RIGHT_VERT + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t, w - border * 2, h - border, small_rad) # Middle left t = self.TOP_HORIZ + clearance l = -(overdraw) w = self.LEFT_VERT - clearance + overdraw h = (self.BOTTOM_HORIZ - clearance) - (self.TOP_HORIZ + clearance) rect(l, t, w, h, big_rad) rect(l, t + border, w - border, h - border * 2, small_rad) # Middle middle l = self.LEFT_VERT + clearance t = self.TOP_HORIZ + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border * 2, small_rad) # Middle right l = self.RIGHT_VERT + clearance t = self.TOP_HORIZ + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border * 2, small_rad) # Lower left w = self.LEFT_VERT - clearance + overdraw h = self.TOP_HORIZ - clearance + overdraw l = -(overdraw) t = self.BOTTOM_HORIZ + clearance rect(l, t, w, h, big_rad) rect(l, t + border, w - border, h - border, small_rad) # Lower middle l = self.LEFT_VERT + clearance w = (self.RIGHT_VERT - clearance) - (self.LEFT_VERT + clearance) rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border, small_rad) # Lower right l = self.RIGHT_VERT + clearance w = self.RIGHT_VERT - clearance + overdraw rect(l, t, w, h, big_rad) rect(l + border, t + border, w - border * 2, h - border, small_rad)
def test_dots_left(): ds = Dots(600, 600, 150, 450, 150, 450) dl = ds.dots_left() assert dl == ((ds.WIDTH//ds.SPACING + 1) * 2 + (ds.HEIGHT//ds.SPACING + 1) * 2)
def test_eat(): ds = Dots(600, 600, 150, 450, 150, 450) for x in range(600): ds.eat(x, 450) assert len(ds.bottom_row) == 0