Exemple #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)
Exemple #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])
Exemple #3
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]})')
        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":
        viewport = [10, 10]
        g.partial_display_viewport = viewport
    elif key == "2":
Exemple #5
0
import gamelib.Constants as Constants

# First let's create a Board that uses squares as delimiters
myboard = Board(
                name='A demo board',
                size=[40,20],
                ui_border_left=Utils.WHITE_SQUARE, # Borders are going to be white squares
                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, # Cells with nothing inside are going to be black squares
                player_starting_position=[10,20]
                )

# Then create a player 
playerone = Player( model=Utils.yellow_bright('××') )

# Place it on the board
myboard.place_item(playerone, 10,10)

# Now let's display our board
myboard.display()

# And make a short loop that moves the player and display the board 
# WARNING: in real life we would use the Game object to manage the game and the screen

for k in range(1,10,1):
    # Clear screen
    Utils.clear_screen()
    # Print a debug message
    Utils.debug(f'Round {k} player position is ({playerone.pos[0]},{playerone.pos[1]}) -- BEFORE moving')
          (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":
        break
    elif key == "1":
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()

    # Key handler
    if key == 'q':
        print(Utils.yellow_bright("Good bye and thank you for playing!"))
Exemple #8
0
    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)
# First let's create a Board that uses squares as delimiters
# Borders are going to be white squares
# Cells with nothing inside are going to be black squares
myboard = Board(
    name="A demo board",
    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=[10, 20],
)

# Then create a player
playerone = Player(model=Utils.yellow_bright("××"))

# Place it on the board
myboard.place_item(playerone, 10, 10)

# Now let's display our board
myboard.display()

# And make a short loop that moves the player and display the board
# WARNING: in real life we would use the Game object to manage the game
# and the screen
for k in range(1, 10, 1):
    # Clear screen
    Utils.clear_screen()
    # Print a debug message
    Utils.debug(
Exemple #10
0
        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()

if os.path.exists("settings-suparex.json"):
    g.load_config("settings-suparex.json", "settings")
    if g.config("settings")["player_name"] is not None:
        g.player.name = g.config("settings")["player_name"]
else:

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

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)

blocker = NPC(model=Sprites.SKULL)
g.current_board().place_item(blocker, 20, 1)
Exemple #12
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)
Exemple #13
0
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':
        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':
Exemple #14
0
        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:
    game.clear_screen()
    print(
        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,
    10,
)
Exemple #16
0
    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)
        hmaps = []
        try:
Exemple #17
0

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

blocker = NPC(model=Sprites.SKULL)
g.current_board().place_item(blocker, 20, 1)
Exemple #18
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()

# We haven't place nazbrok on any board, but that's ok because we are going
# to use Game to manage the starting position of our player