Wersja z problemem generowania prostokatnych map

This commit is contained in:
Konrad Pierzyński 2019-04-01 14:07:27 +02:00
parent e7bede9f5f
commit 7cf49721a5
8 changed files with 16 additions and 15 deletions

View File

@ -2,5 +2,4 @@ from DataModels.Cell import Cell
class GC( Cell ):
def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0):
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue )
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue )

View File

@ -1,6 +1,7 @@
6 5
1 0
Y R R R E H
E R E R R R
H R B R H R
E R R R R G
E H E E R H
E H E E R H

View File

@ -1,5 +1,6 @@
13 4
3 0
E Y R R R H H R R R E E E
H R R H R R R R H R R H E
E E R E H E R H R E R R G
H R R E E B R R R H E R H
H R R E E B R R R H E R H

View File

@ -1,4 +1,5 @@
12 10
1 0
Y R R R E H R R R R R E
E R E R R E R E H E R H
H R R H R R R R R R R E

Binary file not shown.

View File

@ -4,7 +4,9 @@ CELL_SIZE = 64
FPS = 60
map = open( sys.argv[1], 'r' )
GRID_WIDTH, GRID_HEIGHT, GC_X, GC_Y = [int(x) for x in map.readline(2).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()]
WINDOW_HEIGHT = GRID_HEIGHT * CELL_SIZE
WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE

17
main.py
View File

@ -1,7 +1,7 @@
import pygame, sys
from random import randint
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
from DataModels.Grass import Grass
from DataModels.House import House
@ -12,10 +12,11 @@ from DataModels.GC import GC
pygame_sprites = pygame.sprite.Group()
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.readline()
map.readline()
map_objects = [ [ None for y in range(0,GRID_WIDTH)] for x in range(0, GRID_HEIGHT)]
@ -33,8 +34,9 @@ def generate( letter ):
i = 0
for y in map.readlines():
for x in y.split():
x_coord = i % GRID_WIDTH
y_coord = i // GRID_WIDTH
y_coord = i % GRID_WIDTH
x_coord = (i - y_coord)//GRID_WIDTH
yellow, green, blue = [randint(0, HOUSE_CAPACITY //2),randint(0, HOUSE_CAPACITY //2),randint(0, HOUSE_CAPACITY //2)]
if x is 'E':
@ -51,16 +53,11 @@ for y in map.readlines():
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
i += 1
print( GRID_WIDTH, GRID_HEIGHT )
print( map_objects )
for line in map_objects:
for item in line:
pygame_sprites.add(item)
pygame_sprites.add( GC(0,0,2) )
pygame_sprites.add( GC(GC_X, GC_Y, 2) )
while True: