Exemplo n.º 1
0
    def test_place_raises_exception_when_child_position_occupied(self):
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')
        yellow = Noodle.get(Noodle.designation == 'B')

        board.place(light_blue, position=5)

        with self.assertRaises(PositionUnavailableException):
            board.place(yellow, position=11)
Exemplo n.º 2
0
    def test_undo_place_updates_last_played(self):
        """Test that the undo function will update the last_played date on the Game instance."""
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')
        board.puzzle.place(light_blue, position=5)
        yellow = Noodle.get(Noodle.designation == 'B')
        board.place(yellow, position=20)
        last_played = board.player.game.last_played

        board.undo()

        self.assertNotEqual(board.player.game.last_played, last_played)
Exemplo n.º 3
0
    def test_undo_place(self):
        """Test that the previous place noodle action can be undone."""
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')
        board.puzzle.place(light_blue, position=5)
        yellow = Noodle.get(Noodle.designation == 'B')

        board.place(yellow, position=20)

        BoardNoodle.get(
            BoardNoodle.position == 20)  # Should not raise a DoesNotExist

        noodle = board.undo()

        self.assertEqual(noodle, yellow)
        with self.assertRaises(BoardNoodle.DoesNotExist):
            BoardNoodle.get(
                BoardNoodle.position ==
                20)  # Noodle has been removed so will raise DoesNotExist
Exemplo n.º 4
0
    def test_place_noodle(self):
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')

        board.place(light_blue, position=5)

        board_noodle = BoardNoodle.get(BoardNoodle.position == 5)
        self.assertEqual(board_noodle.part1, light_blue.part1)
        self.assertEqual(board_noodle.part2, light_blue.part2)
        self.assertEqual(board_noodle.part3, light_blue.part3)
        self.assertEqual(board_noodle.part4, light_blue.part4)
Exemplo n.º 5
0
    def __init__(self, board, oncancel, master=None, **kwargs):
        """Initialise a new InfoFrame frame.

        Args:
            board: The Board instance.
            oncancel: Callback called when the Exit button is pressed.
            master: The parent widget.
            **kwargs: Optional keyword arguments to configure this screen.
        """
        frame_args = {
            'width': 800,
            'height': 60,
            'bg': '#000000',
        }
        kwargs.update(frame_args)
        super().__init__(master, highlightthickness=1, **kwargs)

        canvas = tk.Canvas(self, highlightthickness=0, **kwargs)
        canvas.pack()

        canvas.create_text(120,
                           26,
                           text='PLAYER: {}'.format(board.player.name),
                           font=settings.fonts['gamescreen_player'],
                           fill=Noodle.get(Noodle.designation == 'B').colour)
        canvas.create_text(300,
                           26,
                           text='LEVEL: {}'.format(board.puzzle.level.number),
                           font=settings.fonts['gamescreen_status'],
                           fill=Noodle.get(Noodle.designation == 'F').colour)
        canvas.create_text(380,
                           26,
                           text='PUZZLE: {}'.format(board.puzzle.number),
                           font=settings.fonts['gamescreen_status'],
                           fill=Noodle.get(Noodle.designation == 'F').colour)
        CanvasButton(canvas,
                     'EXIT',
                     pos=(715, 26),
                     width=140,
                     height=40,
                     onpress=lambda _: oncancel())
Exemplo n.º 6
0
    def test_get_puzzles_completed(self):
        game = Game.create()
        player = Player.create(game=game, name='Test')
        level = Level.create(number=1, name='Level 1')
        Noodle.create(designation='A',
                      colour='yellow',
                      part1='NE',
                      part2='SE',
                      part3='E',
                      part4='W')

        # Configure 2 complete boards
        for n in range(2):
            puzzle = Puzzle.create(level=level, number=n)
            board = Board.create(player=player, puzzle=puzzle)
            for p in range(7):
                BoardNoodle.create(board=board,
                                   noodle=Noodle.get(designation='A'),
                                   position=p,
                                   part1='NE',
                                   part2='SE',
                                   part3='E',
                                   part4='W')

        # Configure 1 incomplete board
        puzzle = Puzzle.create(level=level, number=2)
        board = Board.create(player=player, puzzle=puzzle)
        for p in range(6):
            BoardNoodle.create(board=board,
                               noodle=Noodle.get(designation='A'),
                               position=p,
                               part1='NE',
                               part2='SE',
                               part3='E',
                               part4='W')

        completed = player.puzzles_completed

        self.assertEqual(completed.player_completed, 2)
        self.assertEqual(len(player.boards), 3)
