예제 #1
0
 def setUp(self):
     super().setUp()
     self.game = Game()
     self.board = self.game.load_board("hac-maps/kneighbors.json", 1)
     self.game.player = Player(name="player")
     self.game.change_level(1)
     self.tree26 = self.board.item(2, 6)
     self.treasure38 = self.board.item(3, 8)
     self.tree39 = self.board.item(3, 9)
     self.wall45 = self.board.item(4, 5)
     self.wall46 = self.board.item(4, 6)
     self.wall47 = self.board.item(4, 7)
     self.wall57 = self.board.item(5, 7)
     self.npc77 = self.board.item(7, 7)
     self.treasure1212 = self.board.item(12, 12)
     self.tree1310 = self.board.item(13, 10)
     self.npc168 = self.board.item(16, 8)
예제 #2
0
def make_platform(b, row, column):
    psize = random.randint(2, 10)
    plateform = []
    tmp_game = Game()
    # Only because Game needs it, we don't care.
    tmp_game.player = Player()
    tmp_game.add_board(0, b)
    tmp_game.change_level(0)
    # print(
    #     f"[d] make_platform at {row}, {column}, psize is {psize} column will be "
    #     f"between {column} and {column + psize + 1}"
    # )
    get_up = 0
    # for i in range(column, column + psize + 1):
    for i in range(column - psize - 1, column):
        if i >= b.size[0]:
            break
        if not isinstance(b.item(row, i), BoardItemVoid):
            break
        if i in b.visited_columns:
            break
        # Check if we have other platforms around.
        # If yes moving the platform up.
        if get_up < 3:
            for e in tmp_game.neighbors(2, Door(pos=[row, i])):
                if e.type == "ground":
                    get_up = 3
                    break
        if get_up < 4:
            for e in tmp_game.neighbors(1, Door(pos=[row, i])):
                if e.type == "ground":
                    get_up = 4
                    break
        m = block_color() + "  " + Utils.Style.RESET_ALL
        plateform.append([Wall(model=m, type="platform"), row, i])
    for i in plateform:
        b.place_item(i[0], i[1] - get_up, i[2])
        if random.choice([True, False]):
            generate_treasure(b, i[1] - get_up - 1, i[2])
        else:
            generate_trap(b, i[1] - get_up - 1, i[2])
        b.visited_columns.append(i[2])
예제 #3
0
import gamelib.Utils as Utils
import time
import sys


# Destination 17,12
dest_row = 24
dest_col = 24

if len(sys.argv) > 1:
    dest_row = int(sys.argv[1])

if len(sys.argv) > 2:
    dest_col = int(sys.argv[2])
print(f'dest_row={dest_row} dest_col={dest_col}')
g = Game()
# b = g.load_board('hac-maps/Debug_board.json',1)
# b = g.load_board('hac-maps/PathFinding.json',1)
b = g.load_board('hac-maps/Maze.json',1)

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.set_destination(dest_row,dest_col)
path = pf.find_path()
print("Path found:")
print(path)

for (r,c) in path:
예제 #4
0
    print(Utils.blue_bright("\t\tNew board"))
    print("First we need some information on your new board:")
    name = str(input('Name: '))
    width = int(input_digit('Width (in number of cells): '))
    height = int(input_digit('Height (in number of cells): '))
    game.add_board(
        1,
        Board(name=name,
              size=[width, height],
              ui_borders=Utils.WHITE_SQUARE,
              ui_board_void_cell=Utils.BLACK_SQUARE))
    is_modified = True


