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 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])
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)
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)
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")
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()
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)
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()
# 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()