class TestThingCollider(TestCase): def setUp(self): self.fakegrid = Grid((3,3), []) self.collider = ThingCollider() def test_same_place_will_result_in_collision(self): coord = (2,2) self.fakegrid.place_new(coord, 1) collision = self.collider.will_result_in_collision(self.fakegrid, coord) self.assertTrue(collision) def test_different_place_will_not_result_in_collision(self): grid = Grid((3,3), []) grid.place_new((2,2), 1) collision = self.collider.will_result_in_collision(self.fakegrid, (1, 2)) self.assertFalse(collision) def test_off_board_is_not_collision(self): self.fakegrid.place_new((2,2), 1) collision = self.collider.will_result_in_collision(self.fakegrid, (5,5)) self.assertFalse(collision)
def test_different_place_will_not_result_in_collision(self): grid = Grid((3,3), []) grid.place_new((2,2), 1) collision = self.collider.will_result_in_collision(self.fakegrid, (1, 2)) self.assertFalse(collision)
#Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() currentx = 0 currenty = 0 # draw the background screen.fill(GRAY) rect = [grid_offset_x, grid_offset_y, gamewidth, gameheight] pygame.draw.rect(screen, WHITE, rect, 0) grid.place_new((0,0), 1) grid.place_new((11,11), 2) def draw_block(id, coords): start_x = grid_offset_x + coords[0] * blocksize start_y = grid_offset_y + coords[1] * blocksize pygame.draw.rect(screen, player_colour[id], [start_x, start_y, blocksize, blocksize], 0) def move_to_new_coord(id, new_coord): draw_block(id, new_coord) # end background # -------- Main Program Loop ----------- draw_block(1, (0,0))