2024-03-10 02:46:14 +01:00
|
|
|
import pygame
|
|
|
|
from constant import size, rows, cols
|
2024-03-24 19:28:14 +01:00
|
|
|
import random
|
2024-03-10 02:46:14 +01:00
|
|
|
|
|
|
|
class Board:
|
|
|
|
def __init__(self):
|
|
|
|
self.board = []
|
2024-03-24 19:28:14 +01:00
|
|
|
self.load_images()
|
|
|
|
self.generate_board()
|
2024-03-10 02:46:14 +01:00
|
|
|
|
|
|
|
def load_images(self):
|
2024-03-24 19:28:14 +01:00
|
|
|
self.grass = pygame.image.load("board/grass.png")
|
|
|
|
self.dirt = pygame.image.load("board/dirt.png")
|
2024-05-18 17:10:56 +02:00
|
|
|
self.rock = pygame.image.load("board/rock.png")
|
|
|
|
self.weeds = pygame.image.load("board/weeds.png")
|
2024-03-24 20:54:05 +01:00
|
|
|
self.soil = pygame.image.load("board/zyzna.png")
|
2024-03-24 19:28:14 +01:00
|
|
|
|
|
|
|
def generate_board(self):
|
2024-05-18 17:10:56 +02:00
|
|
|
self.board = [[random.choice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) for _ in range(cols)] for _ in range(rows)]
|
2024-03-10 02:46:14 +01:00
|
|
|
|
|
|
|
def draw_cubes(self, win):
|
|
|
|
for row in range(rows):
|
|
|
|
for col in range(cols):
|
2024-05-18 17:10:56 +02:00
|
|
|
cube_rect = pygame.Rect(col * size, row * size, size, size)
|
|
|
|
cube = self.board[row][col]
|
|
|
|
if row == 4 and col == 4:
|
2024-03-10 02:46:14 +01:00
|
|
|
win.blit(self.grass, cube_rect)
|
2024-03-24 19:28:14 +01:00
|
|
|
elif cube == 0:
|
|
|
|
rock_scale = pygame.transform.scale(self.rock, (size, size))
|
2024-03-10 02:46:14 +01:00
|
|
|
win.blit(self.dirt, cube_rect)
|
2024-05-18 17:10:56 +02:00
|
|
|
win.blit(rock_scale, cube_rect)
|
2024-03-24 19:28:14 +01:00
|
|
|
elif cube == 1:
|
2024-05-18 17:10:56 +02:00
|
|
|
weed_scale = pygame.transform.scale(self.weeds, (size, size))
|
2024-03-24 19:28:14 +01:00
|
|
|
win.blit(self.grass, cube_rect)
|
|
|
|
win.blit(weed_scale, cube_rect)
|
2024-05-18 17:10:56 +02:00
|
|
|
elif cube in (2, 3, 4, 5):
|
|
|
|
win.blit(self.grass, cube_rect)
|
2024-03-24 20:54:05 +01:00
|
|
|
elif cube == 10:
|
|
|
|
win.blit(self.soil, cube_rect)
|
2024-03-24 19:28:14 +01:00
|
|
|
else:
|
2024-05-18 17:10:56 +02:00
|
|
|
win.blit(self.dirt, cube_rect)
|
2024-03-10 02:46:14 +01:00
|
|
|
|
2024-03-24 19:49:08 +01:00
|
|
|
def is_rock(self, row, col):
|
|
|
|
return self.board[row][col] == 0
|
|
|
|
|
2024-05-18 17:10:56 +02:00
|
|
|
def is_weed(self, row, col):
|
2024-03-24 19:49:08 +01:00
|
|
|
return self.board[row][col] == 1
|
|
|
|
|
2024-05-18 17:10:56 +02:00
|
|
|
def set_grass(self, row, col):
|
|
|
|
self.board[row][col] = 2
|
2024-03-24 20:54:05 +01:00
|
|
|
|
2024-05-18 17:10:56 +02:00
|
|
|
def is_dirt(self, row, col):
|
|
|
|
return self.board[row][col] in (6, 7, 8, 9)
|
2024-03-24 20:54:05 +01:00
|
|
|
|
|
|
|
def set_soil(self, row, col):
|
2024-05-18 17:10:56 +02:00
|
|
|
self.board[row][col] = 10
|