Added saving to file
This commit is contained in:
parent
36ff47fe3d
commit
7664888597
@ -1,8 +1,9 @@
|
||||
import random, datetime
|
||||
|
||||
def GenerateMap():
|
||||
#generate random empty map
|
||||
width = random.randint(4,7) #up to 15
|
||||
height = random.randint(4,7) #up to 10
|
||||
width = random.randint(4,15) #up to 15
|
||||
height = random.randint(4,10) #up to 10
|
||||
grid = []
|
||||
|
||||
row = []
|
||||
@ -12,8 +13,8 @@ for i in range(height):
|
||||
grid.append(row.copy())
|
||||
|
||||
#define number of roads for each axis
|
||||
x_roads_count = random.randint(2, max(width//2.3,2))
|
||||
y_roads_count = random.randint(2, max(height//2.3,2))
|
||||
x_roads_count = random.randint(2, max(width//3,2))
|
||||
y_roads_count = random.randint(2, max(height//3,2))
|
||||
|
||||
#select coords of roads for x
|
||||
x_roads_coordinates = [] #output coords
|
||||
@ -73,10 +74,6 @@ intersections_to_leave_count = (len(intersections)//2) + 1
|
||||
for i in range(intersections_to_leave_count):
|
||||
intersections_to_modify.remove(random.choice(intersections_to_modify))
|
||||
|
||||
#remove joined roads number, we need coords
|
||||
#for i in intersections_to_modify:
|
||||
# i.pop()
|
||||
|
||||
print("Intersections: "+str(intersections))
|
||||
print("To modify: "+str(intersections_to_modify))
|
||||
|
||||
@ -174,3 +171,5 @@ for row in grid:
|
||||
map_file.write(" ".join(row)+"\n")
|
||||
map_file.close()
|
||||
print(name)
|
||||
|
||||
return(name)
|
@ -1,10 +1,17 @@
|
||||
import sys, random
|
||||
from MapGenerator import GenerateMap
|
||||
|
||||
CELL_SIZE = 64
|
||||
FPS = 60
|
||||
DELAY = 500
|
||||
|
||||
map = open( sys.argv[1], 'r' )
|
||||
try:
|
||||
MAP_NAME = sys.argv[1]
|
||||
except:
|
||||
MAP_NAME = GenerateMap()
|
||||
|
||||
|
||||
map = open( MAP_NAME, 'r' )
|
||||
|
||||
GRID_WIDTH, GRID_HEIGHT = [int(x) for x in map.readline().split()]
|
||||
GC_X, GC_Y = [int(x) for x in map.readline().split()]
|
||||
|
4
main.py
4
main.py
@ -3,7 +3,7 @@
|
||||
import pygame
|
||||
import sys
|
||||
from random import randint
|
||||
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
|
||||
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y, MAP_NAME
|
||||
|
||||
from PIL import Image,ImageDraw
|
||||
|
||||
@ -21,7 +21,7 @@ dump_count=0
|
||||
FPS_CLOCK = pygame.time.Clock()
|
||||
GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
||||
|
||||
map = open(sys.argv[1], 'r')
|
||||
map = open(MAP_NAME, 'r')
|
||||
map.readline()
|
||||
map.readline()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user