def _init_map_and_cm(self, mapName): if mapName == "srandom" or mapName == "sRandom" or mapName == "sr" or mapName == "sR": # Single player random -> adds AI self.mapName = str(random.randint(100, 10000)) m = Map("random", numPlayers=2, AIPlayers=["1"], seed=int(self.mapName)) elif mapName == "random" or mapName == "Random" or mapName == "r" or mapName == "R": # Multi player random -> doesn't add AI self.mapName = str(random.randint(100, 10000)) m = Map("random", numPlayers=2, seed=int(self.mapName)) elif mapName.isdigit(): m = Map("random", numPlayers=2, seed=int(mapName)) self.mapName = mapName else: m = Map(os.path.join("maps", mapName + ".map")) self.mapName = mapName # self.map = Map(os.path.join("maps", "random", "random487.map")) self.cm = collision_model.CollisionManagerGrid( -BLEED, m.w * CELL_SIZE + BLEED, -BLEED, m.h * CELL_SIZE + BLEED, CELL_SIZE / 2, CELL_SIZE / 2) m.cm = self.cm self.scroller = ScrollingManager(viewport=director.window) self.scroller.add(m) self.h = CELL_SIZE * m.h if self.h < WINDOW_HEIGHT: self.h = WINDOW_HEIGHT self.w = CELL_SIZE * m.w if self.w < WINDOW_WIDTH: self.w = WINDOW_WIDTH return m
def clear(self): self.final_price = 0 self.price_for_sub = {} self.priority_pixels_for_sub = {} self.sub = {} self.priorities = {} self.config_map = Map() self.config_map = Map() self.output_map = Map() self.extra_volume_left = 0 self.as_extra_volume_left = 0
def test_get_fail(self): #Arrange m = Map("mappy", "somefilepath") n = Map("flappy", "anotherfilepath") mStore = MapStore() mStore.add(m) mStore.add(n) #Act and Assert self.assertIsNone(mStore.get("tappy"))
def test_get(self): #Arrange m = Map("mappy", "somefilepath") n = Map("flappy", "anotherfilepath") mStore = MapStore() mStore.add(m) mStore.add(n) #Act and Assert self.assertEquals(m, mStore.get("mappy"))
def init(self, sub, priorities): self.final_price = 0 self.price_for_sub = {} self.priority_pixels_for_sub = {} self.sub = sub self.priorities = priorities self.config_map = Map() self.output_map = Map() print("sub:", self.sub) self.config_map = self.sub[SubConsts.BASIC_LANDUSE_MAP].map self.build_basic_map_for_output_map() self.extra_volume_left = self.sub[SubConsts.EXTRA_VOLUME] self.as_extra_volume_left = 0
def test_list_all(self): # Arrange mp1 = Map("Test map 1", "") mp2 = Map("Test map 2", "") store = MapStore() store.add(mp1) store.add(mp2) # Act act = store.list_all() #Assert self.assertEqual(act, ["Test map 1", "Test map 2"])
def test_remove_map_exception(self): #Arrange m = Map("mappy", "somefilepath") n = Map("flappy", "anotherfilepath") mStore = MapStore() mStore.add(m) mStore.add(n) mStore.remove(m) #Act and Assert with self.assertRaises(Exception): mStore.remove(m)
def __init__(self, screen_size): self.screen = pygame.display.set_mode(screen_size, pygame.FULLSCREEN) self.screen.fill([255, 255, 255]) self.map = Map(self.screen, screen_size) self.strategy = Strategy(self.screen, screen_size) self.information = Information(self.screen, screen_size) self.fullmap = FullMap(self.screen, screen_size)
def setup(): global screen, game_controller, input_controller, main_tileset, map_level_1, player # Initializes pygame pygame.init() # Initializes the screen screen = pygame.display.set_mode(constants.SCREEN_SIZE, pygame.DOUBLEBUF) # Initializes the game controllers game_controller = GameController() input_controller = InputController() # Load the sprites main_tileset = Tileset(constants.FILEPATH_TILESET_MAIN, constants.TILESIZE) # Load the maps map_level_1 = Map() map_level_1.load_background(constants.FILEPATH_LEVEL1_BACKGROUND, main_tileset) map_level_1.load_foreground(constants.FILEPATH_LEVEL1_FOREGROUND, main_tileset) map_level_1.load_colliders(constants.FILEPATH_LEVEL1_COLLIDERS, main_tileset) # Load the player player = Player(constants.FILEPATH_CHARSET)
def hydrology(self, **runoff_landa): self.output_hyrology = Map() if (runoff_landa.get("runoff_co_map", default=None) is None & runoff_landa.get("landa_map", default=None) is None): print("you have to give at least 1 map from runoff or landa !") else: if (runoff_landa.get("runoff_co_map", default=None) is not None) and ( runoff_landa.get("landa_map", default=None) is not None): runoff_coefficient_map_ascii = runoff_landa.get("runoff_co_map") self.landa_map = runoff_landa.get("landa_map") self.runoff_coefficient_map = map_loader.load_map(RunoffCoefficient, runoff_coefficient_map_ascii) runoff_coefficient_map = self.runoff_coefficient_map.map for i in range(len(self.runoff_coefficient_map.matrix)): self.output_hyrology.matrix.append([]) for j in range(len(self.runoff_coefficient_map.matrix[i])): if self.runoff_coefficient_map.matrix[i][j] != runoff_coefficient_map.no_data_value: self.output_hyrology.matrix[i].append( self.runoff_coefficient_map.matrix[i][j] + self.landa_map.matrix[i][j]) else: self.output_hyrology.matrix[i].append(runoff_coefficient_map.no_data_value) else: if runoff_landa.get("runoff_co_map", default=None) is not None: self.output_hyrology = self.runoff_coefficient_map if runoff_landa.get("landa_map", default=None) is not None: self.output_hyrology = self.landa_map return self.output_hyrology
def build_output_based_on_hydrolic(self, water_shell_map_ascii_name, rpt_file, link_col_name, limit_node, inp_file_name, limit=1, merge_nodes=None): # merge_nodes format: {1: [1,2,3], 2: [5], 6: [6]} sub_dic = self.build_sub_dicts_by_inp_file(inp_file_name, limit_node, merge_nodes) data_list = self.hydrolic(rpt_file, link_col_name, limit_node, limit, sub_dic) for i in range(len(data_list)): data_list[i] = int(data_list[i]) water_shed_map = map_loader.load_map(WaterShellMap, water_shell_map_ascii_name) water_shed_m = water_shed_map.map self.output_for_watershell = Map() self.output_for_watershell.set_config(water_shed_m) self.build_basic_output_for_watershell() for i in range(len(water_shed_m.matrix)): for j in range(len(water_shed_m.matrix[i])): pixel = water_shed_m.matrix[i][j] if pixel == water_shed_m.no_data_value: continue if pixel in data_list: #print("pixel in data list:", pixel) self.output_for_watershell.matrix[i][j] = 1 else: self.output_for_watershell.matrix[i][j] = 0 return self.output_for_watershell
def build_map_from_ascii(self, ascii_file): map = Map() map.n_cols = int(ascii_file.readline().replace('ncols', '').replace('\n', '')) map.n_rows = int(ascii_file.readline().replace('nrows', '').replace('\n', '')) map.xll_corner = float(ascii_file.readline().replace('xllcorner', '').replace( '\n', '')) map.yll_corner = float(ascii_file.readline().replace('yllcorner', '').replace( '\n', '')) map.cell_size = int(ascii_file.readline().replace('cellsize', '').replace( '\n', '')) map.no_data_value = int(ascii_file.readline().replace( 'NODATA_value', '').replace('\n', '')) # map.matrix = [] for i in range(map.n_rows): line_str = ascii_file.readline() line_list = line_str.split(' ') line_list = line_list[:len(line_list) - 1] for j in range(len(line_list)): line_list[j] = float(line_list[j]) if len(line_list) > map.n_cols: line_list = line_list[:map.n_cols] elif len(line_list) < map.n_cols: for j in range(map.n_cols - len(line_list)): line_list.append(map.no_data_value) map.matrix.append(line_list) return map
def main(): print 'Creating an "abstract" map...' m = Map() i = m.iterator() while i.hasNext(): print i.getNext() print 'Creating a dict map...' m = DictMap() m.add(1, 'hello') m.add(2, 'goodbye') i = m.iterator() while i.hasNext(): print i.getNext() print 'Creating a wacky map...' m = WackyMap() m.add(1, 'hello') m.add(2, 'goodbye') print 'iterating forwards...' i = m.iterator() while i.hasNext(): print i.getNext() print 'iterating backwards...' i = m.reverseIterator() while i.hasNext(): print i.getNext()
def load_data(self): root_folder = path.dirname(__file__) img_folder = path.join(root_folder, "images") fx_folder = path.join(root_folder, "sound") self.all_sprites = pygame.sprite.Group() self.walls = pygame.sprite.Group() self.fruits = pygame.sprite.Group() # MAPS WITHOUT COLLISION self.map = Map() self.map.load_from_file(MAP) self.map.create_sprites_from_map_data(self) # Load images self.head_image = pygame.image.load(path.join( IMG_FOLDER, SNAKE_HEAD)).convert_alpha() self.body_image = pygame.image.load(path.join( IMG_FOLDER, SNAKE_BODY)).convert_alpha() self.fruit_image = pygame.image.load(path.join(IMG_FOLDER, FRUIT)).convert_alpha() # self.wally_image = pygame.image.load( # path.join(IMG_FOLDER, WALL)).convert_alpha() # Load FX self.music = pygame.mixer.music.load( path.join(FX_FOLDER, BACKGROUND_MUSIC))
def test_list_maps(self): new_map = Map('xdps0') list_of_maps = new_map.list_maps() list_of_maps_top = list_of_maps[0] self.assertTrue(isinstance(list_of_maps_top, tuple)) self.assertEqual(2, len(list_of_maps_top)) self.assertTrue(isinstance(list_of_maps_top[0], str)) self.assertTrue(isinstance(list_of_maps_top[1], str))
def test_list_all(self): #Arrange m = Map("mappy", "somefilepath") n = Map("flappy", "anotherfilepath") mStore = MapStore() mStore.add(m) mStore.add(n) #Act and Assert listy = [] for i in mStore.list_all(): listy.append(mStore.get(i)) self.assertIn(m, listy) self.assertIn(n, listy)
def loadmaps(self): f = open('data/justrightmaps.yaml', 'r') dirtymaps = yaml.load(f, Loader=yaml.FullLoader)['Maps'] pprint(dirtymaps) f.close() self.maps = {} for M in dirtymaps: MP = Map(M, dirtymaps[M]) self.maps[M] = MP
def test_add_success(self): # Arrange mp = Map("Test map", "") store = MapStore() # Act store.add(mp) # Assert self.assertEqual(store.get("Test map"), mp)
def test_add_map_exception(self): #Arrange m = Map("mappy", "somefilepath") mStore = MapStore() mStore.add(m) #Act and Assert with self.assertRaises(Exception): mStore.add(m)
def test_get_success(self): # Arrange mp = Map("Test map", "") store = MapStore() store.add(mp) # Act act = store.get("Test map") # Assert self.assertEqual(act, mp)
def main(screen): init_curses(screen) game_map = Map("map1") player = Player(game_map) textures = ["wall1", "wall2", "dragon", "tree"] Controller(Renderer(screen, player, textures)).start() curses.flushinp() curses.endwin()
def test_remove_success(self): # Arrange mp = Map("Test map", "") store = MapStore() store.add(mp) # Act store.remove(mp) # Assert self.assertEqual(store.list_all(), [])
def game_update(self, data, *args): """ Update """ self.update_count += 1 if not self.map: self.map = Map(data, self.player_index) return self.map.update(data) # Source. largest_army = self.map.get_largest_owned_army() source = largest_army # Destination. dest = None if (self.map.general_tiles): dest = self.map.get_closest_enemy_general_tile(largest_army) elif (self.map.enemy_tiles): dest = self.map.get_closest_enemy_tile(largest_army) elif (self.map.empty_tiles): dest = self.map.get_closest_empty_tile(largest_army) # Next attack. path = self.map.construct_path(largest_army, dest) attack_dest = None if path: attack_dest = path[0] # Send attack command. self.attack(self.map.coord_to_index(source, self.map.width), self.map.coord_to_index(attack_dest, self.map.width), False) #Print to console. self.map.print_everything() if path: print("Moving from " + str(source) + " to " + str(attack_dest) + " towards " + str(dest)) else: print("Moving from " + str(source) + " towards " + str(dest)) print("Path: " + str(path)) print("Generals: " + str(self.map.generals)) # Log to file. self.file.write("Turn " + str(self.update_count) + "\n") if path: self.file.write("Path: " + str(path)) self.file.write("Source: " + str(source) + ", To: " + str(attack_dest) + "\n") self.file.write("Moving toward: " + str(dest) + "\n") else: self.file.write("THERE ARE NO PATH PLEASE TAKE A LOOK") self.file.write("Source: " + str(source) + ", Dest: " + str(dest) + "\n") self.file.write("\n-------------------\n")
class CONSTANTS(object): """ docstring """ VERSION = "0.1.0-alpha" DEFAULT_CONFIG = Map({ "mods": { "disabled": "Tweaks" }, "modules": ["cfg", "constants", "map"] }) AUTHOR = Map({ "DISCORD": { "USERNAME": "******", "DISCRIM": "6452" }, "GITHUB": { "USERNAME": "******", "URL": "https://github.com/Aeryle" }, })
def __init__(self): self._running = None self._surface = None self._size = self.weight, self.height = 812, 650 self._map = Map(50, (10, 10)) self._player_turn = None self._image_library = None self._action = None self._marked = None self._lost = None pos_x, pos_y = self.get_start_position() self._hero = Hero(10, 5, 10, 10, 200, pos_x, pos_y)
def test_get_fail(self): # Arrange mp = Map("Test map", "") store = MapStore() errorText = 'Map does not exist in store' # Act try: store.get(mp) # Assert except Exception as ex: self.assertEqual(str(ex), errorText)
def test_add_fail(self): # Arrange mp = Map("Test map", "") store = MapStore() errorText = 'Map already exists in store' # Act try: store.add(mp) store.add(mp) # Assert except Exception as ex: self.assertEqual(str(ex), errorText)
def enter(): global boy global map global items, font global line global background open_canvas() boy = Boy() map = [Map() for i in range(0, 25)] items = Item() background = backgroundsound() line = 4 font = load_font('ENCR10B.TTF', 30)
def generate_map(cls, taken_spaces_map, room_positions, height, width): res = Map(height, width) for coordinates, room in room_positions: MapGen.place_room(res, room, coordinates) for x, line in enumerate(taken_spaces_map): for y, space_type in enumerate(line): if space_type == 3: res.tile_map[x][y].terrain = ASSETS.get_asset( 'tiles', 'base_floor') elif space_type in [0, 2, 4]: res.tile_map[x][y].terrain = ASSETS.get_asset( 'tiles', 'base_wall') res.reload_fov_map() return res
def reset(self): # Map self.player_score = 0 level_path = path.dirname(path.realpath("resources")) self.map = Map(self.screen, self.game_settings, path.join(level_path, self.level)) self.cur_zone_coords = self.map.spawnpoint self.cur_zone = self.map.zones[self.cur_zone_coords[0]][ self.cur_zone_coords[1]] self.spawn = self.map.zones[self.map.spawnpoint[0]][ self.map.spawnpoint[1]] self.player = Player(self.screen, self.game_settings, self.spawn.leftspawn[0], self.spawn.leftspawn[1]) self.ui = UI(self.screen, self.player)