added plants #12
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
35
field.py
35
field.py
@ -1,6 +1,7 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
import pygame
|
import pygame
|
||||||
import settings
|
import settings
|
||||||
|
import plant
|
||||||
|
|
||||||
|
|
||||||
class Type(Enum):
|
class Type(Enum):
|
||||||
@ -17,6 +18,20 @@ class Type(Enum):
|
|||||||
}[_type]
|
}[_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:
|
class Object:
|
||||||
height = width = 0
|
height = width = 0
|
||||||
name = 'default'
|
name = 'default'
|
||||||
@ -29,7 +44,7 @@ class Object:
|
|||||||
return pygame.transform.scale(img, (self.width, self.height))
|
return pygame.transform.scale(img, (self.width, self.height))
|
||||||
|
|
||||||
|
|
||||||
class Tile(Object) :
|
class Tile(Object):
|
||||||
def __init__(self, name: str, _type: Type):
|
def __init__(self, name: str, _type: Type):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = _type
|
self.type = _type
|
||||||
@ -37,7 +52,7 @@ class Tile(Object) :
|
|||||||
self.object = self.create()
|
self.object = self.create()
|
||||||
|
|
||||||
|
|
||||||
class Block(Object) :
|
class Block(Object):
|
||||||
def __init__(self, name: str, _type: Type):
|
def __init__(self, name: str, _type: Type):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = _type
|
self.type = _type
|
||||||
@ -49,28 +64,33 @@ class Block(Object) :
|
|||||||
class Field:
|
class Field:
|
||||||
type = Type.DEFAULT
|
type = Type.DEFAULT
|
||||||
name = 'default'
|
name = 'default'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tile = Tile(self.name, self.type)
|
self.tile = Tile(self.name, self.type)
|
||||||
self.block = Block(self.name + "_block", 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):
|
class Dirt(Field):
|
||||||
type = Type.PLANT
|
type = Type.PLANT
|
||||||
name = 'dirt'
|
name = 'dirt'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Dirt, self).__init__()
|
super(Dirt, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
class Cobble(Field):
|
class Cobble(Field):
|
||||||
type = Type.SPECIAL
|
type = Type.SPECIAL
|
||||||
name = 'cobble'
|
name = 'cobble'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Cobble, self).__init__()
|
super(Cobble, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
class Grass(Field):
|
class Grass(Field):
|
||||||
type = Type.DEFAULT
|
type = Type.DEFAULT
|
||||||
name = 'grass'
|
name = 'grass'
|
||||||
@ -85,3 +105,4 @@ class Sand(Field):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Sand, self).__init__()
|
super(Sand, self).__init__()
|
||||||
|
# Tile Types END
|
1
main.py
1
main.py
@ -44,6 +44,7 @@ def read_img(agent, fields):
|
|||||||
window.blit(possibleFields['sand'].block.object, (0, 0))
|
window.blit(possibleFields['sand'].block.object, (0, 0))
|
||||||
elif current_field == possibleFields['cobble'].tile.object:
|
elif current_field == possibleFields['cobble'].tile.object:
|
||||||
window.blit(possibleFields['cobble'].block.object, (0, 0))
|
window.blit(possibleFields['cobble'].block.object, (0, 0))
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
pygame.time.delay(2000)
|
pygame.time.delay(2000)
|
||||||
common.set('state_imgShown', False)
|
common.set('state_imgShown', False)
|
||||||
|
108
plant.py
Normal file
108
plant.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class PlantGrowthStages(Enum):
|
||||||
|
PLANTED = 0
|
||||||
|
GROWING = 1
|
||||||
|
UNRIPE = 2
|
||||||
|
RIPE = 3
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def can_be_harvested(_type):
|
||||||
|
return _type == PlantGrowthStages.RIPE
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def next_growth_type(_type):
|
||||||
|
return {
|
||||||
|
PlantGrowthStages.PLANTED: PlantGrowthStages.GROWING,
|
||||||
|
PlantGrowthStages.GROWING: PlantGrowthStages.UNRIPE,
|
||||||
|
PlantGrowthStages.UNRIPE: PlantGrowthStages.RIPE,
|
||||||
|
PlantGrowthStages.RIPE: PlantGrowthStages.RIPE,
|
||||||
|
}[_type]
|
||||||
|
|
||||||
|
|
||||||
|
class Plant:
|
||||||
|
tick_decrease_amount: 1
|
||||||
|
tick_increase_amount: 1
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.growth = PlantGrowthStages.PLANTED
|
||||||
|
self.canBeHarvested = False
|
||||||
|
self.water_level = 0
|
||||||
|
self.fertilizer_level = 0
|
||||||
|
self.growth_stage_level = 0
|
||||||
|
self.growth_stage_threshold = 10000
|
||||||
|
|
||||||
|
def grow(self):
|
||||||
|
self.growth_stage_level = 0
|
||||||
|
previous_growth = self.growth
|
||||||
|
self.growth = PlantGrowthStages.next_growth_type(self.growth)
|
||||||
|
if self.growth == previous_growth:
|
||||||
|
self.canBeHarvested = True
|
||||||
|
|
||||||
|
def is_watered(self):
|
||||||
|
return self.water_level > 0
|
||||||
|
|
||||||
|
def water(self):
|
||||||
|
self.water_level = 100
|
||||||
|
|
||||||
|
def is_fertilized(self):
|
||||||
|
return self.fertilizer_level > 0
|
||||||
|
|
||||||
|
def fertilize(self):
|
||||||
|
self.fertilizer_level = 1000
|
||||||
|
|
||||||
|
def tick(self):
|
||||||
|
self.water_level -= self.tick_decrease_amount
|
||||||
|
self.fertilizer_level -= self.tick_decrease_amount
|
||||||
|
self.growth_stage_level += self.tick_increase_amount
|
||||||
|
if self.growth_stage_threshold == self.growth_stage_level:
|
||||||
|
self.grow()
|
||||||
|
|
||||||
|
def harvest(self):
|
||||||
|
if PlantGrowthStages.can_be_harvested(self.growth):
|
||||||
|
return self
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def sow(seed):
|
||||||
|
return {
|
||||||
|
PlantGrowthStages.PLANTED: PlantGrowthStages.GROWING,
|
||||||
|
PlantGrowthStages.GROWING: PlantGrowthStages.UNRIPE,
|
||||||
|
PlantGrowthStages.UNRIPE: PlantGrowthStages.RIPE,
|
||||||
|
PlantGrowthStages.RIPE: PlantGrowthStages.RIPE,
|
||||||
|
}[seed]
|
||||||
|
|
||||||
|
|
||||||
|
class Carrot(Plant):
|
||||||
|
def __init__(self):
|
||||||
|
super(Carrot, self).__init__()
|
||||||
|
self.growth_stage_threshold = 5000
|
||||||
|
|
||||||
|
|
||||||
|
class Potato(Plant):
|
||||||
|
def __init__(self):
|
||||||
|
super(Potato, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
|
class Wheat(Plant):
|
||||||
|
def __init__(self):
|
||||||
|
super(Wheat, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
|
class Seeds(Enum):
|
||||||
|
Carrot = 0
|
||||||
|
Potato = 1
|
||||||
|
Wheat = 2
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def seed_to_plant(seed):
|
||||||
|
return {
|
||||||
|
Seeds.Carrot: Carrot(),
|
||||||
|
Seeds.Potato: Potato(),
|
||||||
|
Seeds.Wheat: Wheat(),
|
||||||
|
}[seed]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user