2022-03-11 03:02:29 +01:00
|
|
|
import pygame
|
|
|
|
import settings
|
|
|
|
|
|
|
|
|
|
|
|
class Instance:
|
2022-05-10 20:06:15 +02:00
|
|
|
def __init__(self, tank_capacity, direction, seeds, feritizer, water, carrots, potatoes, wheat):
|
2022-03-11 03:02:29 +01:00
|
|
|
size = settings.Field.size
|
|
|
|
self.rect = pygame.Rect(0, 0, size(), size())
|
|
|
|
self.action = ''
|
2022-03-24 15:13:59 +01:00
|
|
|
self.tank_capacity = tank_capacity
|
2022-04-12 14:47:30 +02:00
|
|
|
self.direction = direction
|
2022-05-10 20:06:15 +02:00
|
|
|
self.seeds = seeds
|
|
|
|
self.feritizer = feritizer
|
|
|
|
self.water = water
|
|
|
|
self.carrots = carrots
|
|
|
|
self.potatoes = potatoes
|
|
|
|
self.wheat = wheat
|
2022-03-11 03:02:29 +01:00
|
|
|
|
2022-03-11 03:34:20 +01:00
|
|
|
def coordinates(self):
|
2022-03-11 03:02:29 +01:00
|
|
|
return {
|
|
|
|
'x': self.x(),
|
|
|
|
'y': self.y()
|
|
|
|
}
|
|
|
|
|
|
|
|
def x(self):
|
|
|
|
return int(self.rect.x / settings.Field.size())
|
|
|
|
|
|
|
|
def y(self):
|
|
|
|
return int(self.rect.y / settings.Field.size())
|
2022-04-12 14:47:30 +02:00
|
|
|
|
2022-03-24 15:13:59 +01:00
|
|
|
def get_tank_capacity(self):
|
|
|
|
return self.tank_capacity
|
2022-03-11 03:02:29 +01:00
|
|
|
|
2022-03-24 15:13:59 +01:00
|
|
|
def set_tank_capacity(self, fuel_units):
|
|
|
|
self.tank_capacity = fuel_units
|
2022-04-12 14:47:30 +02:00
|
|
|
|
2022-05-10 20:06:15 +02:00
|
|
|
def get_direction(self):
|
|
|
|
return self.direction
|
|
|
|
|
|
|
|
def set_direction(self, direction):
|
|
|
|
self.direction = direction
|
|
|
|
|
|
|
|
def get_seeds(self):
|
|
|
|
return self.seeds
|
|
|
|
|
|
|
|
def set_seeds(self, seeds):
|
|
|
|
self.seeds = seeds
|
|
|
|
|
|
|
|
def get_feritizer(self):
|
|
|
|
return self.feritizer
|
|
|
|
|
|
|
|
def set_feritizer(self, feritizer):
|
|
|
|
self.feritizer = feritizer
|
|
|
|
|
|
|
|
def get_water(self):
|
|
|
|
return self.water
|
|
|
|
|
|
|
|
def set_water(self, water):
|
|
|
|
self.water = water
|
|
|
|
|
|
|
|
def get_carrots(self):
|
|
|
|
return self.carrots
|
|
|
|
|
|
|
|
def set_carrots(self, carrots):
|
|
|
|
self.carrots = carrots
|
|
|
|
|
|
|
|
def get_potatoes(self):
|
|
|
|
return self.potatoes
|
|
|
|
|
|
|
|
def set_potatoes(self, potatoes):
|
|
|
|
self.potatoes = potatoes
|
|
|
|
|
|
|
|
def get_wheat(self):
|
|
|
|
return self.wheat
|
|
|
|
|
|
|
|
def set_wheat(self, wheat):
|
|
|
|
self.wheat = wheat
|
|
|
|
|
2022-04-28 09:21:32 +02:00
|
|
|
def move(self, action):
|
2022-03-11 03:02:29 +01:00
|
|
|
key_pressed = pygame.key.get_pressed()
|
|
|
|
height = settings.Pygame.height()
|
|
|
|
width = settings.Pygame.width()
|
|
|
|
tile_size = settings.Field.size()
|
|
|
|
|
2022-04-28 09:21:32 +02:00
|
|
|
if key_pressed[pygame.K_UP] and self.direction == 4 and self.rect.x > 0 and action is None:
|
2022-03-11 03:02:29 +01:00
|
|
|
self.rect.x -= tile_size
|
2022-04-28 09:21:32 +02:00
|
|
|
elif key_pressed[pygame.K_UP] and self.direction == 2 and self.rect.x < width - tile_size and action is None:
|
2022-03-11 03:02:29 +01:00
|
|
|
self.rect.x += tile_size
|
2022-04-28 09:21:32 +02:00
|
|
|
elif key_pressed[pygame.K_UP] and self.direction == 1 and self.rect.y > 0 and action is None:
|
2022-03-11 03:02:29 +01:00
|
|
|
self.rect.y -= tile_size
|
2022-04-28 09:21:32 +02:00
|
|
|
elif key_pressed[pygame.K_UP] and self.direction == 3 and self.rect.y < height - tile_size and action is None:
|
|
|
|
self.rect.y += tile_size
|
|
|
|
elif action == 'f' and self.direction == 4 and self.rect.x > 0:
|
|
|
|
self.rect.x -= tile_size
|
|
|
|
elif action == 'f' and self.direction == 2 and self.rect.x < width - tile_size:
|
|
|
|
self.rect.x += tile_size
|
|
|
|
elif action == 'f' and self.direction == 1 and self.rect.y > 0:
|
|
|
|
self.rect.y -= tile_size
|
|
|
|
elif action == 'f' and self.direction == 3 and self.rect.y < height - tile_size:
|
2022-03-11 03:02:29 +01:00
|
|
|
self.rect.y += tile_size
|
|
|
|
elif key_pressed[pygame.K_SPACE]:
|
2022-03-11 03:34:20 +01:00
|
|
|
return 'open_window'
|
|
|
|
return 'none'
|
2022-04-12 14:47:30 +02:00
|
|
|
|
2022-04-28 09:21:32 +02:00
|
|
|
def rotate(self, action):
|
2022-04-12 14:47:30 +02:00
|
|
|
key_pressed = pygame.key.get_pressed()
|
2022-04-28 09:21:32 +02:00
|
|
|
if key_pressed[pygame.K_LEFT] and self.direction == 2 or action == 'l' and self.direction == 2:
|
|
|
|
self.direction = 1
|
|
|
|
elif key_pressed[pygame.K_LEFT] and self.direction == 1 or action == 'l' and self.direction == 1:
|
|
|
|
self.direction = 4
|
|
|
|
elif key_pressed[pygame.K_LEFT] and self.direction == 4 or action == 'l' and self.direction == 4:
|
|
|
|
self.direction = 3
|
|
|
|
elif key_pressed[pygame.K_LEFT] and self.direction == 3 or action == 'l' and self.direction == 3:
|
|
|
|
self.direction = 2
|
|
|
|
elif key_pressed[pygame.K_RIGHT] and self.direction == 1 or action == 'r' and self.direction == 1:
|
|
|
|
self.direction = 2
|
|
|
|
elif key_pressed[pygame.K_RIGHT] and self.direction == 4 or action == 'r' and self.direction == 4:
|
|
|
|
self.direction = 1
|
|
|
|
elif key_pressed[pygame.K_RIGHT] and self.direction == 3 or action == 'r' and self.direction == 3:
|
|
|
|
self.direction = 4
|
|
|
|
elif key_pressed[pygame.K_RIGHT] and self.direction == 2 or action == 'r' and self.direction == 2:
|
|
|
|
self.direction = 3
|
2022-04-12 14:47:30 +02:00
|
|
|
return 'none'
|