def test_game_run_heroku(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.player_c = 1 game.computer_c = 1 game.objects[(game.kx * 5, game.ky * 4)] = Player_checkers(game.kx * 5, game.ky * 4, game.kx, (0, 0, 0)) game.objects[(game.kx * 8, game.ky)] = Computer_checkers(game.kx * 8, game.ky, game.kx, (255, 0, 0)) game.handle_mouse_down((game.kx * 5, game.ky * 4)) game.handle_events = MagicMock( return_value=game.handle_mouse_down((game.kx * 5, game.ky * 2))) conf = dict() conf['0'] = str(775 - game.kx * 8) + '-' + str( 800 - game.ky) + '-' + str( 775 - game.kx * 2) + '-' + str(800 - game.ky * 3) + '-0' game.get_config = MagicMock(return_value=conf) game.run_heroku() self.assertTrue(True)
def test_game_computer_turn_cant_move(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.objects[(game.kx * 2, game.ky)] = Computer_checkers(game.kx * 2, game.ky, game.kx, (255, 0, 0)) game.objects[(game.kx * 2, game.ky * 3)] = Player_checkers(game.kx * 2, game.ky * 3, game.kx, (0, 0, 0)) game.objects[(game.kx * 2, game.ky * 5)] = Player_checkers(game.kx * 2, game.ky * 5, game.kx, (0, 0, 0)) game.objects[(game.kx * 5, game.ky * 2)] = Player_checkers(game.kx * 5, game.ky * 2, game.kx, (0, 0, 0)) game.objects[(game.kx * 8, game.ky * 3)] = Player_checkers(game.kx * 8, game.ky * 3, game.kx, (0, 0, 0)) game.computer_turn() self.assertTrue(game.objects[(game.kx * 2, game.ky)] is not None)
def __init__(self, caption, width, height, back_image_filename, frame_rate, checkers_count_line): self.background_image = pygame.image.load(back_image_filename) self.frame_rate = frame_rate self.game_over = False pygame.mixer.pre_init(44100, 16, 2, 4096) pygame.init() pygame.font.init() self.surface = pygame.display.set_mode((width, height)) self.bounds = Rect(0, 0, width, height) self.state = "" pygame.display.set_caption(caption) self.clock = pygame.time.Clock() self.keydown_handlers = defaultdict(list) self.keyup_handlers = defaultdict(list) self.mouse_handlers = [] self.mouse_handlers.append(self.handle_mouse_event) self.ky = int(height / 20) self.kx = int(width / 31) self.objects = dict() self.player_c = 0 self.computer_c = 0 if self.kx < self.ky: rad = self.kx else: rad = self.ky y = self.ky for i in range(0, 6): if i % 2 != 0: x = self.kx * 2 else: x = self.kx * 5 for j in range(0, 5): self.objects[(x, y)] = Computer_checkers(x, y, rad, (255, 0, 0)) x += self.kx * 6 self.computer_c += 1 y += self.ky y = height - self.ky for i in range(0, 6): if i % 2 != 0: x = self.kx * 2 else: x = self.kx * 5 for j in range(0, 5): self.objects[(x, y)] = Player_checkers(x, y, rad, (0, 0, 0)) x += self.kx * 6 self.player_c += 1 y -= self.ky self.from_c = tuple() self.to_c = tuple() self.active_checker = None self.enemy_dict = dict() self.turn = "Player"
def test_game_computer_turn_move_checker_become_king(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.objects[(game.kx * 5, game.ky * 18)] = Computer_checkers( game.kx * 5, game.ky * 18, game.kx, (255, 0, 0)) game.computer_turn() game.computer_turn() game.computer_turn() self.assertTrue(True)
def test_game_computer_turn_move_and_eat_checker_up_right(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.objects[(game.kx * 2, game.ky * 5)] = Computer_checkers( game.kx * 2, game.ky * 5, game.kx, (255, 0, 0)) game.objects[(game.kx * 5, game.ky * 4)] = Player_checkers(game.kx * 5, game.ky * 4, game.kx, (0, 0, 0)) game.computer_turn() self.assertTrue(game.objects[(game.kx * 5, game.ky * 4)] is None)
def test_game_computer_turn_move_and_eat_checker_down_left_king(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.objects[(game.kx * 8, game.ky * 3)] = Computer_checkers( game.kx * 8, game.ky * 3, game.kx, (255, 0, 0)) game.objects[(game.kx * 8, game.ky * 3)].checkers_type = "king" game.objects[(game.kx * 5, game.ky * 4)] = Player_checkers(game.kx * 5, game.ky * 4, game.kx, (0, 0, 0)) game.computer_turn() self.assertTrue(game.objects[(game.kx * 5, game.ky * 4)] is None)
def test_game_run_computer(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.player_c = 1 game.computer_c = 1 game.objects[(game.kx * 5, game.ky * 2)] = Computer_checkers( game.kx * 5, game.ky * 2, game.kx, (255, 0, 0)) game.objects[(game.kx * 5, game.ky * 4)] = Player_checkers(game.kx * 5, game.ky * 4, game.kx, (0, 0, 0)) game.turn = "Computer" game.run_computer() self.assertTrue(True)
def test_game_handle_mouse_down_move_and_eat_checker_up_right(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.objects[(game.kx * 2, game.ky * 5)] = Player_checkers(game.kx * 2, game.ky * 5, game.kx, (0, 0, 0)) game.objects[(game.kx * 5, game.ky * 4)] = Computer_checkers( game.kx * 5, game.ky * 4, game.kx, (255, 0, 0)) game.handle_mouse_down((game.kx * 2, game.ky * 5)) game.handle_mouse_down((game.kx * 5, game.ky * 4)) self.assertEqual(game.active_checker, None) game.handle_mouse_down((game.kx * 8, game.ky * 3)) self.assertEqual(game.active_checker, game.objects.get((game.kx * 8, game.ky * 3)))
def test_game_computer_turn_move_checker(self): x_size = 775 y_size = 800 game = Game("Checkers 100", x_size, y_size, "1.png", 120) game.objects = dict() game.objects[(game.kx * 5, game.ky * 2)] = Computer_checkers( game.kx * 5, game.ky * 2, game.kx, (255, 0, 0)) game.objects[(game.kx * 5, game.ky * 6)] = Player_checkers(game.kx * 5, game.ky * 6, game.kx, (0, 0, 0)) game.objects[(game.kx * 5, game.ky * 8)] = Player_checkers(game.kx * 5, game.ky * 8, game.kx, (0, 0, 0)) game.computer_turn() game.computer_turn() self.assertEqual(None, game.objects.get((game.kx * 5, game.ky * 4)))
def test_Computer_checkers_draw(self): checker = Computer_checkers(0, 0, 10, (0, 0, 0)) checker.draw(pygame.display.set_mode((775, 800))) self.assertTrue(True)
def test_Computer_checkers_init(self): checker = Computer_checkers(0, 0, 10, (0, 0, 0)) self.assertTrue(True)