144 lines
3.6 KiB
Python
144 lines
3.6 KiB
Python
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
|
|
|
|
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]
|
|
|
|
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:
|
|
return 0
|
|
else:
|
|
self.set_poz([-1,0])
|
|
self.set_poz_on_screen([-70,0])
|
|
print("Ruch w lewo")
|
|
self.set_turn(1)
|
|
self.moves_up()
|
|
return 1
|
|
|
|
def move_up(self):
|
|
if self.poz[1] == 0:
|
|
return 0
|
|
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()
|
|
return 1
|
|
|
|
def move_right(self):
|
|
if self.poz[0] == 9:
|
|
return 0
|
|
else:
|
|
self.set_poz([1, 0])
|
|
self.set_poz_on_screen([70, 0])
|
|
self.set_turn(3)
|
|
print("Ruch w prawo")
|
|
self.moves_up()
|
|
return 1
|
|
|
|
def move_down(self):
|
|
if self.poz[1] == 9:
|
|
return 0
|
|
else:
|
|
self.set_poz([0, 1])
|
|
self.set_poz_on_screen([0, 70])
|
|
self.set_turn(0)
|
|
print("Ruch w dół")
|
|
self.moves_up()
|
|
return 1
|
|
|
|
def work(self):
|
|
if self.get_mode() == 0:
|
|
return (self.water())
|
|
|
|
if self.get_mode() == 1:
|
|
return (self.weeds())
|
|
|
|
if self.get_mode() == 2:
|
|
return (self.plant())
|
|
|
|
if self.get_mode() == 3:
|
|
return (self.harvest())
|
|
|
|
def water(self):
|
|
if self.field.get_value(self.poz) in [0, 1, 2, 3]:
|
|
print("Podlanie pola")
|
|
self.field.change_value(self.poz,4)
|
|
return 1
|
|
return 0
|
|
|
|
def weeds(self):
|
|
if self.field.get_value(self.poz) in [1, 3, 5, 7]:
|
|
print("Odchwaszczenie pola")
|
|
self.field.change_value(self.poz,-1)
|
|
return 1
|
|
return 0
|
|
|
|
def plant(self):
|
|
if self.field.get_value(self.poz) in [0, 1, 4, 5]:
|
|
print("Zasadzenie pola")
|
|
self.field.change_value(self.poz,2)
|
|
return 1
|
|
return 0
|
|
|
|
def harvest(self):
|
|
if self.field.get_value(self.poz) == 8:
|
|
self.field.change_value(self.poz,-8)
|
|
print("Zbiory z pola")
|
|
return 1
|
|
return 0 |