# Main program
game = Game()
current_file = ''
game.player = Player(model='[]')
key = 'None'
current_object = BoardItemVoid(model='None')
object_history = []
current_menu = 'main'
while True:
    game.clear_screen()
    print(
        Utils.cyan_bright("HAC-GAME-LIB - EDITOR v" +
                          Constants.HAC_GAME_LIB_VERSION))

    print('Looking for existing maps in selected directories...', end='')
    with open('directories.json') as paths:
        directories = json.load(paths)
    for c in range(dg.width):
        if dg.dungeon[r][c].get_ch() == "#":
            random_board.place_item(Wall(model=Sprites.WALL), r, c)
        elif dg.dungeon[r][c].get_ch() == "+":
            random_board.place_item(Door(model=Sprites.DOOR), r, c)
        elif dg.dungeon[r][c].get_ch() == ".":
            potential_starting_position.append([r, c])
random_board.player_starting_position = choice(potential_starting_position)
print("done")
print(f"starting position chosen: {random_board.player_starting_position}")

# dg.print_map()
# random_board.display()
input("New random dungeon generated. Next?")

g = Game()
g.enable_partial_display = True
# g.load_board('/home/arnaud/Code/Games/hgl-editor/Large_Dungeon.json', 1)
g.player = Player(model=Sprites.MAGE)
g.add_board(1, random_board)
g.change_level(1)

key = None
viewport = [10, 10]
g.partial_display_viewport = viewport
while True:
    if key == "Q":
        break
    elif key == "S":
        g.save_board(1, f"random-dungeon-{randrange(1000,9999)}.json")
    elif key == "1":
예제 #6
0
from gamelib.Game import Game


g = Game()
c = g.load_config("test-config.json", "test")

print(f"Version: {g.config('test')['config_file_version']}")
g.config("test")["directories"].append("test_boards")
g.save_config("test", "config-test.json")
print(g.config("blorp"))
예제 #7
0
from gamelib.Game import Game
from gamelib.Board import Board
import gamelib.Utils as Utils
import gamelib.Sprites as Sprites
import gamelib.Constants as Constants
from gamelib.Characters import Player
import time

mygame = Game(name='Demo Game')

board1 = Board(name='Level 1',
               ui_borders=Sprites.WALL,
               ui_board_void_cell=Utils.BLACK_SQUARE,
               player_starting_position=[0, 0])
board2 = Board(name='Level 2',
               ui_borders=Utils.RED_SQUARE,
               ui_board_void_cell=Utils.BLACK_SQUARE,
               player_starting_position=[4, 4])

mygame.player = Player(name='DaPlay3r', model=Sprites.UNICORN_FACE)

mygame.add_board(1, board1)
mygame.add_board(2, board2)

mygame.change_level(1)

key = None
# Main game loop
while True:
    mygame.clear_screen()
    mygame.display_board()
예제 #8
0
from gamelib.Board import Board
import gamelib.Utils as Utils
import gamelib.Sprites as Sprites
from gamelib.Characters import Player
import time

#################################################################################
##                                                                             ##
## IMPORTANT NOTE:                                                             ##
##                                                                             ##
## The companion article for this tutorial code is at:                         ##
## https://astro.hyrul.es/guides/hac-game-lib/tutorial-01-the-game-object.html ##
##                                                                             ##
#################################################################################

mygame = Game(name='Demo game')
board1 = Board(name='Level 1',
               ui_borders=Sprites.WALL,
               ui_board_void_cell=Utils.BLACK_SQUARE,
               player_starting_position=[0, 0])
board2 = Board(name='Level 2',
               ui_borders=Utils.RED_SQUARE,
               ui_board_void_cell=Utils.BLACK_SQUARE,
               player_starting_position=[4, 4])

mygame.player = Player(name='DaPlay3r', model=Sprites.UNICORN_FACE)

mygame.add_board(1, board1)
mygame.add_board(2, board2)

count = 0
예제 #9
0
import gamelib.Sprites as Sprites
import gamelib.Constants as Constants
import gamelib.Utils as Utils
import time
import sys

board_to_load = 'hac-maps/test-board.json'

if len(sys.argv) > 1:
    board_to_load = sys.argv[1]

max_iter = 10
if len(sys.argv) > 2:
    max_iter = int(sys.argv[2])

g = Game()

b = g.load_board(board_to_load, 1)

