def reset_map(self): if not self.keep_map: generate(self.fname, self.node_ranges, self.cost_range, self.objects_range, self.occurrences_range) self.map = load_map(self.fname) else: self.map = reset_distribution(self.fname, self.node_ranges, self.cost_range, self.objects_range, self.occurrences_range)
__author__ = 'dlpogue' import os import map import Player import roomDescriptions import random import sys Map = 0 mapList = map.generate() usrRandPos = random.randrange(0, 99, 1) userPos, endPos, mapList, dispList = map.userplace(usrRandPos, mapList) roomDescriptions.generate() descList = roomDescriptions.roomgenerator(mapList) #print(descList) map.display(dispList) while True: print chr(27) + "[2J" os.system('cls' if os.name == 'nt' else 'clear') if Map == 1: map.display(dispList) Map = 0 description, Choices = map.roomchoices(mapList, userPos) #print userPos #print descList[userPos-1] print descList[userPos] print " ".join(description) #print userPos usrChoice = Player.options(Choices) #print usrChoice if usrChoice == 'QUIT': sys.exit(0)
def generate_level(): level = MapGenerator(Globals.level_base).return_map() generate(level)
import sys import argparse from os.path import join, abspath, dirname sys.path.append(dirname(dirname(join(abspath(__file__))))) from map import generate NODES_RANGE = [8, 8] COST_RANGE = [10, 500] OBJECTS_RANGE = [4, 4] OCCURRENCES_RANGE = [1, 4] if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--map", help="path to the map file", type=str, default="maps/default.dat") fname = parser.parse_args().map generate(fname, NODES_RANGE, COST_RANGE, OBJECTS_RANGE, OCCURRENCES_RANGE)
while Globals.game_cycle: # Тут идёт загрузка и сохранение карты, а так же его элементов Wall((-25, 0)) Wall((Globals.WIDTH + 1, 0)) if new_level: generate_level() else: with open('data/map.txt', mode='r', encoding='utf8') as level: structure = level.read() if structure: structure = structure.split('\n') Globals.level_base = [] for y in range(len(structure) - 1): Globals.level_base.append( [int(element) for element in structure[y].split(' ')]) generate(Globals.level_base) else: generate_level() new_level = True with open('data/map.txt', mode='w', encoding='utf8') as level: result = '' for y in range(len(Globals.level_base)): row = [str(element) for element in Globals.level_base[y]] result += ' '.join( [str(element) for element in Globals.level_base[y]]) + '\n' level.write(result) Globals.level_base = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],