add carrot
This commit is contained in:
parent
8cdf6d8118
commit
9eb5029b38
BIN
board/carrot.png
Normal file
BIN
board/carrot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 232 KiB |
22
main.py
22
main.py
@ -5,8 +5,6 @@ from tractor import Tractor
|
||||
from kolejka import Stan, Kolejka, Odwiedzone
|
||||
|
||||
|
||||
|
||||
|
||||
fps = 5
|
||||
WIN = pygame.display.set_mode((width, height))
|
||||
|
||||
@ -24,8 +22,8 @@ def actions(elem, istate):
|
||||
while((elem.row != istate.row) or (elem.col != istate.col) or (elem.direction != istate.direction)):
|
||||
akcje.append(elem.a)
|
||||
elem = elem.p[0]
|
||||
|
||||
return akcje
|
||||
|
||||
def graphsearch(istate, goaltest, board):
|
||||
explored = Odwiedzone()
|
||||
fringe = Kolejka()
|
||||
@ -46,14 +44,14 @@ def graphsearch(istate, goaltest, board):
|
||||
def main():
|
||||
rotation = ["left", "up", "right", "down"]
|
||||
istate = Stan(4,4, "down")
|
||||
goaltest = Stan(1,1, "up")
|
||||
goaltest = Stan(2,3, "up")
|
||||
run = True
|
||||
clock = pygame.time.Clock()
|
||||
board = Board()
|
||||
board.load_images()
|
||||
actions = graphsearch(istate, goaltest, board)
|
||||
print("akcje: >",actions )
|
||||
tractor = Tractor(4, 4)
|
||||
tractor = Tractor(2, 3)
|
||||
while run:
|
||||
clock.tick(fps)
|
||||
|
||||
@ -64,6 +62,7 @@ def main():
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
if keys[pygame.K_UP]:
|
||||
if keys[pygame.K_UP]:
|
||||
if(tractor.direction == "up" and tractor.row > 0 ):
|
||||
if board.is_weed(tractor.col, tractor.row - 1):
|
||||
board.set_grass(tractor.col, tractor.row - 1)
|
||||
@ -71,8 +70,12 @@ def main():
|
||||
elif board.is_dirt(tractor.col, tractor.row - 1):
|
||||
board.set_soil(tractor.col, tractor.row - 1)
|
||||
tractor.row -= 1
|
||||
elif board.is_soil(tractor.col, tractor.row - 1):
|
||||
board.set_carrot(tractor.col, tractor.row - 1)
|
||||
tractor.row -= 1
|
||||
elif not board.is_rock(tractor.col, tractor.row - 1):
|
||||
tractor.row -= 1
|
||||
|
||||
if(tractor.direction == "left" and tractor.col > 0):
|
||||
if board.is_weed(tractor.col - 1, tractor.row):
|
||||
board.set_grass(tractor.col - 1, tractor.row)
|
||||
@ -80,6 +83,9 @@ def main():
|
||||
elif board.is_dirt(tractor.col - 1, tractor.row):
|
||||
board.set_soil(tractor.col - 1, tractor.row)
|
||||
tractor.col -= 1
|
||||
elif board.is_soil(tractor.col - 1, tractor.row):
|
||||
board.set_carrot(tractor.col - 1, tractor.row)
|
||||
tractor.col -= 1
|
||||
elif not board.is_rock(tractor.col - 1, tractor.row):
|
||||
tractor.col -= 1
|
||||
if(tractor.direction == "down" and tractor.row < rows - 1):
|
||||
@ -89,6 +95,9 @@ def main():
|
||||
elif board.is_dirt(tractor.col, tractor.row + 1):
|
||||
board.set_soil(tractor.col, tractor.row + 1)
|
||||
tractor.row += 1
|
||||
elif board.is_soil(tractor.col, tractor.row + 1):
|
||||
board.set_carrot(tractor.col, tractor.row + 1)
|
||||
tractor.row += 1
|
||||
elif not board.is_rock(tractor.col, tractor.row + 1):
|
||||
tractor.row += 1
|
||||
if(tractor.direction == "right" and tractor.col < cols - 1):
|
||||
@ -98,6 +107,9 @@ def main():
|
||||
elif board.is_dirt(tractor.col + 1, tractor.row):
|
||||
board.set_soil(tractor.col + 1, tractor.row)
|
||||
tractor.col += 1
|
||||
elif board.is_soil(tractor.col + 1, tractor.row ):
|
||||
board.set_carrot(tractor.col + 1, tractor.row )
|
||||
tractor.col += 1
|
||||
elif not board.is_rock(tractor.col + 1, tractor.row):
|
||||
tractor.col += 1
|
||||
if keys[pygame.K_LEFT]:
|
||||
|
Loading…
Reference in New Issue
Block a user