print(b)

g.player = Player(model=Sprites.FLYING_SAUCER)
g.change_level(1)

idx = 0
key = None

while idx < max_iter or max_iter == 0:
    if key == 'w':
        g.move_player(Constants.UP, 1)
    elif key == 's':
예제 #10
0
    global g
    for i in g.current_board().get_immovables(type='path_marker'):
        g.current_board().place_item(BoardItemVoid(), i.pos[0], i.pos[1])


# Destination (24,24) is the center of the labyrinth
dest_row = 24
dest_col = 24

if len(sys.argv) > 1:
    dest_row = int(sys.argv[1])

if len(sys.argv) > 2:
    dest_col = int(sys.argv[2])

g = Game()
b = g.load_board('hac-maps/Maze.json', 1)

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)
예제 #11
0
                            ": I am so lonely, if only I had an aquatic friend to play with..."
                        )


# The board we want to load for the first level
level_1 = 'levels/TutoMap-hac-game-lib.json'

# And the game over screen
game_over = 'levels/Game_Over.json'

# The notifications are going to be used to give info to the player without entering a full dialog mode.
# IMPORTANT: The player movement clears the notifications not the rest of the game. As we are going to multithread the game at some point it's important to take the right decision from start.
notifications = []

# Create the game object. We are going to use this as a global variable.
g = Game()

# Load the board as level 1
b = g.load_board(level_1, 1)
# The game over screen is going to be level 999. There is no reason for that, it is just a convention as I don't think that this game is going to have more than 998 levels.
g.load_board(game_over, 999)

# Create the player object.
g.player = Player(name='The Mighty Wizard', model=Sprites.MAGE)
g.change_level(1)

# Now we need to fix the river (it's missing 2 tiles of water)
# First let's move the NPCs so the whales are not replaced by our new tiles.
g.actuate_npcs(1)
# Now let's place the 2 river tiles (we use the Door object as a shortcut to get a overlapable, restorable item)
g.current_board().place_item(Door(model=Utils.BLUE_SQUARE), 0, 26)
예제 #12
0
            default_map_dir, "hac-maps", "maps"
        ]
        game.config("settings")["config_file_version"] = 10100
        game.config("settings")["enable_partial_display"] = True
        game.config("settings")["partial_display_viewport"] = [10, 30]
        game.config("settings")["menu_mode"] = "full"
        game.config("settings")["last_used_board_parameters"] = {
            "name": None,
            "width": None,
            "height": None,
        }
        game.config("settings")["object_library"] = []


# Main program
game = Game()
current_file = ""
game.player = Player(model="[]")
key = "None"
current_object = BoardItemVoid(model="None")
current_object_instance = BoardItemVoid(model="None")
object_history = []
viewport_board = Board(
    name="Viewport testing board",
    size=[viewport_width * 2, viewport_height * 2],
    ui_borders=Utils.GREEN_SQUARE,
    ui_board_void_cell=Utils.RED_SQUARE,
)
game.add_board(2, viewport_board)
current_menu = "main"
while True:
예제 #13
0
            sum_dc = eucli_dist
            # print(
            #     f"Updating winner with {winner} and deltas {dc_r},{dc_c} "
            #     f"and sum_dc = {sum_dc}"
            # )
    if DEBUG:
        reset_drawn_path()
        g.current_board().place_item(
            Door(model=Utils.GREEN_SQUARE, type="path_marker"), winner[0],
            winner[1])
        redraw()
    # input(f'Winner: {winner}')
    return winner


g = Game()
# b = g.load_board('/home/arnaud/Code/Games/hgl-editor/TestChasing.json', 1)
b = g.load_board("hac-maps/The_Castle.json", 1)

g.player = Player(name="The Mighty Wizard", model=Sprites.MAGE)
g.change_level(1)

guards = []

for item in g.current_board().get_movables(type="guard"):
    guards.append(item)

