60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import pygame
|
|
from constant import size, rows, cols
|
|
import random
|
|
|
|
|
|
class Board:
|
|
def __init__(self):
|
|
self.board = []
|
|
self.load_images()
|
|
self.generate_board()
|
|
|
|
|
|
def load_images(self):
|
|
self.grass = pygame.image.load("board/grass.png")
|
|
self.dirt = pygame.image.load("board/dirt.png")
|
|
self.rock= pygame.image.load("board/rock.png")
|
|
self.weeds = pygame.image.load("board/weeds.png")
|
|
self.soil = pygame.image.load("board/zyzna.png")
|
|
|
|
def generate_board(self):
|
|
self.board = [[random.choice([0,1,2,3,4,5,6,7,8,9]) for _ in range(rows)] for _ in range(cols)]
|
|
|
|
def draw_cubes(self, win):
|
|
|
|
for row in range(rows):
|
|
for col in range(cols):
|
|
cube_rect = pygame.Rect(row * size, col * size, size, size)
|
|
cube=self.board[row][col]
|
|
|
|
if row==4 and col==4:
|
|
win.blit(self.grass, cube_rect)
|
|
elif cube == 0:
|
|
rock_scale = pygame.transform.scale(self.rock, (size, size))
|
|
win.blit(self.dirt, cube_rect)
|
|
win.blit(rock_scale, cube_rect)
|
|
elif cube == 1:
|
|
weed_scale = pygame.transform.scale(self.weeds, (size,size))
|
|
win.blit(self.grass, cube_rect)
|
|
win.blit(weed_scale, cube_rect)
|
|
elif cube in(2,3,4,5):
|
|
win.blit(self.grass, cube_rect)
|
|
elif cube == 10:
|
|
win.blit(self.soil, cube_rect)
|
|
else:
|
|
win.blit(self.dirt, cube_rect)
|
|
|
|
def is_rock(self, row, col):
|
|
return self.board[row][col] == 0
|
|
|
|
def is_weed(self,row,col):
|
|
return self.board[row][col] == 1
|
|
|
|
def set_grass(self,row,col):
|
|
self.board[row][col]=2
|
|
|
|
def is_dirt(self,row,col):
|
|
return self.board[row][col] in (6,7,8,9)
|
|
|
|
def set_soil(self, row, col):
|
|
self.board[row][col] = 10 |