2019-04-01 14:10:14 +02:00
|
|
|
import pygame
|
|
|
|
import sys
|
2019-04-01 10:33:32 +02:00
|
|
|
|
2019-04-01 12:48:11 +02:00
|
|
|
from random import randint
|
2019-04-01 14:07:27 +02:00
|
|
|
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
|
2019-04-01 12:48:11 +02:00
|
|
|
|
|
|
|
from DataModels.Grass import Grass
|
|
|
|
from DataModels.House import House
|
|
|
|
from DataModels.Dump import Dump
|
2019-04-01 13:29:13 +02:00
|
|
|
from DataModels.Road import Road
|
|
|
|
from DataModels.GC import GC
|
2019-04-01 10:33:32 +02:00
|
|
|
|
|
|
|
pygame_sprites = pygame.sprite.Group()
|
|
|
|
|
|
|
|
FPS_CLOCK = pygame.time.Clock()
|
2019-04-01 12:48:11 +02:00
|
|
|
GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
|
|
|
|
|
|
|
map = open(sys.argv[1], 'r')
|
|
|
|
map.readline()
|
2019-04-01 14:07:27 +02:00
|
|
|
map.readline()
|
2019-04-01 12:48:11 +02:00
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
map_objects = [[None for y in range(0, GRID_WIDTH)]
|
|
|
|
for x in range(0, GRID_HEIGHT)]
|
2019-04-01 12:48:11 +02:00
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
|
|
|
|
def generate(letter):
|
|
|
|
key = 'D' if letter in ['B', 'G', 'Y'] else letter
|
2019-04-01 12:48:11 +02:00
|
|
|
letter_mapping = {
|
2019-04-01 14:10:14 +02:00
|
|
|
'E': lambda x, y: Grass(x, y),
|
|
|
|
'H': lambda x, y, max_rubbish, yellow, green, blue: House(x, y, max_rubbish, yellow, green, blue),
|
|
|
|
'D': lambda x, y, max_rubbish, dump_type: Dump(x, y, max_rubbish, dump_type),
|
|
|
|
'R': lambda x, y: Road(x, y)
|
2019-04-01 12:48:11 +02:00
|
|
|
}
|
2019-04-01 13:29:13 +02:00
|
|
|
|
|
|
|
return letter_mapping[key]
|
2019-04-01 12:48:11 +02:00
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
|
2019-04-01 12:48:11 +02:00
|
|
|
i = 0
|
|
|
|
for y in map.readlines():
|
|
|
|
for x in y.split():
|
2019-04-01 14:07:27 +02:00
|
|
|
|
2019-04-01 14:39:08 +02:00
|
|
|
x_coord = i % GRID_WIDTH
|
2019-04-01 14:32:24 +02:00
|
|
|
y_coord = (i-x_coord)//GRID_WIDTH
|
2019-04-01 13:29:13 +02:00
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
yellow, green, blue = [randint(0, HOUSE_CAPACITY // 2), randint(
|
|
|
|
0, HOUSE_CAPACITY // 2), randint(0, HOUSE_CAPACITY // 2)]
|
2019-04-01 12:48:11 +02:00
|
|
|
if x is 'E':
|
|
|
|
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
|
|
|
|
elif x is 'H':
|
2019-04-01 14:10:14 +02:00
|
|
|
map_objects[x_coord][y_coord] = generate(x)(
|
|
|
|
x_coord, y_coord, HOUSE_CAPACITY, yellow, green, blue)
|
2019-04-01 12:48:11 +02:00
|
|
|
elif x is 'B':
|
2019-04-01 14:10:14 +02:00
|
|
|
map_objects[x_coord][y_coord] = generate(
|
|
|
|
x)(x_coord, y_coord, 100, "Dump_Blue")
|
2019-04-01 13:29:13 +02:00
|
|
|
elif x is 'G':
|
2019-04-01 14:10:14 +02:00
|
|
|
map_objects[x_coord][y_coord] = generate(
|
|
|
|
x)(x_coord, y_coord, 100, "Dump_Green")
|
2019-04-01 13:29:13 +02:00
|
|
|
elif x is 'Y':
|
2019-04-01 14:10:14 +02:00
|
|
|
map_objects[x_coord][y_coord] = generate(
|
|
|
|
x)(x_coord, y_coord, 100, "Dump_Yellow")
|
2019-04-01 13:29:13 +02:00
|
|
|
elif x is 'R':
|
|
|
|
map_objects[x_coord][y_coord] = generate(x)(x_coord, y_coord)
|
2019-04-01 12:48:11 +02:00
|
|
|
i += 1
|
|
|
|
|
2019-04-01 13:29:13 +02:00
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
print(GRID_WIDTH, GRID_HEIGHT)
|
|
|
|
print(map_objects)
|
2019-04-01 13:29:13 +02:00
|
|
|
|
|
|
|
|
2019-04-01 12:48:11 +02:00
|
|
|
for line in map_objects:
|
|
|
|
for item in line:
|
|
|
|
pygame_sprites.add(item)
|
|
|
|
|
2019-04-01 14:36:27 +02:00
|
|
|
gc = GC(GC_X, GC_Y, 2)
|
|
|
|
print("GC: " + str(GC_X) + str(GC_Y))
|
|
|
|
pygame_sprites.add(gc)
|
2019-04-01 13:29:13 +02:00
|
|
|
|
2019-04-01 12:48:11 +02:00
|
|
|
while True:
|
|
|
|
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit()
|
2019-04-01 14:10:14 +02:00
|
|
|
elif event.type == pygame.KEYUP:
|
|
|
|
if event.key == pygame.K_UP:
|
|
|
|
gc.move("up", map_objects)
|
|
|
|
elif event.key == pygame.K_DOWN:
|
|
|
|
gc.move("down", map_objects)
|
|
|
|
elif event.key == pygame.K_LEFT:
|
|
|
|
gc.move("left", map_objects)
|
|
|
|
elif event.key == pygame.K_RIGHT:
|
|
|
|
gc.move("right", map_objects)
|
|
|
|
|
2019-04-01 12:48:11 +02:00
|
|
|
pygame_sprites.update()
|
|
|
|
pygame_sprites.draw(GAME_WINDOW)
|
2019-04-01 10:33:32 +02:00
|
|
|
|
2019-04-01 12:48:11 +02:00
|
|
|
pygame.display.flip()
|
2019-04-01 14:10:14 +02:00
|
|
|
FPS_CLOCK.tick(FPS)
|