nm = None
key = None
chasing = False
        g.actuate_projectiles(1)
        g.animate_items(1)
        time.sleep(0.1)


game_running = True
b = Board(
    ui_borders=Graphics.WHITE_SQUARE,
    ui_board_void_cell=Graphics.BLACK_SQUARE,
    size=[20, 20],
    player_starting_position=[5, 5],
)
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,
예제 #15
0
        d.animation = a
        # Finally place the water on the board
        b.place_item(d, r, c)
    # Redraw the screen and wait to see the nice animation of the algorithm working.
    # Otherwise it's instantanous.
    redraw_screen(g)
    time.sleep(0.1)
    # Now make recursive calls to fill the cells around this one.
    flood_filler(g, b, r + 1, c)
    flood_filler(g, b, r - 1, c)
    flood_filler(g, b, r, c + 1)
    flood_filler(g, b, r, c - 1)


# Using the Game object just to load the board easily
g = Game()
b = g.load_board("/home/arnaud/Code/Games/hgl-editor/Filler.json", 1)
g.player = Player(model=Graphics.Sprites.MAGE)
g.change_level(1)
# We need the player out of our way
g.move_player(Constants.LEFT, 5)

# Now let's flood the floor!!
flood_filler(g, b, 5, 6)

# Show the animated lake for 200 turns (~40 secondes)
i = 0
while i < 200:
    i += 1
    redraw_screen(g)
    g.animate_items(1)
예제 #16
0
lvl1 = Board(ui_borders=Utils.CYAN_SQUARE,
             ui_board_void_cell=Utils.BLACK_SQUARE,
             player_starting_position=[0, 0])

# On that board the player starts at the center
lvl2 = Board(ui_borders=Utils.MAGENTA_SQUARE,
             ui_board_void_cell=Utils.BLACK_SQUARE,
             player_starting_position=[5, 5])

# And on that board the player starts at the bottom right corner
lvl3 = Board(ui_borders=Utils.RED_SQUARE,
             ui_board_void_cell=Utils.BLACK_SQUARE,
             player_starting_position=[9, 9])

# Now let's create a game object.
mygame = Game(name='demo')

# And a Player
nazbrok = Player(name='Nazbrok', model=Utils.green_bright("¤¤"))

# Now add the boards to the game so the Game object can manage them
# the parameters of add_board() are a level number and a board.
mygame.add_board(1, lvl1)
mygame.add_board(2, lvl2)
mygame.add_board(3, lvl3)

# Now we also want our player to be managed by the game
mygame.player = nazbrok

# Now let's show a clean screen to our player
mygame.clear_screen()
예제 #17
0
    ui_border_bottom=Utils.WHITE_SQUARE,
    ui_board_void_cell=Utils.BLACK_SQUARE,
    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)
예제 #18
0
from gamelib.Board import Board
from gamelib.Characters import Player, Vehicle
from gamelib.Game import Game
import gamelib.Utils as Utils
import gamelib.Constants as Constants

g = Game()
g.player = Player(model="\u232C")

b = Board(size=[80, 50])
mod_right = [["\u25E3", " "], ["\u25A2", "\u25D7"], ["\u25E4", " "]]
mod_left = [["\u25E2"], ["\u25D6", "\u25A2"], ["\u25E2"]]
mi = Vehicle(model=mod_right)

g.add_board(1, b)
g.change_level(1)
g.current_board().place_item(mi, 20, 20)

key = None

while True:
    if key == Utils.key.UP:
        g.current_board().move(mi, Constants.UP, 1)
    elif key == Utils.key.DOWN:
        g.current_board().move(mi, Constants.DOWN, 1)
    elif key == Utils.key.LEFT:
        # mi.update_model(mod_left)
        g.current_board().move(mi, Constants.LEFT, 1)
    elif key == Utils.key.RIGHT:
        # mi.update_model(mod_right)
        g.current_board().move(mi, Constants.RIGHT, 1)
