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