def test_happy_path(self):
        """Successfully creates various happy path Sigils."""
        test1 = Sigil("R")
        test2 = Sigil("$", priority=4)
        test3 = Sigil("φ", priority=2, color=(200, 225, 200))

        for t in (test1, test2, test3):
            assert isinstance(t, Sigil)
Example #2
0
    def test_create_unhappy_paths(self):
        # Most things that go wrong here are type mismatches (which are
        # handled by explicit typing) and invalid values of size
        with self.assertRaises(Exception):
            test1 = Entity(size=34, sigil=Sigil("x"))  # Size > 10

        with self.assertRaises(Exception):
            test2 = Entity(size=-2, sigil=Sigil("z"))  # Size < 0
Example #3
0
    def test_sigil(self):
        ent = _get_demo_entity()
        assert isinstance(ent.sigil, Sigil)

        ent.sigil = Sigil("z")  # Happy path change
        assert ent.sigil.character == "z"

        with self.assertRaises(Exception):
            ent.sigil = Sigil("zz")  # Invalid sigil
Example #4
0
    def __init__(self,
                 open_char: str = ".",
                 closed_char: str = "+",
                 color: Tuple[int, int, int] = (240, 240, 240),
                 start_open: bool = False):
        self._open_sigil = Sigil(open_char, 3, color)
        self._closed_sigil = Sigil(closed_char, 3, color)
        self._is_open = False

        # Call the super's constructor
        super().__init__(name="Door", color=color)

        # Replace the default sigil with the appropriate sigil for this door's initial state
        self._sigil = self._open_sigil if start_open else self._closed_sigil
    def test_sad_paths(self):
        """Fails to create various unhappy path sigils."""
        with self.assertRaises(ValueError):
            # The hiragana 'ku' isn't in CP437
            test1 = Sigil("く")

        with self.assertRaises(ValueError):
            test2 = Sigil("F", priority=-32)

        with self.assertRaises(ValueError):
            test3 = Sigil("F2f")

        with self.assertRaises(ValueError):
            test4 = Sigil("C", color=(42, -85, 94))
Example #6
0
    def test_playfield(self):
        ent = Entity(size=5, sigil=Sigil("4"))
        pf = PlayField(4, 4)
        ent.introduce_at(2, 2, pf)

        assert isinstance(ent.playfield, PlayField)
        assert ent in pf.entities
Example #7
0
    def test_passable(self):
        """Test getter and setter for passable"""
        ent = Entity(size=6, sigil=Sigil("r"))
        assert ent.passable  # Entities are passable by default
        ent.passable = False
        assert not ent.passable

        ent2 = Entity(size=3, sigil=Sigil("q"))
        pf = PlayField(3, 3)

        # Test that movement is blocked when destination contains an impassable entity
        ent.introduce_at(1, 2, pf)
        ent2.introduce_at(2, 2, pf)

        ent2.move_to(1, 2)
        assert ent2.position == (2, 2)
 def _default_wall_generator():
     """A stand-in for something specifiable at instantiation. Returns a bland little wall."""
     return lambda: Static(size=9,
                           sigil=Sigil("#",
                                       priority=3),
                           name="Wall",
                           passable=False)
    def test_drawables(self):
        ent1 = Static(4, Sigil("X", priority=4))
        ent2 = Entity(3, Sigil("y"))
        ent3 = Entity(3, Sigil("z"))
        pf = PlayField(3, 3)

        ent1.introduce_at(1, 1, pf)
        ent2.introduce_at(1, 1, pf)
        ent3.introduce_at(2, 0, pf)

        # Extract the characters from the resulting dicts for comparison
        chars = [row["character"] for row in pf.drawables()]

        # The high priority X should render, and not the lower priority y
        assert "X" in chars
        assert "y" not in chars
    def test_sigils(self):
        # Test that .sigils returns the highest priority sigils in a cell
        pf = PlayField(4, 4)
        ent = Entity(4, Sigil("A"))
        ent2 = Entity(4, Sigil("B"))
        ent3 = Entity(4, Sigil("C", priority=2))

        # Introduce three passable entities, one with a lower priority
        ent.introduce_at(2, 2, pf)
        ent2.introduce_at(2, 2, pf)
        ent3.introduce_at(2, 2, pf)
        sigs: List[Sigil] = pf.get_cell(2, 2).sigils

        # Assert that the two highest, but not the one lowest, are returned by .sigil
        assert ent.sigil in sigs
        assert ent2.sigil in sigs
        assert ent3.sigil not in sigs