예제 #19
0
from gamelib.Game import Game
from gamelib.Board import Board
from gamelib.Characters import Player, NPC
from gamelib.Structures import Door, Treasure
from gamelib.BoardItem import BoardItemVoid
import gamelib.Sprites as Sprites
import gamelib.Constants as Constants
import gamelib.Utils as Utils
import time
import random

## Here are our global variables (it is usually a bad idea to use global variables but it will simplify that tutorial, keep in mind that we don't usually rely on global variables)

# Create the game object. We are going to use this as a global variable.
g = Game()
# Load the board as level 1
b = g.load_board('levels/TutoMap-hac-game-lib.json', 1)


def refresh_screen():
    global g

    g.clear_screen()
    g.display_player_stats()
    g.display_board()


def damage_player(params):
    pass
예제 #20
0
# IMPORTANT: The player movement clears the notifications not the rest of the game. As
# we are going to multithread the game at some point it's important to take the right
# decision from start.
notifications = []

# Now create a variable to hold the current menu.
current_menu = "default"

# We also need to keep track of how much gold was given to the fairy
fairy_gold = 0

# We will need to keep a counter for the number of turns left in level 2
level_2_turns_left = 21

# Create the game object. We are going to use this as a global variable.
g = Game()


def print_animated(message):
    for line in message:
        print(line, end="", flush=True)
        if line == "\n":
            time.sleep(1)
        else:
            time.sleep(0.1)


