コード例 #1
0
ファイル: 99-final-game.py プロジェクト: kaozdl/hac-game-lib
def whale_behavior():
    # This function is really only the minimum viable product. We could do much better, for example:
    # 1) We could implement dialogues so we leave to the player to give or not the octopus.
    # 2) We could implement different dialogues to give hints more gradually to the player.
    # 3) One more thing is that we should use Actuators.pause() and Actuator.run() to prevent the whale from moving away from the player (that part is going to be critical when we multi-thread the program).
    # That list is non exhaustive.
    global g
    global notifications
    whales = []
    # Here we only ask for the movable objects (like the NPCs) that have "whale" in their type. 
    # This matches both "left_whale" and "right_whale"
    for item in g.current_board().get_movables(type="whale"):
        if item.type == 'right_whale' or item.type == 'left_whale':
            whales.append(item)
    if len(whales) > 0:
        for whale in whales:
            # Let's look at the neighborhood of the whales (within a 2 cells radius)
            for item in g.neighbors(2,whale):
                # If there is a Player around, then look into the inventory...
                if isinstance(item,Player):
                    inventory_item_name = None
                    # And reserve that Happy Octopus if present
                    for item_name in g.player.inventory.items_name():
                        if item_name.startswith('Happy Octopus'):
                            inventory_item_name = item_name
                            break
                    if inventory_item_name != None:
                        row = 0
                        column = 0
                        if whale.type == 'left_whale':
                            g.add_npc(1,NPC(model=Sprites.OCTOPUS,name="Swimming Octopus (Left)",type="swimming_octopus"),8,16)
                            row = 26
                            column = 32
                        else:
                            g.add_npc(1,NPC(model=Sprites.OCTOPUS,name="Swimming Octopus (Right)",type="swimming_octopus"),14,37)
                            row = 25
                            column = 32
                        notifications.append(whale.model+": Thank you! Here, let me extinguish that fire for you!")
                        notifications.append(whale.model+": "+Sprites.WATER_DROP)
                        g.player.inventory.delete_item(inventory_item_name)
                        g.current_board().item(row,column).model = Sprites.WATER_DROP
                        whale.type = 'happy_' + whale.type
                        refresh_screen()
                        time.sleep(1.5)
                        g.current_board().clear_cell(row,column)
                        refresh_screen()
                        
                    else:
                        notifications.append(whale.model+": I am so lonely, if only I had an aquatic friend to play with...") 
コード例 #2
0
    def test_play_all(self):
        self.item = NPC(model='-o-', name='Dancer')
        self.animation = Animation(animated_object=self.item,
                                   refresh_screen=self.redraw,
                                   display_time=0.5)
        self.animation.add_frame('-o-')
        self.animation.add_frame('\\o-')
        self.animation.add_frame('\\o\\')
        self.animation.add_frame('|o|')
        self.assertTrue(self.animation.play_all())
        self.animation.pause()
        self.assertFalse(self.animation.play_all())
        self.animation.stop()
        self.assertFalse(self.animation.play_all())
        self.animation = Animation(animated_object='breaking',
                                   refresh_screen=self.redraw,
                                   display_time=0.5)
        with self.assertRaises(Exception) as context:
            self.animation.play_all()
        self.assertTrue(
            'needs to be a sub class of BoardItem' in str(context.exception))

        self.animation = Animation(animated_object=self.item,
                                   refresh_screen='breaking',
                                   display_time=0.5)
        with self.assertRaises(Exception) as context:
            self.animation.play_all()
        self.assertTrue('needs to be a callback function reference' in str(
            context.exception))
コード例 #3
0
ファイル: test_animation.py プロジェクト: bwirtz/hac-game-lib
    def test_play_all(self):
        self.item = NPC(model="-o-", name="Dancer")
        self.animation = Animation(animated_object=self.item,
                                   refresh_screen=self.redraw,
                                   display_time=0.5)
        self.animation.add_frame("-o-")
        self.animation.add_frame("\\o-")
        self.animation.add_frame("\\o\\")
        self.animation.add_frame("|o|")
        self.assertTrue(self.animation.play_all())
        self.animation.pause()
        self.assertFalse(self.animation.play_all())
        self.animation.stop()
        self.assertFalse(self.animation.play_all())
        self.animation = Animation(animated_object="breaking",
                                   refresh_screen=self.redraw,
                                   display_time=0.5)
        with self.assertRaises(Exception) as context:
            self.animation.play_all()
        self.assertTrue(
            "needs to be a sub class of BoardItem" in str(context.exception))

        self.animation = Animation(animated_object=self.item,
                                   refresh_screen="breaking",
                                   display_time=0.5)
        with self.assertRaises(Exception) as context:
            self.animation.play_all()
        self.assertTrue("needs to be a callback function reference" in str(
            context.exception))
