controlling fields with water and trees #16

Merged
s464981 merged 1 commits from field into master 2022-04-06 21:14:41 +02:00
2 changed files with 27 additions and 4 deletions
Showing only changes of commit 7286171207 - Show all commits

View File

@ -15,6 +15,8 @@ LEFT_KNIGHTS_SPAWN_FIRST_ROW = 6
LEFT_KNIGHTS_SPAWN_FIRST_COL = 0
RIGHT_KNIGHTS_SPAWN_FIRST_ROW = 6
RIGHT_KNIGHTS_SPAWN_FIRST_COL = 20
NBR_OF_WATER = 10
NBR_OF_TREES = 16
CASTLE_SPAWN_WIDTH = 6
CASTLE_SPAWN_HEIGHT = 5

View File

@ -1,9 +1,9 @@
import random
import numpy as np
import pygame
from common.constants import ROWS, COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, GRID_CELL_HEIGHT, BORDER_WIDTH, \
BORDER_RADIUS
BORDER_RADIUS, NBR_OF_TREES, NBR_OF_WATER
from .field import Field
@ -13,6 +13,22 @@ class Grid:
self.grid = []
self.free_fields = []
self.busy_fields = []
podkladka = np.zeros((ROWS, COLUMNS))
for drzewa in range(0, NBR_OF_TREES):
rzad = random.randint(0, ROWS-1)
kolumna = random.randint(0, COLUMNS-1)
if podkladka[rzad][kolumna] == 0:
podkladka[rzad][kolumna] = 1
else:
drzewa = drzewa - 1
for i in range(0, NBR_OF_WATER):
rzad = random.randint(0, ROWS-1)
kolumna = random.randint(0, COLUMNS-1)
if podkladka[rzad][kolumna] == 0:
podkladka[rzad][kolumna] = 2
else:
drzewa = drzewa - 1
print(podkladka)
for row in range(ROWS):
self.grid.append(pygame.sprite.Group())
for column in range(COLUMNS):
@ -20,7 +36,12 @@ class Grid:
(GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING + 7,
GRID_CELL_WIDTH,
GRID_CELL_HEIGHT]
texture_path, converted_texture = self.get_random_texture()
if podkladka[row][column] == 1:
texture_path, converted_texture = self.textures[-1]
elif podkladka[row][column] == 2:
texture_path, converted_texture = self.textures[-2]
else:
texture_path, converted_texture = self.get_random_texture()
field = Field(
texture_path,
converted_texture,
@ -42,7 +63,7 @@ class Grid:
self.draw(screen)
def get_random_texture(self):
texture_index = random.randint(0, len(self.textures) - 1)
texture_index = random.randint(0, len(self.textures) - 3)
return self.textures[texture_index]
def draw(self, screen):