This commit is contained in:
s464923 2024-03-24 20:54:05 +01:00
parent 3d3781de15
commit 92918cf21d
2 changed files with 26 additions and 1 deletions

View File

@ -15,6 +15,7 @@ class Board:
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)]
@ -38,6 +39,8 @@ class Board:
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)
@ -49,3 +52,9 @@ class Board:
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

16
main.py
View File

@ -31,6 +31,10 @@ def main():
board.set_grass(tractor.col, tractor.row - 1)
tractor.row -= 1
tractor.direction = "up"
elif board.is_dirt(tractor.col, tractor.row - 1):
board.set_soil(tractor.col, tractor.row - 1)
tractor.row -= 1
tractor.direction = "up"
elif not board.is_rock(tractor.col, tractor.row - 1):
tractor.row -= 1
tractor.direction = "up"
@ -42,6 +46,10 @@ def main():
board.set_grass(tractor.col, tractor.row + 1)
tractor.row += 1
tractor.direction = "down"
elif board.is_dirt(tractor.col, tractor.row + 1):
board.set_soil(tractor.col, tractor.row + 1)
tractor.row += 1
tractor.direction = "down"
elif not board.is_rock(tractor.col, tractor.row + 1):
tractor.row += 1
tractor.direction = "down"
@ -52,6 +60,10 @@ def main():
board.set_grass(tractor.col - 1, tractor.row)
tractor.col -= 1
tractor.direction = "left"
elif board.is_dirt(tractor.col - 1, tractor.row):
board.set_soil(tractor.col - 1, tractor.row)
tractor.col -= 1
tractor.direction = "left"
elif not board.is_rock(tractor.col - 1, tractor.row):
tractor.col -= 1
tractor.direction = "left"
@ -62,6 +74,10 @@ def main():
board.set_grass(tractor.col + 1, tractor.row)
tractor.col += 1
tractor.direction = "right"
elif board.is_dirt(tractor.col + 1, tractor.row):
board.set_soil(tractor.col + 1, tractor.row)
tractor.col += 1
tractor.direction = "right"
elif not board.is_rock(tractor.col + 1, tractor.row):
tractor.col += 1
tractor.direction = "right"