コード例 #4
0
ファイル: test_animation.py プロジェクト: bwirtz/hac-game-lib
 def test_pause(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.pause()
     self.assertEqual(self.animation.state, Constants.PAUSED)
コード例 #5
0
 def test_stop(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(parent=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.stop()
     self.assertEqual(self.animation.state, Constants.STOPPED)
コード例 #6
0
 def test_stop(self):
     self.item = NPC(model='-o-', name='Dancer')
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.stop()
     self.assertEqual(self.animation.state, Constants.STOPPED)
コード例 #7
0
 def test_add_frame(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(parent=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame("\\o-")
     with self.assertRaises(Exception) as context:
         self.animation.add_frame(2)
     self.assertTrue("must be a string" in str(context.exception))
コード例 #8
0
 def test_add_frame(self):
     self.item = NPC(model='-o-', name='Dancer')
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame('\\o-')
     with self.assertRaises(Exception) as context:
         self.animation.add_frame(2)
     self.assertTrue('must be a string' in str(context.exception))
コード例 #9
0
ファイル: test_animation.py プロジェクト: bwirtz/hac-game-lib
 def test_current_frame(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o\\")
     self.animation.add_frame("|o|")
     self.assertEqual(self.animation.current_frame(), "-o-")
     self.animation.next_frame()
     self.assertEqual(self.animation.current_frame(), "\\o-")
コード例 #10
0
 def test_current_frame(self):
     self.item = NPC(model='-o-', name='Dancer')
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame('-o-')
     self.animation.add_frame('\\o-')
     self.animation.add_frame('\\o\\')
     self.animation.add_frame('|o|')
     self.assertEqual(self.animation.current_frame(), '-o-')
     self.animation.next_frame()
     self.assertEqual(self.animation.current_frame(), '\\o-')
コード例 #11
0
ファイル: test_animation.py プロジェクト: bwirtz/hac-game-lib
 def test_search_frame(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o-")
     self.assertEqual(self.animation.search_frame("\\o-"), 1)
     self.assertNotEqual(self.animation.search_frame("\\o-"), 2)
     with self.assertRaises(Exception) as context:
         self.animation.search_frame(2)
     self.assertTrue("must be a string" in str(context.exception))
コード例 #12
0
ファイル: test_animation.py プロジェクト: bwirtz/hac-game-lib
 def test_next_frame(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o\\")
     self.animation.add_frame("|o|")
     self.assertEqual(self.animation.next_frame(), "\\o-")
     self.animation.pause()
     self.assertEqual(self.animation.next_frame(), "\\o-")
     self.animation.stop()
     self.assertIsNone(self.animation.next_frame())
     self.animation.animated_object = "This is going to break!"
     with self.assertRaises(Exception) as context:
         self.animation.next_frame()
     self.assertTrue(
         "needs to be a sub class of BoardItem" in str(context.exception))
コード例 #13
0
 def test_next_frame(self):
     self.item = NPC(model='-o-', name='Dancer')
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame('-o-')
     self.animation.add_frame('\\o-')
     self.animation.add_frame('\\o\\')
     self.animation.add_frame('|o|')
     self.assertEqual(self.animation.next_frame(), '\\o-')
     self.animation.pause()
     self.assertEqual(self.animation.next_frame(), '\\o-')
     self.animation.stop()
     self.assertIsNone(self.animation.next_frame())
     self.animation.animated_object = 'This is going to break!'
     with self.assertRaises(Exception) as context:
         self.animation.next_frame()
     self.assertTrue(
         'needs to be a sub class of BoardItem' in str(context.exception))
コード例 #14
0
ファイル: test_animation.py プロジェクト: bwirtz/hac-game-lib
 def test_remove_frame(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame("-o-")
     self.animation.add_frame("\\o-")
     self.animation.add_frame("\\o\\")
     self.animation.add_frame("|o|")
     self.animation.add_frame("/o/")
     self.animation.add_frame("-o/")
     with self.assertRaises(Exception) as context:
         self.animation.remove_frame(999)
     self.assertTrue("out of range" in str(context.exception))
     self.assertEqual(self.animation.remove_frame(0), "-o-")
     self.animation.next_frame()
     self.animation.next_frame()
     self.assertEqual(self.animation.remove_frame(2), "|o|")
     self.assertEqual(self.animation.current_frame(), "\\o\\")
     self.assertEqual(self.animation.next_frame(), "/o/")
コード例 #15
0
 def test_remove_frame(self):
     self.item = NPC(model='-o-', name='Dancer')
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.animation.add_frame('-o-')
     self.animation.add_frame('\\o-')
     self.animation.add_frame('\\o\\')
     self.animation.add_frame('|o|')
     self.animation.add_frame('/o/')
     self.animation.add_frame('-o/')
     with self.assertRaises(Exception) as context:
         self.animation.remove_frame(999)
     self.assertTrue('out of range' in str(context.exception))
     self.assertEqual(self.animation.remove_frame(0), '-o-')
     self.animation.next_frame()
     self.animation.next_frame()
     self.assertEqual(self.animation.remove_frame(2), '|o|')
     self.assertEqual(self.animation.current_frame(), '\\o\\')
     self.assertEqual(self.animation.next_frame(), '/o/')
コード例 #16
0
 def test_create_animation(self):
     self.item = NPC(model="-o-", name="Dancer")
     self.animation = Animation(parent=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.assertEqual(self.item.name, self.animation.parent.name)
コード例 #17
0
 def test_create_animation(self):
     self.item = NPC(model='-o-', name='Dancer')
     self.animation = Animation(animated_object=self.item,
                                refresh_screen=self.redraw,
                                display_time=0.5)
     self.assertEqual(self.item.name, self.animation.animated_object.name)
コード例 #18
0
    player_starting_position=[10, 20],
)
lvl2 = Board(
    name='Level_2',
    size=[40, 20],
    ui_border_left=Utils.WHITE_SQUARE,
    ui_border_right=Utils.WHITE_SQUARE,
    ui_border_top=Utils.WHITE_SQUARE,
    ui_border_bottom=Utils.WHITE_SQUARE,
    ui_board_void_cell=Utils.BLACK_SQUARE,
    player_starting_position=[0, 0],
)

game = Game(name='HAC Game')
p = Player(model=sprite_player['right'], name='Nazbrok')
npc1 = NPC(model=sprite_npc, name='Bad guy 1', step=1)
# Test of the PathActuator
npc1.actuator = PathActuator(path=[
    cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.UP, cst.RIGHT,
    cst.RIGHT, cst.RIGHT, cst.RIGHT, cst.DOWN, cst.DOWN, cst.DOWN, cst.DOWN,
    cst.DOWN, cst.DOWN, cst.DOWN, cst.DOWN, cst.LEFT, cst.LEFT, cst.LEFT,
    cst.LEFT
])

game.add_board(1, lvl1)
game.add_board(2, lvl2)

t = Treasure(model=sprite_treasure, name='Cool treasure', type='gem')
money_bag = Treasure(model=sprite_treasure2, name='money', value=20)

tree = GenericStructure(model=sprite_tree)
コード例 #19
0
ファイル: hgl-editor.py プロジェクト: A-Productions/pygamelib
def create_wizard():
    global game
    key = ""
    while True:
        game.clear_screen()
        print(Utils.green_bright("\t\tObject creation wizard"))
        print("What do you want to create: a NPC or a structure?")
        print("1 - NPC (Non Playable Character)")
        print("2 - Structure (Wall, Door, Treasure, Portal, Trees, etc.)")
        key = Utils.get_key()
        if key == "1" or key == "2":
            break
    if key == "1":
        game.clear_screen()
        print(
            Utils.green_bright("\t\tObject creation wizard: ") +
            Utils.cyan_bright("NPC"))
        new_object = NPC()
        print("First give a name to your NPC. Default value: " +
              new_object.name)
        r = str(input("(Enter name)> "))
        if len(r) > 0:
            new_object.name = r
        print(
            "Then give it a type. A type is important as it allows grouping.\n"
            "Type is a string. Default value: " + new_object.type)
        r = str(input("(Enter type)> "))
        if len(r) > 0:
            new_object.type = r
        print("Now we need a model. Default value: " + new_object.model)
        input('Hit "Enter" when you are ready to choose a model.')
        new_object.model = model_picker()
        game.clear_screen()
        print(
            Utils.green_bright("\t\tObject creation wizard: ") +
            Utils.cyan_bright("NPC") + f" - {new_object.model}")
        print("We now needs to go through some basic statistics. "
              "You can decide to go with default by simply hitting "
              'the "Enter" key.')
        r = input_digit(f"Number of cell crossed in one turn. "
                        f"Default: {new_object.step}(type: int) > ")
        if len(r) > 0:
            new_object.step = int(r)
        else:
            # If it's 0 it means it's going to be a static NPC so to prevent
            # python to pass some random pre-initialized default, we explicitly
            # set the Actuator to a static one
            new_object.actuator = SimpleActuators.RandomActuator(moveset=[])

        r = input_digit(f"Max HP (Health Points). "
                        f"Default: {new_object.max_hp}(type: int) > ")
        if len(r) > 0:
            new_object.max_hp = int(r)
        new_object.hp = new_object.max_hp

        r = input_digit(f"Max MP (Mana Points). "
                        f"Default: {new_object.max_mp}(type: int) > ")
        if len(r) > 0:
            new_object.max_mp = int(r)
        new_object.mp = new_object.max_mp

        r = input_digit(
            f"Remaining lives (it is advised to set that to 1 for a "
            f"standard NPC). "
            f"Default: {new_object.remaining_lives}(type: int) > ")
        if len(r) > 0:
            new_object.remaining_lives = int(r)

        r = input_digit(f"AP (Attack Power). "
                        f"Default: {new_object.attack_power}(type: int) > ")
        if len(r) > 0:
            new_object.attack_power = int(r)

        r = input_digit(f"DP (Defense Power). "
                        f"Default: {new_object.defense_power}(type: int) > ")
        if len(r) > 0:
            new_object.defense_power = int(r)

        r = input_digit(
            f"Strength. Default: {new_object.strength}(type: int) > ")
        if len(r) > 0:
            new_object.strength = int(r)

        r = input_digit(
            f"Intelligence. Default: {new_object.intelligence}(type: int) > ")
        if len(r) > 0:
            new_object.intelligence = int(r)

        r = input_digit(
            f"Agility. Default: {new_object.agility}(type: int) > ")
        if len(r) > 0:
            new_object.agility = int(r)

        game.clear_screen()
        print("We now need to give some life to that NPC. "
              "What kind of movement should it have:")
        print("1 - Randomly chosen from a preset of directions")
        print("2 - Following a predetermined path")
        print("3 - Following a predetermined path back and forth")
        print(
            "4 - Automatically finding it's way from one point to another (no"
            " pre-determined path, you will set the points on the map).")
        r = Utils.get_key()
        if r == "1":
            new_object.actuator = SimpleActuators.RandomActuator(moveset=[])
            print("Random it is! Now choose from which preset "
                  "of movements should we give it:")
            print("1 - UP,DOWN,LEFT, RIGHT")
            print("2 - UP,DOWN")
            print("3 - LEFT, RIGHT")
            print("4 - UP,DOWN,LEFT, RIGHT + all DIAGONALES")
            print("5 - DIAGONALES (DIAG UP LEFT, DIAG UP RIGHT, etc.) "
                  "but NO straight UP, DOWN, LEFT and RIGHT")
            print("6 - No movement")
            r = Utils.get_key()
            if r == "1":
                new_object.actuator.moveset = [
                    Constants.UP,
                    Constants.DOWN,
                    Constants.LEFT,
                    Constants.RIGHT,
                ]
            elif r == "2":
                new_object.actuator.moveset = [Constants.UP, Constants.DOWN]
            elif r == "3":
                new_object.actuator.moveset = [Constants.RIGHT, Constants.LEFT]
            elif r == "4":
                new_object.actuator.moveset = [
                    Constants.UP,
                    Constants.DOWN,
                    Constants.LEFT,
                    Constants.RIGHT,
                    Constants.DLDOWN,
                    Constants.DLUP,
                    Constants.DRDOWN,
                    Constants.DRUP,
                ]
            elif r == "5":
                new_object.actuator.moveset = [
                    Constants.DLDOWN,
                    Constants.DLUP,
                    Constants.DRDOWN,
                    Constants.DRUP,
                ]
            elif r == "6":
                new_object.actuator.moveset = []
            else:
                Utils.warn(
                    f'"{r}" is not a valid choice. Movement set is now empty.')
                new_object.actuator.moveset = []
        elif r == "2" or r == "3":
            if r == "2":
                new_object.actuator = SimpleActuators.PathActuator(path=[])
            elif r == "3":
                new_object.actuator = SimpleActuators.PatrolActuator(path=[])
            print("Great, so what path this NPC should take:")
            print("1 - UP/DOWN patrol")
            print("2 - DOWN/UP patrol")
            print("3 - LEFT/RIGHT patrol")
            print("4 - RIGHT/LEFT patrol")
            print("5 - Circle patrol: LEFT, DOWN, RIGHT, UP")
            print("6 - Circle patrol: LEFT, UP, RIGHT, DOWN")
            print("7 - Circle patrol: RIGHT, DOWN, LEFT, UP")
            print("8 - Circle patrol: RIGHT, UP, LEFT, DOWN")
            print("9 - Write your own path")
            r = Utils.get_key()
            if r == "1":
                print("How many steps should the NPC go in one direction "
                      "before turning back ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += ([
                    Constants.UP for i in range(0, r, 1)
                ], )
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
            elif r == "2":
                print("How many steps should the NPC go in one "
                      "direction before turning back ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == "3":
                print("How many steps should the NPC go in one "
                      "direction before turning back ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
            elif r == "3":
                print("How many steps should the NPC go in one direction "
                      "before turning back ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
            elif r == "4":
                print("How many steps should the NPC go in one "
                      "direction before turning back ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == "5":
                print("How many steps should the NPC go in EACH "
                      "direction before changing ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == "6":
                print("How many steps should the NPC go in EACH "
                      "direction before changing ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
            elif r == "7":
                print("How many steps should the NPC go in EACH "
                      "direction before changing ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == "8":
                print("How many steps should the NPC go in EACH direction "
                      "before changing ?")
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
            elif r == "9":
                print("Write your own path using only words from this list: "
                      "UP, DOWN, LEFT, RIGHT, DLDOWN, DLUP, DRDOWN, DRUP.")
                print("Each direction has to be separated by a coma.")
                r = str(input("Write your path: ")).upper()
                new_object.actuator.path = r.split(",")
            else:
                Utils.warn(f'"{r}" is not a valid choice. Path is now empty.')
                new_object.actuator.path = []
        elif r == "4":
            new_object.actuator = AdvancedActuators.PathFinder(
                parent=new_object, circle_waypoints=True)
            print(
                "Do you want the NPC to go through your way points once and stop or"
                " to cycle through all of them infinitely ?")
            print("1 - Cycle once")
            print("2 - Cycle infinitely (default value)")
            r = Utils.get_key()
            if r == "1":
                new_object.actuator.circle_waypoints = False
        return new_object
    elif key == "2":
        while True:
            game.clear_screen()
            print(
                Utils.green_bright("\t\tObject creation wizard: ") +
                Utils.magenta_bright("Structure"))
            print("What kind of structure do you want to create:")
            print(
                "1 - A wall like structure (an object that cannot be picked-up "
                "and is not overlappable). Ex: walls, trees, non moving "
                "elephant (try to go through an elephant or to pick it up "
                "in your backpack...)")
            print("2 - A door (player and/or NPC can go through)")
            print("3 - A treasure (can be picked up, take space in the "
                  "inventory, give points to the player)")
            print("4 - A generic object (you can set the properties to "
                  "make it pickable or overlappable)")
            print("5 - A generic actionable object (to make portals, heart "
                  "to replenish life, etc.)")
            key = Utils.get_key()
            new_object = None
            if key == "1":
                new_object = Structures.Wall()
                new_object.name = str(uuid.uuid1())
                new_object.model = model_picker()
                break
            elif key == "2":
                new_object = Structures.Door()
                new_object.name = str(uuid.uuid1())
                new_object.model = model_picker()
                break
            elif key == "3":
                new_object = Structures.Treasure()
                print("First give a name to your Treasure. Default value: " +
                      new_object.name)
                r = str(input("(Enter name)> "))
                if len(r) > 0:
                    new_object.name = r
                print("Then give it a type. A type is important as it allows "
                      "grouping (in this case probably in the inventory).\n"
                      "Type is a string. Default value: " + new_object.type)
                r = str(input("(Enter type)> "))
                if len(r) > 0:
                    new_object.type = r
                print("Now we need a model. Default value: " +
                      new_object.model)
                input('Hit "Enter" when you are ready to choose a model.')
                new_object.model = model_picker()
                break
            elif key == "4" or key == "5":
                if key == "4":
                    new_object = Structures.GenericStructure()
                else:
                    new_object = Structures.GenericActionableStructure()
                new_object.set_overlappable(False)
                new_object.set_pickable(False)
                print("First give a name to your structure. Default value: " +
                      new_object.name)
                r = str(input("(Enter name)> "))
                if len(r) > 0:
                    new_object.name = r
                print(
                    "Then give it a type. \nType is a string. Default value: "
                    + new_object.type)
                r = str(input("(Enter type)> "))
                if len(r) > 0:
                    new_object.type = r
                print("Now we need a model. Default value: " +
                      new_object.model)
                input('Hit "Enter" when you are ready to choose a model.')
                new_object.model = model_picker()
                print("Is this object pickable? (can it be picked up "
                      "by the player)?")
                print("0 - No")
                print("1 - Yes")
                r = Utils.get_key()
                if r == "1":
                    new_object.set_pickable(True)
                print("Is this object overlappable? (can it be walked "
                      "over by player?")
                print("0 - No")
                print("1 - Yes")
                r = Utils.get_key()
                if r == "1":
                    new_object.set_overlappable(True)
                break

        return new_object

    # Placeholder
    return BoardItemVoid()
コード例 #20
0
def create_wizard():
    global game
    key = ''
    while True:
        game.clear_screen()
        print(Utils.green_bright("\t\tObject creation wizard"))
        print('What do you want to create: a NPC or a structure?')
        print('1 - NPC (Non Playable Character)')
        print('2 - Structure (Wall, Door, Treasure, Portal, Trees, etc.)')
        key = Utils.get_key()
        if key == '1' or key == '2':
            break
    if key == '1':
        game.clear_screen()
        print(
            Utils.green_bright("\t\tObject creation wizard: ") +
            Utils.cyan_bright("NPC"))
        new_object = NPC()
        print("First give a name to your NPC. Default value: " +
              new_object.name)
        r = str(input('(Enter name)> '))
        if len(r) > 0:
            new_object.name = r
        print(
            "Then give it a type. A type is important as it allows grouping.\nType is a string. Default value: "
            + new_object.type)
        r = str(input('(Enter type)> '))
        if len(r) > 0:
            new_object.type = r
        print("Now we need a model. Default value: " + new_object.model)
        input('Hit "Enter" when you are ready to choose a model.')
        new_object.model = model_picker()
        game.clear_screen()
        print(
            Utils.green_bright("\t\tObject creation wizard: ") +
            Utils.cyan_bright("NPC") + f' - {new_object.model}')
        print(
            'We now needs to go through some basic statistics. You can decide to go with default by simply hitting the "Enter" key.'
        )
        r = input_digit(
            f'Number of cell crossed in one turn. Default: {new_object.step}(type: int) > '
        )
        if len(r) > 0:
            new_object.step = int(r)
        else:
            # If it's 0 it means it's going to be a static NPC so to prevent python to pass some random pre-initialized default, we explicitly set the Actuator to a static one
            new_object.actuator = SimpleActuators.RandomActuator(moveset=[])
        r = input_digit(
            f'Max HP (Health Points). Default: {new_object.max_hp}(type: int) > '
        )
        if len(r) > 0:
            new_object.max_hp = int(r)
        new_object.hp = new_object.max_hp
        r = input_digit(
            f'Max MP (Mana Points). Default: {new_object.max_mp}(type: int) > '
        )
        if len(r) > 0:
            new_object.max_mp = int(r)
        new_object.mp = new_object.max_mp
        r = input_digit(
            f'Remaining lives (it is advised to set that to 1 for a standard NPC). Default: {new_object.remaining_lives}(type: int) > '
        )
        if len(r) > 0:
            new_object.remaining_lives = int(r)
        r = input_digit(
            f'AP (Attack Power). Default: {new_object.attack_power}(type: int) > '
        )
        if len(r) > 0:
            new_object.attack_power = int(r)
        r = input_digit(
            f'DP (Defense Power). Default: {new_object.defense_power}(type: int) > '
        )
        if len(r) > 0:
            new_object.defense_power = int(r)
        r = input_digit(
            f'Strength. Default: {new_object.strength}(type: int) > ')
        if len(r) > 0:
            new_object.strength = int(r)
        r = input_digit(
            f'Intelligence. Default: {new_object.intelligence}(type: int) > ')
        if len(r) > 0:
            new_object.intelligence = int(r)
        r = input_digit(
            f'Agility. Default: {new_object.agility}(type: int) > ')
        if len(r) > 0:
            new_object.agility = int(r)
        game.clear_screen()
        print(
            "We now need to give some life to that NPC. What kind of movement should it have:"
        )
        print("1 - Randomly chosen from a preset of directions")
        print("2 - Following a predetermined path")
        r = Utils.get_key()
        if r == '1':
            new_object.actuator = SimpleActuators.RandomActuator(moveset=[])
            print(
                'Random it is! Now choose from which preset of movements should we give it:'
            )
            print('1 - UP,DOWN,LEFT, RIGHT')
            print('2 - UP,DOWN')
            print('3 - LEFT, RIGHT')
            print('4 - UP,DOWN,LEFT, RIGHT + all DIAGONALES')
            print(
                '5 - DIAGONALES (DIAG UP LEFT, DIAG UP RIGHT, etc.) but NO straight UP, DOWN, LEFT and RIGHT'
            )
            print('6 - No movement')
            r = Utils.get_key()
            if r == '1':
                new_object.actuator.moveset = [
                    Constants.UP, Constants.DOWN, Constants.LEFT,
                    Constants.RIGHT
                ]
            elif r == '2':
                new_object.actuator.moveset = [Constants.UP, Constants.DOWN]
            elif r == '3':
                new_object.actuator.moveset = [Constants.RIGHT, Constants.LEFT]
            elif r == '4':
                new_object.actuator.moveset = [
                    Constants.UP, Constants.DOWN, Constants.LEFT,
                    Constants.RIGHT, Constants.DLDOWN, Constants.DLUP,
                    Constants.DRDOWN, Constants.DRUP
                ]
            elif r == '5':
                new_object.actuator.moveset = [
                    Constants.DLDOWN, Constants.DLUP, Constants.DRDOWN,
                    Constants.DRUP
                ]
            elif r == '6':
                new_object.actuator.moveset = []
            else:
                Utils.warn(
                    f'"{r}" is not a valid choice. Movement set is now empty.')
                new_object.actuator.moveset = []
        elif r == '2':
            new_object.actuator = SimpleActuators.PathActuator(path=[])
            print("Great, so what path this NPC should take:")
            print('1 - UP/DOWN patrol')
            print('2 - DOWN/UP patrol')
            print('3 - LEFT/RIGHT patrol')
            print('4 - RIGHT/LEFT patrol')
            print('5 - Circle patrol: LEFT, DOWN, RIGHT, UP')
            print('6 - Circle patrol: LEFT, UP, RIGHT, DOWN')
            print('7 - Circle patrol: RIGHT, DOWN, LEFT, UP')
            print('8 - Circle patrol: RIGHT, UP, LEFT, DOWN')
            print('9 - Write your own path')
            r = Utils.get_key()
            if r == '1':
                print(
                    "How many steps should the NPC go in one direction before turning back ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
            elif r == '2':
                print(
                    "How many steps should the NPC go in one direction before turning back ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == '3':
                print(
                    "How many steps should the NPC go in one direction before turning back ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
            elif r == '3':
                print(
                    "How many steps should the NPC go in one direction before turning back ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
            elif r == '4':
                print(
                    "How many steps should the NPC go in one direction before turning back ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == '5':
                print(
                    "How many steps should the NPC go in EACH direction before changing ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == '6':
                print(
                    "How many steps should the NPC go in EACH direction before changing ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
            elif r == '7':
                print(
                    "How many steps should the NPC go in EACH direction before changing ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
            elif r == '8':
                print(
                    "How many steps should the NPC go in EACH direction before changing ?"
                )
                r = int(input_digit("(please enter an integer)> "))
                new_object.actuator.path += [
                    Constants.RIGHT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.UP for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.LEFT for i in range(0, r, 1)
                ]
                new_object.actuator.path += [
                    Constants.DOWN for i in range(0, r, 1)
                ]
            elif r == '9':
                print(
                    "Write your own path using only words from this list: UP, DOWN, LEFT, RIGHT, DLDOWN, DLUP, DRDOWN, DRUP."
                )
                print('Each direction has to be separated by a coma.')
                r = str(input('Write your path: ')).upper()
                new_object.actuator.path = r.split(',')
            else:
                Utils.warn(f'"{r}" is not a valid choice. Path is now empty.')
                new_object.actuator.path = []

        return new_object
    elif key == '2':
        while True:
            game.clear_screen()
            print(
                Utils.green_bright("\t\tObject creation wizard: ") +
                Utils.magenta_bright("Structure"))
            print("What kind of structure do you want to create:")
            print(
                '1 - A wall like structure (an object that cannot be picked-up and is not overlappable). Ex: walls, trees, non moving elephant (try to go through an elephant or to pick it up in your backpack...)'
            )
            print('2 - A door (player and/or NPC can go through)')
            print(
                '3 - A treasure (can be picked up, take space in the inventory, give points to the player)'
            )
            print(
                '4 - A generic object (you can set the properties to make it pickable or overlappable)'
            )
            print(
                '5 - A generic actionable object (to make portals, heart to replenish life, etc.)'
            )
            key = Utils.get_key()
            new_object = None
            if key == '1':
                new_object = Structures.Wall()
                new_object.name = str(uuid.uuid1())
                new_object.model = model_picker()
                break
            elif key == '2':
                new_object = Structures.Door()
                new_object.name = str(uuid.uuid1())
                new_object.model = model_picker()
                break
            elif key == '3':
                new_object = Structures.Treasure()
                print("First give a name to your Treasure. Default value: " +
                      new_object.name)
                r = str(input('(Enter name)> '))
                if len(r) > 0:
                    new_object.name = r
                print(
                    "Then give it a type. A type is important as it allows grouping (in this case probably in the inventory).\nType is a string. Default value: "
                    + new_object.type)
                r = str(input('(Enter type)> '))
                if len(r) > 0:
                    new_object.type = r
                print("Now we need a model. Default value: " +
                      new_object.model)
                input('Hit "Enter" when you are ready to choose a model.')
                new_object.model = model_picker()
                break
            elif key == '4' or key == '5':
                if key == '4':
                    new_object = Structures.GenericStructure()
                else:
                    new_object = Structures.GenericActionableStructure()
                new_object.set_overlappable(False)
                new_object.set_pickable(False)
                print("First give a name to your structure. Default value: " +
                      new_object.name)
                r = str(input('(Enter name)> '))
                if len(r) > 0:
                    new_object.name = r
                print(
                    "Then give it a type. \nType is a string. Default value: "
                    + new_object.type)
                r = str(input('(Enter type)> '))
                if len(r) > 0:
                    new_object.type = r
                print("Now we need a model. Default value: " +
                      new_object.model)
                input('Hit "Enter" when you are ready to choose a model.')
                new_object.model = model_picker()
                print(
                    'Is this object pickable? (can it be picked up by the player)?'
                )
                print('0 - No')
                print('1 - Yes')
                r = Utils.get_key()
                if r == '1':
                    new_object.set_pickable(True)
                print(
                    'Is this object overlappable? (can it be walked over by player?'
                )
                print('0 - No')
                print('1 - Yes')
                r = Utils.get_key()
                if r == '1':
                    new_object.set_overlappable(True)
                break

        return new_object

    #Placeholder
    return BoardItemVoid()
コード例 #21
0
ファイル: Game.py プロジェクト: bwirtz/hac-game-lib
 def _ref2obj(ref):
     obj_keys = ref.keys()
     local_object = BoardItemVoid()
     if "Wall" in ref["object"]:
         local_object = Structures.Wall()
     elif "Treasure" in ref["object"]:
         local_object = Structures.Treasure()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
     elif "GenericStructure" in ref["object"]:
         local_object = Structures.GenericStructure()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "pickable" in obj_keys:
             local_object.set_pickable(ref["pickable"])
         if "overlappable" in obj_keys:
             local_object.set_overlappable(ref["overlappable"])
     elif "Door" in ref["object"]:
         local_object = Structures.Door()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "pickable" in obj_keys:
             local_object.set_pickable(ref["pickable"])
         if "overlappable" in obj_keys:
             local_object.set_overlappable(ref["overlappable"])
         if "restorable" in obj_keys:
             local_object.set_restorable(ref["restorable"])
     elif "GenericActionableStructure" in ref["object"]:
         local_object = Structures.GenericActionableStructure()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "pickable" in obj_keys:
             local_object.set_pickable(ref["pickable"])
         if "overlappable" in obj_keys:
             local_object.set_overlappable(ref["overlappable"])
     elif "NPC" in ref["object"]:
         local_object = NPC()
         if "value" in obj_keys:
             local_object.value = ref["value"]
         if "size" in obj_keys:
             local_object._size = ref["size"]
         if "hp" in obj_keys:
             local_object.hp = ref["hp"]
         if "max_hp" in obj_keys:
             local_object.max_hp = ref["max_hp"]
         if "step" in obj_keys:
             local_object.step = ref["step"]
         if "remaining_lives" in obj_keys:
             local_object.remaining_lives = ref["remaining_lives"]
         if "attack_power" in obj_keys:
             local_object.attack_power = ref["attack_power"]
         if "actuator" in obj_keys:
             if "RandomActuator" in ref["actuator"]["type"]:
                 local_object.actuator = RandomActuator(moveset=[])
                 if "moveset" in ref["actuator"].keys():
                     for m in ref["actuator"]["moveset"]:
                         local_object.actuator.moveset.append(
                             _string_to_constant(m))
             elif "PathActuator" in ref["actuator"]["type"]:
                 local_object.actuator = PathActuator(path=[])
                 if "path" in ref["actuator"].keys():
                     for m in ref["actuator"]["path"]:
                         local_object.actuator.path.append(
                             _string_to_constant(m))
     # Now what remains is what is common to all BoardItem
     if not isinstance(local_object, BoardItemVoid):
         if "name" in obj_keys:
             local_object.name = ref["name"]
         if "model" in obj_keys:
             local_object.model = ref["model"]
         if "type" in obj_keys:
             local_object.type = ref["type"]
     return local_object
コード例 #22
0
def whale_behavior():
    global g
    global notifications
    whales = []
    # Here we only ask for the movable objects (like the NPCs) that have "whale" in their type.
    # This matches both "left_whale" and "right_whale"
    for item in g.current_board().get_movables(type="whale"):
        if item.type == 'right_whale' or item.type == 'left_whale':
            whales.append(item)
    # if right_whale != None:
    #     for item in g.neighbors(2,right_whale):
    #         if isinstance(item,Player):
    #             inventory_item_name = None
    #             for item_name in g.player.inventory.items_name():
    #                 if item_name.startswith('Happy Octopus'):
    #                    inventory_item_name = item_name
    #                    break
    #             if inventory_item_name != None:
    #                 g.player.inventory.delete_item(inventory_item_name)
    #                 g.current_board().place_item(BoardItemVoid(model=g.current_board().ui_board_void_cell),25,32)
    if len(whales) > 0:
        for whale in whales:
            # Let's look at the neighborhood of the whales (within a 2 cells radius)
            for item in g.neighbors(2, whale):
                # If there is a Player around, then look into the inventory...
                if isinstance(item, Player):
                    inventory_item_name = None
                    # And reserve that Happy Octopus if present
                    for item_name in g.player.inventory.items_name():
                        if item_name.startswith('Happy Octopus'):
                            inventory_item_name = item_name
                            break
                    if inventory_item_name != None:
                        row = 0
                        column = 0
                        if whale.type == 'left_whale':
                            g.add_npc(
                                1,
                                NPC(model=Sprites.OCTOPUS,
                                    name="Swimming Octopus (Left)",
                                    type="swimming_octopus"), 8, 16)
                            row = 26
                            column = 32
                        else:
                            g.add_npc(
                                1,
                                NPC(model=Sprites.OCTOPUS,
                                    name="Swimming Octopus (Right)",
                                    type="swimming_octopus"), 14, 37)
                            row = 25
                            column = 32
                        notifications.append(
                            whale.model +
                            ": Thank you! Here, let me extinguish that fire for you!"
                        )
                        notifications.append(whale.model + ": " +
                                             Sprites.WATER_DROP)
                        g.player.inventory.delete_item(inventory_item_name)
                        g.current_board().item(
                            row, column).model = Sprites.WATER_DROP
                        whale.type = 'happy_' + whale.type
                        refresh_screen()
                        time.sleep(1.5)
                        g.current_board().clear_cell(row, column)
                        refresh_screen()

                    else:
                        notifications.append(
                            whale.model +
                            ": I am so lonely, if only I had an aquatic friend to play with..."
                        )
コード例 #23
0
g.player = Player(name='The Mighty Wizard', model=Sprites.MAGE)
g.change_level(1)
g.actuate_npcs(1)

pf = PathFinder(game=g, actuated_object=g.player)

pf.add_waypoint(dest_row, dest_col)
pf.add_waypoint(24, 24)
pf.add_waypoint(21, 40)

pf.circle_waypoints = True

pf.set_destination(dest_row, dest_col)

blocker = NPC(model=Sprites.SKULL)
g.current_board().place_item(blocker, 20, 1)

nm = None
(wpr, wpc) = (None, None)
path = []

while nm != Constants.NO_DIR:
    nm = pf.next_move()

    # The following code is only to draw the path calculated by the PathFinder.
    (tmp_wpr, tmp_wpc) = pf.current_waypoint()
    if wpr != tmp_wpr or wpc != tmp_wpc:
        if len(path) != 0:
            reset_drawn_path()
        path = pf.current_path()
コード例 #24
0
 def _ref2obj(ref):
     obj_keys = ref.keys()
     local_object = BoardItemVoid()
     if 'Wall' in ref['object']:
         local_object = Structures.Wall()
     elif 'Treasure' in ref['object']:
         local_object = Structures.Treasure()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
     elif 'GenericStructure' in ref['object']:
         local_object = Structures.GenericStructure()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'pickable' in obj_keys:
             local_object.set_pickable(ref['pickable'])
         if 'overlappable' in obj_keys:
             local_object.set_overlappable(ref['overlappable'])
     elif 'Door' in ref['object']:
         local_object = Structures.Door()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'pickable' in obj_keys:
             local_object.set_pickable(ref['pickable'])
         if 'overlappable' in obj_keys:
             local_object.set_overlappable(ref['overlappable'])
         if 'restorable' in obj_keys:
             local_object.set_restorable(ref['restorable'])
     elif 'GenericActionableStructure' in ref['object']:
         local_object = Structures.GenericActionableStructure()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'pickable' in obj_keys:
             local_object.set_pickable(ref['pickable'])
         if 'overlappable' in obj_keys:
             local_object.set_overlappable(ref['overlappable'])
     elif 'NPC' in ref['object']:
         local_object = NPC()
         if 'value' in obj_keys:
             local_object.value = ref['value']
         if 'size' in obj_keys:
             local_object._size = ref['size']
         if 'hp' in obj_keys:
             local_object.hp = ref['hp']
         if 'max_hp' in obj_keys:
             local_object.max_hp = ref['max_hp']
         if 'step' in obj_keys:
             local_object.step = ref['step']
         if 'remaining_lives' in obj_keys:
             local_object.remaining_lives = ref['remaining_lives']
         if 'attack_power' in obj_keys:
             local_object.attack_power = ref['attack_power']
         if 'actuator' in obj_keys:
             if 'RandomActuator' in ref['actuator']['type']:
                 local_object.actuator = RandomActuator(moveset=[])
                 if 'moveset' in ref['actuator'].keys():
                     for m in ref['actuator']['moveset']:
                         local_object.actuator.moveset.append(
                             _string_to_constant(m))
             elif 'PathActuator' in ref['actuator']['type']:
                 local_object.actuator = PathActuator(path=[])
                 if 'path' in ref['actuator'].keys():
                     for m in ref['actuator']['path']:
                         local_object.actuator.path.append(
                             _string_to_constant(m))
     # Now what remains is what is common to all BoardItem
     if not isinstance(local_object, BoardItemVoid):
         if 'name' in obj_keys:
             local_object.name = ref['name']
         if 'model' in obj_keys:
             local_object.model = ref['model']
         if 'type' in obj_keys:
             local_object.type = ref['type']
     return local_object
コード例 #25
0
g.player = Player(name="The Mighty Wizard", model=Sprites.MAGE)
g.change_level(1)
g.actuate_npcs(1)

pf = PathFinder(game=g, actuated_object=g.player)

pf.add_waypoint(dest_row, dest_col)
pf.add_waypoint(24, 24)
pf.add_waypoint(21, 40)

pf.circle_waypoints = True

pf.set_destination(dest_row, dest_col)

blocker = NPC(model=Sprites.SKULL)
g.current_board().place_item(blocker, 20, 1)

wall = Wall(model=Sprites.WALL)
wall.animation = Animation(animated_object=wall)
wall.animation.add_frame(Sprites.BANKNOTE_DOLLARS)
wall.animation.add_frame(Sprites.BANKNOTE_EUROS)
wall.animation.add_frame(Sprites.BANKNOTE_WINGS)
g.current_board().place_item(wall, 5, 25)

# 43,28 43,34 39,34 39,40 44,40 44,28
patroller = NPC(model=Sprites.ALIEN, name="patroller")
patroller.actuator = PathFinder(game=g,
                                actuated_object=patroller,
                                circle_waypoints=True)
g.add_npc(1, patroller, 43, 29)
コード例 #26
0
g.player = Player(name='The Mighty Wizard', model=Sprites.MAGE)
g.change_level(1)
g.actuate_npcs(1)

pf = PathFinder(game=g, actuated_object=g.player)

pf.add_waypoint(dest_row, dest_col)
pf.add_waypoint(24, 24)
pf.add_waypoint(21, 40)

pf.circle_waypoints = True

pf.set_destination(dest_row, dest_col)

blocker = NPC(model=Sprites.SKULL)
g.current_board().place_item(blocker, 20, 1)

wall = Wall(model=Sprites.WALL)
wall.animation = Animation(animated_object=wall)
wall.animation.add_frame(Sprites.BANKNOTE_DOLLARS)
wall.animation.add_frame(Sprites.BANKNOTE_EUROS)
wall.animation.add_frame(Sprites.BANKNOTE_WINGS)
g.current_board().place_item(wall, 5, 25)

# 43,28 43,34 39,34 39,40 44,40 44,28
patroller = NPC(model=Sprites.ALIEN, name='patroller')
patroller.actuator = PathFinder(game=g, actuated_object=patroller)
g.add_npc(1, patroller, 42, 28)
patroller.actuator.set_destination(43, 29)
patroller.actuator.add_waypoint(43, 29)
コード例 #27
0
)
wall = Wall(model=Graphics.Sprites.BRICK)
b.place_item(wall, 1, 6)
b.place_item(wall, 5, 10)
g = Game()
g.add_board(1, b)
g.player = Player(model=Graphics.Sprites.MAGE)
g.player.level = 1
g.player.mp = 20
g.player.max_mp = 20

g.add_npc(
    1,
    NPC(
        name="Bob Soontobedead",
        model=Graphics.Sprites.SKULL,
        hp=10,
        actuator=RandomActuator(moveset=[Constants.NO_DIR]),
    ),
    6,
    10,
)
g.add_npc(
    1,
    NPC(
        name="Bob Soontobedead II",
        model=Graphics.Sprites.SKULL,
        hp=10,
        actuator=RandomActuator(moveset=[Constants.NO_DIR]),
    ),
    7,
    11,