Example #11
0
    def test_cell(self):
        """Test getter and setter for parent cell"""
        ent = Entity(size=5, sigil=Sigil("4"))
        pf = PlayField(4, 4)
        ent.introduce_at(2, 3, pf)

        assert isinstance(ent.cell, Cell)
        assert ent in ent._parent_cell.contents
        def generate_content(
                walls: np.ndarray,
                field: np.ndarray) -> List[Tuple[int, int, Entity]]:
            ents = [
                Mobile(size=4,
                       sigil=Sigil("m", color=(190, 190, 240)),
                       name="Memeish boi"),
                Mobile(size=4,
                       sigil=Sigil("m", color=(220, 200, 255)),
                       name="Memey McMemeFace")
            ]
            positions = [(pos[1], pos[0])
                         for pos, truth in np.ndenumerate(field) if truth]

            ents_and_positions = [(ent, rand.choice(positions))
                                  for ent in ents]
            return [(pos[0], pos[1], ent) for ent, pos in ents_and_positions]
    def test_entities(self):
        """Tests .entities, which returns a list of all entities in the field."""
        e1 = Mobile(4, Sigil("A"))
        e2 = Entity(4, Sigil("B"))
        e3 = Static(4, Sigil("C"))
        pf = PlayField(10, 10)

        e1.introduce_at(1, 2, pf)
        e2.introduce_at(5, 3, pf)
        e3.introduce_at(9, 5, pf)

        assert e1 in pf.entities
        assert e2 in pf.entities
        assert e3 in pf.entities

        with self.assertRaises(Exception):
            # Rejects assignment.
            pf.entities = [e2]
Example #14
0
 def __init__(self,
              character: str = "#",
              name: str = "",
              color=(100, 100, 100)):
     """By default, instantiates as a passable, bland-gray, priority 2, size 1 hash mark."""
     super().__init__(size=1,
                      sigil=Sigil(character, priority=2, color=color),
                      name=name,
                      passable=True)
    def test_statics(self):
        """Create three entities, of which only one is a static should appear alone in .statics."""
        ent1 = Static(2, Sigil("A"))
        ent2 = Mobile(3, Sigil("B"))
        ent3 = Entity(4, Sigil("C"))
        pf = PlayField(3, 3)

        ent1.introduce_at(0, 2, pf)
        ent2.introduce_at(2, 1, pf)
        ent3.introduce_at(1, 1, pf)

        assert ent1 in pf.statics
        assert ent2 not in pf.statics
        assert ent3 not in pf.statics

        with self.assertRaises(Exception):
            # Reject assignment
            pf.statics = [ent1]
    def __init__(self):
        super().__init__()
        self.name = "Memory Bounds"
        self.sigil = Sigil("█", color=(225, 225, 225))


# foo = ToyBoi()
#
# while foo.cooldown > 0:
#     foo.tick()
#     print(foo.cooldown)
    def test_passable(self):
        """Should be passable if no entity in the cell has .passable=False"""
        ent1 = Entity(4, Sigil("A"))
        ent2 = Entity(3, Sigil("B"))
        ent3 = Entity(3, Sigil("C"))

        pf = PlayField(3, 3)
        ent1.introduce_at(2, 2, pf)
        ent2.introduce_at(2, 2, pf)
        ent3.introduce_at(2, 2, pf)

        c: Cell = pf.get_cell(2, 2)
        assert c.passable

        # Making any of the contents impassible should make the cell impassable
        ent2.passable = False
        assert not c.passable

        c.remove_entity(ent2)
        assert c.passable
    def test_tick(self):
        """Ticking the playfield should tick entities within it."""
        mob = Mobile(size=4, sigil=Sigil("X"), base_move_cost=50)
        pf = PlayField(3, 3)
        mob.introduce_at(2, 2, pf)

        a = mob.cooldown
        pf.tick()
        b = mob.cooldown

        assert a > b
        assert a == b + 1
    def test_priority(self):
        """Tests getter & setter for Sigil.priority"""
        test = Sigil("R")
        test2 = Sigil("S", priority=2)
        assert test.priority > test2.priority

        test2.priority = 4
        assert test2.priority > test.priority

        with self.assertRaises(Exception):
            test.priority = 6

        with self.assertRaises(Exception):
            test.priority = -3

        with self.assertRaises(Exception):
            test.priority = "Foo"
Example #20
0
        def rows_to_drawables(
                x_0: int, y_0: int,
                opt_rows: RenderableArray) -> List[Tuple[int, int, Sigil]]:
            """

            :param x_0: The x component of the top-left corner of this set of things to be drawn
            :param y_0: The y component of the top-left corner of this set of things to be drawn
            :param opt_rows: A batch of rows (usually given by a MenuObject) to be drawn
            :return: A list of (x, y, Sigil) tuples, where x and y are true console positions.
            """
            drawables_ = []
            for dy in range(
                    0, len(opt_rows)
            ):  # dy is both change from y0 and our row iterator
                for dx in range(
                        0, len(opt_rows[dy])
                ):  # same for dx, x0, and our our column iterator
                    char = opt_rows[dy][dx][0]
                    color = opt_rows[dy][dx][1]
                    drawables_.append(
                        (x_0 + dx, y_0 + dy, Sigil(char, color=color)))
            return drawables_
Example #21
0
    def launch_the_game(event):
        interface.new_playfield(width=200,
                                height=80)

        floors = []
        for y in range(0, 40):
            floors.append([(x, y, WalkableTerrain())
                           for x in range(0, 60)])

        for f in sum(floors, []):
            x, y, ent = f
            ent.introduce_at(x, y, interface.playfield)

        walls = [(x, 20, Wall()) for x in range(0, 11)]
        for w in walls:
            x, y, ent = w
            ent.introduce_at(x, y, interface.playfield)

        player_char = Mobile(size=4,
                             sigil=Sigil("@", priority=3),
                             name="Player Character")
        player_char.introduce_at(10, 10, interface.playfield)
        interface.playfield.player_character = player_char

        interface.playfield.origin = (2, 2)
        interface.add_animation(7, 7, Animation(frames=[AnimationFrame(Sigil("\\"), 5),
                                                        AnimationFrame(Sigil("|"), 5),
                                                        AnimationFrame(Sigil("/"), 5),
                                                        AnimationFrame(Sigil("-"), 5)],
                                                repeating=True))
        blue_floor = WalkableTerrain(color=(50, 50, 255))
        blue_floor.sigil = Sigil("!", priority=blue_floor.sigil.priority)
        blue_floor.introduce_at(12, 12, interface.playfield)

        # print(interface.playfield.get_cell(12, 12).sigils)
        interface.new_game_log(height=10, width=40)
        interface.print_to_log("This is a log tests!", color=(25, 250, 25))
        interface.print_to_log("This is an exceptionally long log tests so we can see how well it handles multiples of these.")
        interface.print_to_log("This is another line.")
        interface.print_to_log("This is yet another line.")
        interface.print_to_log("This should bump the first line off of the screen.")
        menu.close_menu()
    def test_color(self):
        test = Sigil("A", priority=3, color=(199, 198, 197))

        assert test.r == 199
        assert test.g == 198
        assert test.b == 197

        assert test.color == (199, 198, 197)

        test.color = (101, 102, 103)

        assert test.r == 101
        assert test.g == 102
        assert test.b == 103

        test.b = 202
        assert test.color[2] == 202

        with self.assertRaises(ValueError):
            test.g = 442

        with self.assertRaises(ValueError):
            test.g = -30
Example #23
0
 def __init__(self, char: str = "█", name: str = "", color=(200, 200, 200)):
     super().__init__(size=9,
                      sigil=Sigil(char, priority=4),
                      name=name,
                      passable=False)
 def __init__(self):
     super().__init__(name="Wall",
                      size=5,
                      sigil=Sigil("█", color=(230, 230, 230)),
                      passable=False)
Example #25
0
 def __init__(self):
     super().__init__(4, Sigil("@"), "testyboi")
     self.modifiers = {}
     self.testymcstatface = 54
Example #26
0
 def test_create_happy_paths(self):
     test1 = Entity(size=3, sigil=Sigil("q"))
     test2 = Entity(size=9, sigil=Sigil("a"), name="Floofie")
Example #27
0
def _get_demo_entity():
    return Entity(size=5, sigil=Sigil("Q"), name="Demoboi")
def make_wall():
    return Static(size=9,
                  sigil=Sigil("#", priority=3, color=(220, 220, 255)),
                  name="Boundary",
                  passable=False)