Exemplo n.º 7
0
    def test_undo_no_place_does_nothing(self):
        """Test that attempting to undo when no place has occurred does nothing."""
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')

        board.puzzle.place(light_blue, position=5)

        noodle = board.undo(
        )  # Nothing to undo, because undo does not remove puzzle noddles (only board noodles)

        self.assertIsNone(noodle)
        PuzzleNoodle.get(
            PuzzleNoodle.position == 5)  # Should not raise a DoesNotExist
Exemplo n.º 8
0
    def test_setup(self):
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')
        light_blue.rotate(increment=3)
        board.puzzle.place(light_blue, position=3)
        board.setup()

        self.assertEqual(len(board.noodles), 1)
        self.assertEqual(board.noodles[0].id, 1)
        self.assertEqual(board.noodles[0].part1, orientation.W)
        self.assertEqual(board.noodles[0].part2, orientation.W)
        self.assertEqual(board.noodles[0].part3, orientation.SW)
        self.assertEqual(board.noodles[0].part4, orientation.NW)
Exemplo n.º 9
0
    def test_place_noodle_specific_part(self):
        """Test place a noodle onto the board supplying the specific noodle
        part that should be placed.
        """
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')

        pos = board.place(light_blue, position=3, part_pos=3)

        self.assertEqual(pos, 5)
        board_noodle = BoardNoodle.get(BoardNoodle.position == 5)
        self.assertEqual(board_noodle.part1, light_blue.part1)
        self.assertEqual(board_noodle.part2, light_blue.part2)
        self.assertEqual(board_noodle.part3, light_blue.part3)
        self.assertEqual(board_noodle.part4, light_blue.part4)
Exemplo n.º 10
0
    def __init__(self, onnewplayer, onexistingplayer, onhighscores, master=None, **kwargs):
        """Initialise a HomeScreen frame.

        Args:
            onnewplayer: No-args callback called when the new player button is pressed.
            onexistingplayer: No-args callback called when the existing player button is pressed.
            master: The parent widget.
            **kwargs: Optional keyword arguments to configure this screen.
        """
        args = {
            'width': 800,
            'height': 480,
            'bg': '#000000'
        }
        kwargs.update(args)

        super().__init__(master, highlightthickness=2, **kwargs)

        canvas = tk.Canvas(self, highlightthickness=0, **args)
        canvas.pack()

        canvas.create_text(400, 100, text='Kanoodle', font=fonts['homescreen_kanoodle'],
                           justify='center', fill='#FFFFFF')

        colour_map = OrderedDict()
        colour_map['G'] = Noodle.get(Noodle.designation == 'A').colour
        colour_map['E'] = Noodle.get(Noodle.designation == 'E').colour
        colour_map['N'] = Noodle.get(Noodle.designation == 'C').colour
        colour_map['I'] = Noodle.get(Noodle.designation == 'B').colour
        colour_map['U'] = Noodle.get(Noodle.designation == 'D').colour
        colour_map['S'] = Noodle.get(Noodle.designation == 'F').colour

        x, x_offset = 250, 60
        for char in colour_map:
            canvas.create_text(x, 180, text=char, font=fonts['homescreen_genius'],
                               justify='center', fill=colour_map[char])
            x += x_offset

        canvas.create_text(615, 140, text='2D', font=fonts['homescreen_2d'],
                           justify='center', fill='#FFFFFF')

        args = {
            'width': 170,
        }

        CanvasButton(canvas, 'NEW PLAYER', (305, 280), onpress=lambda _: onnewplayer(), **args)
        CanvasButton(canvas, 'EXISTING PLAYER', (495, 280), onpress=lambda _: onexistingplayer(),
                     disabled=len(Player.active_players()) == 0, **args)
        CanvasButton(canvas, 'HIGH SCORES', (400, 350), onpress=lambda _: onhighscores(),
                     disabled=len(Player.active_players()) == 0, **args)
Exemplo n.º 11
0
    def test_place_raises_exception_when_root_position_off_board(self):
        board = self._create_board()
        light_blue = Noodle.get(Noodle.designation == 'D')

        with self.assertRaises(PositionUnavailableException):
            board.place(light_blue, position=37)