SI_Traktor/tractor.py
2020-05-03 16:59:29 +02:00

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