49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import pygame
|
|
from settings import Settings
|
|
from field import Field
|
|
|
|
settings = Settings()
|
|
|
|
|
|
def create_board(screen):
|
|
board = []
|
|
shelfs = [(250, 150), (250, 250), (450, 150), (450, 250), (650, 150), (650, 250), (850, 150), (850, 250),
|
|
(250, 450), (350, 450), (750, 450), (850, 450),
|
|
(250, 650), (250, 750), (450, 650), (450, 750), (650, 650), (650, 750), (850, 650), (850, 750)]
|
|
|
|
for y in range(settings.y_fields):
|
|
row = []
|
|
for x in range(settings.x_fields):
|
|
field = Field(screen, x, y, 50 + x * 100, 50 + y * 100, False, False, 1)
|
|
for shelf in shelfs:
|
|
if field.center_x == shelf[0] and field.center_y == shelf[1]:
|
|
field.is_shelf = True
|
|
field.image = pygame.image.load('img/shelf.png')
|
|
|
|
row.append(field)
|
|
board.append(row)
|
|
for row in board:
|
|
for field in row:
|
|
field.add_neighbors(board)
|
|
|
|
for row in board:
|
|
for field in row:
|
|
if field.x > 0 and board[field.y][field.x - 1].is_shelf:
|
|
field.cost_of_travel += 1
|
|
if field.x < 9 and board[field.y][field.x + 1].is_shelf:
|
|
field.cost_of_travel += 1
|
|
if field.y > 0 and board[field.y - 1][field.x].is_shelf:
|
|
field.cost_of_travel += 1
|
|
if field.y < 9 and board[field.y + 1][field.x].is_shelf:
|
|
field.cost_of_travel += 1
|
|
|
|
return board
|
|
|
|
|
|
def draw_board(board):
|
|
for row in board:
|
|
for field in row:
|
|
field.blitme()
|
|
|
|
|