コード例 #1
0
 def test_horizontal_padding(self):
     """Tests that .horizontal_padding has working a working getter and rejects assignment."""
     opt = MenuOption("Howdy!",
                      width=12,
                      height=5,
                      on_select=lambda x: print("Howdy!"),
                      subtext="It says howdy",
                      pad_horizontal=1,
                      pad_vertical=1,
                      color=(200, 255, 200))
     assert opt.horizontal_padding == 1
     with self.assertRaises(Exception):
         opt.horizontal_padding = 4
コード例 #2
0
    def test_color(self):
        """Tests that color has a working setter and getter."""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1,
                         color=(200, 255, 200))
        assert opt.color == (200, 255, 200)

        opt.color = (155, 175, 155)
        assert opt.color == (155, 175, 155)

        with self.assertRaises(Exception):
            opt.color = (155, 22)  # Invalid tuple length

        with self.assertRaises(Exception):
            opt.color = (-32, 5, 122)  # One param below zero

        with self.assertRaises(Exception):
            opt.color = "Potatoes"  # Invalid argument type

        with self.assertRaises(Exception):
            opt.color = (1, "Onions", 35)  # One invalid param type

        with self.assertRaises(Exception):
            opt.color = None  # Assignment to None
コード例 #3
0
    def test_size(self):
        """Checks that .size has a working getter and refuses assignment."""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1)

        assert opt.size == (12, 5)

        with self.assertRaises(Exception):
            opt.size = (1, 2)
コード例 #4
0
    def test_subtext(self):
        """Checks that .subtext has a working setter and getter."""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1)

        assert opt.subtext == "It says howdy"

        opt.subtext = "It sure says something."
        assert opt.subtext == "It sure says something."
コード例 #5
0
    def test_text(self):
        """Checks that .text has a working setter and getter"""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1)

        # Test getter
        assert opt.text == "Howdy!"

        # Test setter
        opt.text = "Do\noo\ndy!"  # <= 12 - 1*2 wide, less than 5 - 1*2 high
        assert opt.text == "Do\noo\ndy!"

        # Test setter parameter checking.
        with self.assertRaises(Exception):
            opt.text = "Groooooooooooooooooooooooooooooot."  # Too long entirely

        with self.assertRaises(Exception):
            opt.text = "Mooooooood."  # Too long given horizontal padding

        with self.assertRaises(Exception):
            opt.text = "Loo\n\oo\noo\nooo\n\ooo\n\oooot\n"  # Too many lines entirely

        with self.assertRaises(Exception):
            opt.text = "Fooo\nooooo\nooooo\noooods"  # Too many lines after vertical padding
コード例 #6
0
    def test_add_option(self):
        """Tests that Menu.add_option() adds a valid MenuOption to Menu.contents."""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1,
                         color=(200, 255, 200))
        menu = Menu(20, 20)
        menu.add_option(opt)

        assert opt in menu.contents
コード例 #7
0
    def test_clear(self):
        """Tests that Menu.clear() will remove all its MenuOptions from its contents."""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1,
                         color=(200, 255, 200))
        menu = Menu(20, 20, contents=[opt])
        assert opt in menu.contents

        menu.clear()
        assert opt not in menu.contents
コード例 #8
0
    def test_rows(self):
        """Tests that the MenuOption can render itself to a row x col 2D list of (character, (r, g, b)) tuples."""
        opt = MenuOption("AB\nCD",
                         width=6,
                         height=4,
                         on_select=lambda x: print("AB CD!"),
                         subtext="It says some letters",
                         pad_horizontal=1,
                         pad_vertical=1,
                         color=(200, 200, 200))
        rows: RenderableArray = opt.rows
        a: RenderableItem = rows[3][3]

        assert a[0] == "A"
        assert a[1] == (200, 200, 200)
コード例 #9
0
    def test_contents(self):
        """Tests getter for Menu.contents and that it rejects assignment."""
        opt = MenuOption("Howdy!",
                         width=12,
                         height=5,
                         on_select=lambda x: print("Howdy!"),
                         subtext="It says howdy",
                         pad_horizontal=1,
                         pad_vertical=1,
                         color=(200, 255, 200))
        menu = Menu(width=20, height=20, has_border=True, contents=[opt])

        assert opt in menu.contents

        with self.assertRaises(Exception):
            menu.contents = [opt]
コード例 #10
0
def main():
    # Make the multiprocessing logic used in the modules happy.
    mp.freeze_support()

    # Load the tileset and context
    tileset = tcod.tileset.load_tilesheet("tilesets/yayo_c64_16x16.png", 16, 16,
                                          charmap=tcod.tileset.CHARMAP_CP437)
    context = tcod.context.new(width=WIDTH,
                               height=HEIGHT,
                               tileset=tileset,
                               sdl_window_flags=FLAGS)

    interface = Interface(context)

    # Mock-up of generating the main menu, which should be its own class, I think
    menu = Menu(width=floor(WIDTH/(2*TILESET_SIZE)),
                height=floor(HEIGHT/TILESET_SIZE),
                interface=interface,
                spacing=1)

    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()

    menu.add_option(MenuOption(text="Start Game",
                               width=24, height=5,
                               on_select=launch_the_game))
    menu.add_option(MenuOption(text="Do Nothing",
                               width=24, height=5,
                               on_select=lambda x: print("Did nothing!")))
    menu.add_option(MenuOption(text="Do Nothing Else",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Do More Nothing",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Make this menu long",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Like REALLY long",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Because we, ah...",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Need to tests something",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="You know, uh...",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="that one thing...",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Oh yeah!",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    menu.add_option(MenuOption(text="Overflow behavior! :)",
                               width=24, height=5,
                               on_select=lambda x: print("Did more nothing!")))
    interface.open_menu(menu)

    last_tick = __time_ms()  # In epoch milliseconds
    tick_length = 50         # Milliseconds per engine tick
    while True:
        now_ms = __time_ms()

        # Only run the main loop logic if we've reached the next clock increment
        if now_ms - last_tick >= tick_length:
            if interface.playfield:
                win_width, win_height = context.recommended_console_size(min_columns=50,
                                                                         min_rows=40)
                interface.playfield.window = (win_width - READOUT_WIDTH,
                                              win_height - GAMELOG_HEIGHT)
            interface.tick()
            interface.print_self()

            # Forward the reference time to the time at which we started this batch of logic
            last_tick = now_ms