SzybciorSmartTraktor/field.py
2022-05-10 20:06:15 +02:00

218 lines
4.3 KiB
Python

from enum import Enum
import pygame
import settings
import plant
class Type(Enum):
DEFAULT = 0
PLANT = 1
SPECIAL = 2
@staticmethod
def get_string(_type):
return {
Type.DEFAULT: 'default',
Type.PLANT: 'plant',
Type.SPECIAL: 'special',
}[_type]
# Field Types START
class FieldType:
def __init__(self):
self.field = None
self.plowed = False
def plow(self):
self.plowed = True
def sow(self, seed: plant.Seeds):
if self.plowed:
self.field = plant.Seeds.seed_to_plant(seed)
class Object:
height = width = 0
name = 'default'
type = Type.DEFAULT
def create(self):
field_string = Type.get_string(self.type)
img = pygame.image.load("./assets/fields/" + field_string + "/" + self.name + ".jpg")
return pygame.transform.scale(img, (self.width, self.height))
class Tile(Object):
def __init__(self, name: str, _type: Type):
self.name = name
self.type = _type
self.width = self.height = settings.Field.size()
self.object = self.create()
class Block(Object):
def __init__(self, name: str, _type: Type):
self.name = name
self.type = _type
self.width = settings.Pygame.width()
self.height = settings.Pygame.height()
self.object = self.create()
class Field:
type = Type.DEFAULT
name = 'default'
def __init__(self):
self.tile = Tile(self.name, self.type)
self.block = Block(self.name + "_block", self.type)
self.field_type = FieldType()
def can_be_sown(self):
return self.type == Type.DEFAULT
# Tile Types START
class Dirt(Field):
type = Type.PLANT
name = 'dirt'
cost = 5
def __init__(self):
super(Dirt, self).__init__()
class Carrot_empty(Field):
type = Type.PLANT
name = 'carrot_empty'
cost = 5
def __init__(self):
super(Carrot_empty, self).__init__()
class Carrot_sow(Field):
type = Type.PLANT
name = 'carrot_sow'
cost = 5
def __init__(self):
super(Carrot_sow, self).__init__()
class Carrot_watered(Field):
type = Type.PLANT
name = 'carrot_watered'
cost = 5
def __init__(self):
super(Carrot_watered, self).__init__()
class Carrot_feritized(Field):
type = Type.PLANT
name = 'carrot_feritized'
cost = 5
def __init__(self):
super(Carrot_feritized, self).__init__()
class Potato_empty(Field):
type = Type.PLANT
name = 'potato_empty'
cost = 5
def __init__(self):
super(Potato_empty, self).__init__()
class Potato_sow(Field):
type = Type.PLANT
name = 'potato_sow'
cost = 5
def __init__(self):
super(Potato_sow, self).__init__()
class Potato_watered(Field):
type = Type.PLANT
name = 'potato_watered'
cost = 5
def __init__(self):
super(Potato_watered, self).__init__()
class Potato_feritized(Field):
type = Type.PLANT
name = 'potato_feritized'
cost = 5
def __init__(self):
super(Potato_feritized, self).__init__()
class Wheat_empty(Field):
type = Type.PLANT
name = 'wheat_empty'
cost = 5
def __init__(self):
super(Wheat_empty, self).__init__()
class Wheat_sow(Field):
type = Type.PLANT
name = 'wheat_sow'
cost = 5
def __init__(self):
super(Wheat_sow, self).__init__()
class Wheat_watered(Field):
type = Type.PLANT
name = 'wheat_watered'
cost = 5
def __init__(self):
super(Wheat_watered, self).__init__()
class Wheat_feritized(Field):
type = Type.PLANT
name = 'wheat_feritized'
cost = 5
def __init__(self):
super(Wheat_feritized, self).__init__()
class Cobble(Field):
type = Type.SPECIAL
name = 'cobble'
cost = 1
def __init__(self):
super(Cobble, self).__init__()
class Grass(Field):
type = Type.DEFAULT
name = 'grass'
cost = 3
def __init__(self):
super(Grass, self).__init__()
class Sand(Field):
type = Type.DEFAULT
name = 'sand'
cost = 10
def __init__(self):
super(Sand, self).__init__()
class Station(Field):
type = Type.SPECIAL
name = 'station'
cost = 1
def __init__(self):
super(Station, self).__init__()
# Tile Types END