2020-05-03 16:59:29 +02:00
|
|
|
from pygame.locals import *
|
|
|
|
import pygame
|
|
|
|
|
|
|
|
class tractor():
|
|
|
|
def __init__(self,field):
|
|
|
|
self.field = field
|
|
|
|
self.moves = 0
|
|
|
|
self.turn = 0
|
|
|
|
self.modes = ["Nawadnianie", "Odchwaszczanie", "Sadzenie", "Zbiory"]
|
|
|
|
self.mode_value = 0
|
|
|
|
self.poz = [0,0]
|
|
|
|
self.poz_on_screen = [75,75]
|
|
|
|
|
|
|
|
def get_field_value(self):
|
|
|
|
return self.field.get_value(self.poz)
|
|
|
|
|
|
|
|
def get_moves(self):
|
|
|
|
return self.moves
|
|
|
|
|
|
|
|
def moves_up(self):
|
|
|
|
self.moves += 1
|
|
|
|
|
|
|
|
def set_mode(self,value):
|
|
|
|
self.mode_value = value
|
|
|
|
print("Tryb: " + str(self.modes[self.mode_value]))
|
|
|
|
|
|
|
|
def get_mode(self):
|
|
|
|
return self.mode_value
|
|
|
|
|
2020-05-07 18:42:40 +02:00
|
|
|
def get_modes_values(self):
|
|
|
|
if self.mode_value == 0:
|
|
|
|
return [0, 1, 2, 3]
|
|
|
|
elif self.mode_value == 1:
|
|
|
|
return [1, 3, 5, 7]
|
|
|
|
elif self.mode_value == 2:
|
|
|
|
return [0, 1, 4, 5]
|
|
|
|
elif self.mode_value == 3:
|
|
|
|
return [8]
|
|
|
|
|
2020-05-03 16:59:29 +02:00
|
|
|
def get_mode_name(self):
|
|
|
|
return self.modes[self.mode_value]
|
|
|
|
|
|
|
|
def get_turn(self):
|
|
|
|
return self.turn
|
|
|
|
|
|
|
|
def set_turn(self, turn):
|
|
|
|
self.turn = turn
|
|
|
|
|
|
|
|
def get_poz(self):
|
|
|
|
return self.poz
|
|
|
|
|
|
|
|
def get_poz_on_screen(self):
|
|
|
|
return self.poz_on_screen
|
|
|
|
|
|
|
|
def set_poz(self,poz):
|
|
|
|
self.poz = [self.poz[0]+poz[0],self.poz[1]+poz[1]]
|
|
|
|
|
|
|
|
def set_poz_on_screen(self,poz):
|
|
|
|
self.poz_on_screen = [self.poz_on_screen[0]+poz[0],self.poz_on_screen[1]+poz[1]]
|
|
|
|
|
|
|
|
def move_left(self):
|
|
|
|
if self.poz[0] == 0:
|
2020-05-07 20:00:03 +02:00
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
else:
|
|
|
|
self.set_poz([-1,0])
|
|
|
|
self.set_poz_on_screen([-70,0])
|
|
|
|
print("Ruch w lewo")
|
|
|
|
self.set_turn(1)
|
|
|
|
self.moves_up()
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def move_up(self):
|
|
|
|
if self.poz[1] == 0:
|
2020-05-07 20:00:03 +02:00
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
else:
|
|
|
|
self.set_poz([0, -1])
|
|
|
|
self.set_poz_on_screen([0, -70])
|
|
|
|
print("Ruch w górę")
|
|
|
|
self.set_turn(2)
|
|
|
|
self.moves_up()
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def move_right(self):
|
|
|
|
if self.poz[0] == 9:
|
2020-05-07 20:00:03 +02:00
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
else:
|
|
|
|
self.set_poz([1, 0])
|
|
|
|
self.set_poz_on_screen([70, 0])
|
|
|
|
self.set_turn(3)
|
|
|
|
print("Ruch w prawo")
|
|
|
|
self.moves_up()
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def move_down(self):
|
|
|
|
if self.poz[1] == 9:
|
2020-05-07 20:00:03 +02:00
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
else:
|
|
|
|
self.set_poz([0, 1])
|
|
|
|
self.set_poz_on_screen([0, 70])
|
|
|
|
self.set_turn(0)
|
|
|
|
print("Ruch w dół")
|
|
|
|
self.moves_up()
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def work(self):
|
|
|
|
if self.get_mode() == 0:
|
2020-05-07 20:00:03 +02:00
|
|
|
return (self.water())
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
if self.get_mode() == 1:
|
2020-05-07 20:00:03 +02:00
|
|
|
return (self.weeds())
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
if self.get_mode() == 2:
|
2020-05-07 20:00:03 +02:00
|
|
|
return (self.plant())
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
if self.get_mode() == 3:
|
2020-05-07 20:00:03 +02:00
|
|
|
return (self.harvest())
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def water(self):
|
|
|
|
if self.field.get_value(self.poz) in [0, 1, 2, 3]:
|
2020-05-07 20:00:03 +02:00
|
|
|
print("Podlanie pola")
|
2020-05-03 16:59:29 +02:00
|
|
|
self.field.change_value(self.poz,4)
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def weeds(self):
|
|
|
|
if self.field.get_value(self.poz) in [1, 3, 5, 7]:
|
2020-05-07 20:00:03 +02:00
|
|
|
print("Odchwaszczenie pola")
|
2020-05-03 16:59:29 +02:00
|
|
|
self.field.change_value(self.poz,-1)
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def plant(self):
|
|
|
|
if self.field.get_value(self.poz) in [0, 1, 4, 5]:
|
2020-05-07 20:00:03 +02:00
|
|
|
print("Zasadzenie pola")
|
2020-05-03 16:59:29 +02:00
|
|
|
self.field.change_value(self.poz,2)
|
2020-05-07 20:00:03 +02:00
|
|
|
return 1
|
|
|
|
return 0
|
2020-05-03 16:59:29 +02:00
|
|
|
|
|
|
|
def harvest(self):
|
|
|
|
if self.field.get_value(self.poz) == 8:
|
2020-05-07 20:00:03 +02:00
|
|
|
self.field.change_value(self.poz,-8)
|
|
|
|
print("Zbiory z pola")
|
|
|
|
return 1
|
|
|
|
return 0
|