def introduction_scene():
    intro_dialog = (
        f"{Sprites.MAGE}: Hu... Where am I?\n"
        f"{Sprites.UNICORN_FACE}: Welcome Mighty Wizard!\n"
예제 #21
0
    nb_blocks = int((g.player.mp / g.player.max_mp) * 20)
    print("Mana [" + Utils.BLUE_RECT * nb_blocks + Utils.BLACK_RECT *
          (20 - nb_blocks) + "]")
    g.display_board()
    # manage_fireballs()


b = Board(
    ui_borders=Utils.WHITE_SQUARE,
    ui_board_void_cell=Utils.BLACK_SQUARE,
    size=[20, 20],
    player_starting_position=[5, 5],
)
wall = Wall(model=Sprites.WALL)
b.place_item(wall, 1, 6)
g = Game()
g.add_board(1, b)
g.player = Player(model=Sprites.MAGE, name="The Maje")
g.player.mp = 20
g.player.max_mp = 20
g.change_level(1)
key = None

black_circle = "-\U000025CF"
circle_jot = "-\U0000233E"

throw_fireball = False
projectile = Projectile()

while True:
    if key == "Q":
예제 #22
0
    global term, term_res
    if term.width >= 140:
        term_res = 140
    else:
        term_res = 80
    g.partial_display_viewport = [10, int(term_res / 4)]


# We need the hac-game-lib v1.1+
if Constants.HAC_GAME_LIB_VERSION < "1.1.0":
    Utils.print_white_on_red(
        "Super Panda Run EX require the hac-game-lib version 1.1.0 or greater."
        f" Version installed is {Constants.HAC_GAME_LIB_VERSION}")
    raise SystemExit()

g = Game()
g.enable_partial_display = True
g.partial_display_viewport = [10, int(term_res / 4)]
g.current_level = 0
g.player = Player(model=bg_color + Graphics.Sprites.PANDA +
                  Graphics.Style.RESET_ALL)
g.player.name = "Zigomar"
g.player.max_y = g.player.pos[0]
g.player.dy = gravity_speed
g.player.last_y = g.player.pos[0]
g.player.last_x = g.player.pos[1]
g.timer = 60
g.score = 0
g.obj_stack = []
g.pause()
예제 #23
0
import examples_includes  # noqa: F401

# For this example we need to import Game, Board, Utils and Player
from gamelib.Game import Game
import gamelib.Utils as Utils

# First of all let's create a Game object
mygame = Game(name="Demo game")

# Set a message variable to display a message on selected menu item
message = None

# Now we want to create some menus to tell the player what to do, or to
# give some informations/directions
# IMPORTANT: Menu do absolutely nothing by themselves, they are just a
# structured display of informations.
# The syntaxe is game_object.add_menu_entry(category,shortcut,message)
option_red = "A cool menu in dim red"
option_magenta = "Another cool menu in bright magenta"
mygame.add_menu_entry("main_menu", None, "=" * 22)
mygame.add_menu_entry("main_menu", "h", "Show the help menu")
mygame.add_menu_entry("main_menu", None, "=" * 22)
mygame.add_menu_entry("main_menu", "1", Utils.red_dim(option_red))
mygame.add_menu_entry("main_menu", "2", Utils.magenta_bright(option_magenta))
mygame.add_menu_entry("main_menu", "q", "Quit game")

mygame.add_menu_entry("help_menu", None, "---------")
mygame.add_menu_entry("help_menu", None, "Help Menu")
mygame.add_menu_entry("help_menu", None, "---------")
mygame.add_menu_entry("help_menu", "j", "Random help menu")
mygame.add_menu_entry("help_menu", "b", "Back to main menu")
예제 #24
0
# The notifications are going to be used to give info to the player without entering a full dialog mode.
# IMPORTANT: The player movement clears the notifications not the rest of the game. As we are going to multithread the game at some point it's important to take the right decision from start.
notifications = []

# Now create a variable to hold the current menu.
current_menu = 'default'

# We also need to keep track of how much gold was given to the fairy
fairy_gold = 0

# We will need to keep a counter for the number of turns left in level 2
level_2_turns_left = 21

# Create the game object. We are going to use this as a global variable.
g = Game()

def print_animated(message):
    for l in message:
        print(l,end='', flush=True)
        if l == '\n':
            time.sleep(1)
        else:
            time.sleep(0.1)

def introduction_scene():
    intro_dialog = f"{Sprites.MAGE}: Hu... Where am I?\n{Sprites.UNICORN_FACE}: Welcome Mighty Wizard!\n{Sprites.UNICORN_FACE}: Your help is needed to bring balance to the wildlife of this world.\n{Sprites.UNICORN_FACE}: Only then will you be able to ask the portal fairy to open the portal to continue your journey.\n{Sprites.UNICORN_FACE}: Good luck!\n{Sprites.MAGE}: Ok then, let's go!"

    g.clear_screen()
    print_animated(intro_dialog)
    
예제 #25
0
from gamelib.Game import Game
from gamelib.Characters import Player
import gamelib.Sprites as Sprites
import gamelib.Utils as Utils
import gamelib.Constants as Constants

g = Game()

b = g.load_board('hac-maps/kneighbors.json',1)


g.player = Player(model=Sprites.FLYING_SAUCER,name='player')
g.change_level(1)

key = None

while True:
    if key == 'w':
        g.move_player(Constants.UP,1)
    elif key == 's':
        g.move_player(Constants.DOWN,1)
    elif key == 'a':
        g.move_player(Constants.LEFT,1)
    elif key == 'd':
        g.move_player(Constants.RIGHT,1)
    elif key == 'q':
        break
    g.clear_screen()
    g.display_board()
    for i in g.neighbors(1):
        print(f'Player: {i.name} ({i.pos[0]},{i.pos[1]})')
예제 #26
0
import examples_includes
# For this example we need to import Game, Board, Utils and Player
from gamelib.Game import Game
import gamelib.Utils as Utils

# First of all let's create a Game object
mygame = Game(name='Demo game')

# Set a message variable to display a message on selected menu item
message = None

# Now we want to create some menus to tell the player what to do, or to give some informations/directions
# IMPORTANT: Menu do absolutely nothing by themselves, they are just a structured display of informations
# The syntaxe is game_object.add_menu_entry(category,shortcut,message)
mygame.add_menu_entry('main_menu', None, '=' * 22)
mygame.add_menu_entry('main_menu', 'h', 'Show the help menu')
mygame.add_menu_entry('main_menu', None, '=' * 22)
mygame.add_menu_entry('main_menu', '1',
                      Utils.red_dim('A cool menu in dim red'))
mygame.add_menu_entry(
    'main_menu', '2',
    Utils.magenta_bright('Another cool menu in bright magenta'))
mygame.add_menu_entry('main_menu', 'q', 'Quit game')

mygame.add_menu_entry('help_menu', None, '---------')
mygame.add_menu_entry('help_menu', None, 'Help Menu')
mygame.add_menu_entry('help_menu', None, '---------')
mygame.add_menu_entry('help_menu', 'j', 'Random help menu')
mygame.add_menu_entry('help_menu', 'b', 'Back to main menu')

# let's set a variable that hold the current menu category (for navigation)
예제 #27
0
    global g
    g.clear_screen()
    g.display_board()


# Destination (24,24) is the center of the labyrinth
dest_row = 24
dest_col = 24

if len(sys.argv) > 1:
    dest_row = int(sys.argv[1])

if len(sys.argv) > 2:
    dest_col = int(sys.argv[2])

g = Game()
b = g.load_board('hac-maps/Maze.json', 1)

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)
예제 #28
0
class GameNeighborTestCase(unittest.TestCase):
    def setUp(self):
        super().setUp()
        self.game = Game()
        self.board = self.game.load_board("hac-maps/kneighbors.json", 1)
        self.game.player = Player(name="player")
        self.game.change_level(1)
        self.tree26 = self.board.item(2, 6)
        self.treasure38 = self.board.item(3, 8)
        self.tree39 = self.board.item(3, 9)
        self.wall45 = self.board.item(4, 5)
        self.wall46 = self.board.item(4, 6)
        self.wall47 = self.board.item(4, 7)
        self.wall57 = self.board.item(5, 7)
        self.npc77 = self.board.item(7, 7)
        self.treasure1212 = self.board.item(12, 12)
        self.tree1310 = self.board.item(13, 10)
        self.npc168 = self.board.item(16, 8)

    def test_player_neighbors(self):
        testcases = (
            ([3, 3], []),
            ([3, 5], [self.tree26, self.wall45, self.wall46]),
            ([3, 6], [self.tree26, self.wall45, self.wall46, self.wall47]),
            ([3, 7], [self.tree26, self.wall46, self.wall47, self.treasure38]),
            ([4, 8], [self.wall47, self.wall57, self.treasure38, self.tree39]),
            ([5, 6], [self.wall45, self.wall46, self.wall47, self.wall57]),
        )

        for pos, expected_board_items in testcases:
            with self.subTest(str(pos)):
                self.game.player.pos = pos
                actual_board_items = self.game.neighbors()
                assertion_message = " ".join([
                    readable_board_items(expected_board_items),
                    "!=",
                    readable_board_items(actual_board_items),
                ])
                self.assertSetEqual(
                    set(expected_board_items),
                    set(actual_board_items),
                    assertion_message,
                )

    def test_npc_neighbors(self):
        def move_player_next_to_npc77():
            pos_next_to_npc = [7, 8]
            self.game.move_player(Constants.DOWN, pos_next_to_npc[0])
            self.game.move_player(Constants.RIGHT, pos_next_to_npc[1])
            self.assertEqual(pos_next_to_npc, self.game.player.pos)

        actual_board_items = self.game.neighbors(1, self.npc77)
        self.assertSetEqual(set(), set(actual_board_items))

        move_player_next_to_npc77()
        actual_board_items = self.game.neighbors(1, self.npc77)
        self.assertSetEqual({self.game.player}, set(actual_board_items))

    def dump_board_items(self):
        h, w = self.board.size
        for y in range(h):
            for x in range(w):
                boarditem = self.board.item(y, x)
                assert isinstance(boarditem, BoardItem)
                if isinstance(boarditem, BoardItemVoid):
                    continue
                print(readable_board_item(boarditem))