capture weeds
This commit is contained in:
parent
7351c59ab7
commit
3d3781de15
8
board.py
8
board.py
@ -41,5 +41,11 @@ class Board:
|
|||||||
else:
|
else:
|
||||||
win.blit(self.dirt, cube_rect)
|
win.blit(self.dirt, cube_rect)
|
||||||
|
|
||||||
def is_rock(self, col, row):
|
def is_rock(self, row, col):
|
||||||
return self.board[row][col] == 0
|
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
|
52
main.py
52
main.py
@ -25,18 +25,46 @@ def main():
|
|||||||
run = False
|
run = False
|
||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_UP] and tractor.row > 0 and not board.is_rock(tractor.row-1, tractor.col):
|
|
||||||
tractor.row -= 1
|
if keys[pygame.K_UP] and tractor.row > 0 :
|
||||||
tractor.direction = "up"
|
if board.is_weed(tractor.col, tractor.row - 1):
|
||||||
if keys[pygame.K_DOWN] and tractor.row < rows-1 and not board.is_rock(tractor.row+1,tractor.col):
|
board.set_grass(tractor.col, tractor.row - 1)
|
||||||
tractor.row += 1
|
tractor.row -= 1
|
||||||
tractor.direction = "down"
|
tractor.direction = "up"
|
||||||
if keys[pygame.K_LEFT] and tractor.col > 0 and not board.is_rock(tractor.row,tractor.col-1):
|
elif not board.is_rock(tractor.col, tractor.row - 1):
|
||||||
tractor.col -= 1
|
tractor.row -= 1
|
||||||
tractor.direction = "left"
|
tractor.direction = "up"
|
||||||
if keys[pygame.K_RIGHT] and tractor.col < cols -1 and not board.is_rock(tractor.row,tractor.col+1):
|
|
||||||
tractor.col += 1
|
|
||||||
tractor.direction = "right"
|
|
||||||
|
if keys[pygame.K_DOWN] and tractor.row < rows-1 :
|
||||||
|
if board.is_weed(tractor.col, tractor.row + 1):
|
||||||
|
board.set_grass(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"
|
||||||
|
|
||||||
|
|
||||||
|
if keys[pygame.K_LEFT] and tractor.col > 0:
|
||||||
|
if board.is_weed(tractor.col - 1, tractor.row):
|
||||||
|
board.set_grass(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"
|
||||||
|
|
||||||
|
|
||||||
|
if keys[pygame.K_RIGHT] and tractor.col < cols - 1:
|
||||||
|
if board.is_weed(tractor.col + 1, tractor.row):
|
||||||
|
board.set_grass(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"
|
||||||
|
|
||||||
board.draw_cubes(WIN)
|
board.draw_cubes(WIN)
|
||||||
tractor.draw(WIN)
|
tractor.draw(WIN)
|
||||||
|
Loading…
Reference in New Issue
Block a user