komentarze dla bambusków

This commit is contained in:
Tomasz Adamczyk 2021-04-03 11:24:39 +02:00
parent 30ccb27ab8
commit face109cb4
16 changed files with 57 additions and 51 deletions

View File

@ -3,6 +3,13 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment=""> <list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/definitions.py" beforeDir="false" afterPath="$PROJECT_DIR$/definitions.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/field.py" beforeDir="false" afterPath="$PROJECT_DIR$/field.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/map.py" beforeDir="false" afterPath="$PROJECT_DIR$/map.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/soil.py" beforeDir="false" afterPath="$PROJECT_DIR$/soil.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/station.py" beforeDir="false" afterPath="$PROJECT_DIR$/station.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/tractor.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/tractor.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -98,6 +105,7 @@
<workItem from="1617396071094" duration="3170000" /> <workItem from="1617396071094" duration="3170000" />
<workItem from="1617399305318" duration="2444000" /> <workItem from="1617399305318" duration="2444000" />
<workItem from="1617401891560" duration="232000" /> <workItem from="1617401891560" duration="232000" />
<workItem from="1617439271903" duration="2500000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -105,22 +113,22 @@
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1617402125132"> <state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1617441783230">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617402125132" /> <state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1617402125132"> <state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1617441783230">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617402125132" /> <state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1617402125132"> <state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1617441783230">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617402125132" /> <state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1617402125132"> <state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1617441783230">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617402125132" /> <state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617441783230" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1617385468328"> <state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1617385468328">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
@ -137,12 +145,12 @@
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468328" /> <state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1617385468328" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1617401891370"> <state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1617439275650">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617401891370" /> <state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1617439275650" />
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1617402000466" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1617441749283" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component> </component>
</project> </project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,4 @@
#definicje
import os import os
import pygame import pygame
BLOCK_SIZE = 60 BLOCK_SIZE = 60

View File

@ -1,5 +1,5 @@
class Field: class Field:
def __init__(self, plant, rect, soil): def __init__(self, plant, rect, soil): #składa się z rośliny oraz gleby, plus koordynaty danego pola
self.plant = plant self.plant = plant
self.rect = rect self.rect = rect
self.soil = soil self.soil = soil

8
map.py
View File

@ -5,12 +5,12 @@ import pygame
import soil import soil
class Map: class Map:
def __init__(self, fields): def __init__(self, fields):
self.fields = fields self.fields = fields #przechowuje wszystkie pola (Field)
def get_fields(self): def get_fields(self):
return self.fields return self.fields
def set_fields(self, fields): def set_fields(self, fields):
self.fields = fields self.fields = fields
def create_base_map(self): def create_base_map(self): #wypełnia mapę polami z bazowymi logicznymi wartościami
for i in range(definitions.WIDTH_AMOUNT): for i in range(definitions.WIDTH_AMOUNT):
temp_map_field = [] temp_map_field = []
for j in range(definitions.HEIGHT_AMOUNT): for j in range(definitions.HEIGHT_AMOUNT):
@ -23,7 +23,7 @@ class Map:
temp_field = field.Field(temp_plant, temp_rect, temp_soil) temp_field = field.Field(temp_plant, temp_rect, temp_soil)
temp_map_field.append(temp_field) temp_map_field.append(temp_field)
self.fields.append(temp_map_field) self.fields.append(temp_map_field)
def fill_map(self): def fill_map(self): #wypełnia mapę teksturami na podstawie logicznego stanu pól
for i in range(definitions.WIDTH_AMOUNT): for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT): for j in range(definitions.HEIGHT_AMOUNT):
field = self.fields[i][j] field = self.fields[i][j]
@ -81,7 +81,7 @@ class Map:
elif block != definitions.DIRT or block != definitions.FARMLAND_DRY or block != definitions.FARMLAND_WET: elif block != definitions.DIRT or block != definitions.FARMLAND_DRY or block != definitions.FARMLAND_WET:
definitions.WINDOW.blit(definitions.FARMLAND_WET, (rect.x, rect.y)) definitions.WINDOW.blit(definitions.FARMLAND_WET, (rect.x, rect.y))
definitions.WINDOW.blit(block, (rect.x, rect.y)) definitions.WINDOW.blit(block, (rect.x, rect.y))
def draw_window(self, tractor1_rect): def draw_window(self, tractor1_rect): #rysuje mapę
self.fill_map() self.fill_map()
definitions.WINDOW.blit(definitions.TRACTOR, (tractor1_rect.x, tractor1_rect.y)) definitions.WINDOW.blit(definitions.TRACTOR, (tractor1_rect.x, tractor1_rect.y))
pygame.display.update() pygame.display.update()

View File

@ -1,8 +1,8 @@
import definitions import definitions
class Plant: class Plant:
def __init__(self, name, state): def __init__(self, name, state):
self.name = name self.name = name #nazwa rośliny np. "wheat"
self.state = state self.state = state #etap rozwoju rośliny
def get_name(self): def get_name(self):
return self.name return self.name
def set_name(self, name): def set_name(self, name):
@ -12,7 +12,7 @@ class Plant:
def set_state(self, state): def set_state(self, state):
self.state = state self.state = state
@staticmethod @staticmethod
def grow_plants(map1): def grow_plants(map1): #metoda statyczna, która zwiększa pole state (etap rozwoju rośliny) dla danej rośliny na danym polu o 1
for i in range(definitions.WIDTH_AMOUNT): for i in range(definitions.WIDTH_AMOUNT):
for j in range(definitions.HEIGHT_AMOUNT): for j in range(definitions.HEIGHT_AMOUNT):
field = map1.get_fields()[i][j] field = map1.get_fields()[i][j]

3
py.py
View File

@ -6,6 +6,7 @@ import station
import tractor import tractor
pygame.display.set_caption("Smart Tractor") pygame.display.set_caption("Smart Tractor")
def main(): def main():
#tworzenie podstawowych obiektów
map1 = map.Map([]) map1 = map.Map([])
map1.create_base_map() map1.create_base_map()
amount_of_seeds_dict = {"beetroot": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "carrot": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "potato": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "wheat": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE} amount_of_seeds_dict = {"beetroot": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "carrot": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "potato": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE, "wheat": definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE}
@ -16,7 +17,7 @@ def main():
tractor1_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE) tractor1_rect = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.BLOCK_SIZE, definitions.BLOCK_SIZE)
clock = pygame.time.Clock() clock = pygame.time.Clock()
run = True run = True
while run: while run: #pętla główna programu
clock.tick(definitions.FPS) clock.tick(definitions.FPS)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:

View File

@ -1,8 +1,8 @@
class Soil: class Soil:
def __init__(self, is_fertilized, state, water_level): def __init__(self, is_fertilized, state, water_level):
self.is_fertilized = is_fertilized self.is_fertilized = is_fertilized #nienawieziona lub nawieziona
self.state = state self.state = state #niezaorana lub zaorana
self.water_level = water_level self.water_level = water_level #niepodlana lub podlana
def get_is_fertilized(self): def get_is_fertilized(self):
return self.is_fertilized return self.is_fertilized
def set_is_fertilized(self, is_fertilized): def set_is_fertilized(self, is_fertilized):

View File

@ -1,7 +1,7 @@
class Station: class Station:
def __init__(self, collected_plants): def __init__(self, collected_plants):
self.collected_plants = collected_plants self.collected_plants = collected_plants #collected_plants to słownik, przechowuje informacje o oddanych plonach
def get_collected_plants(self, name): def get_collected_plants(self, name): #zwraca łączną ilość oddanych plonów dla podanej rośliny (name)
return self.collected_plants[name] return self.collected_plants[name]
def set_collected_plants(self, name, value): def set_collected_plants(self, name, value): #dla podanej rośliny (name) ustawia łączną ilość oddanych plonów (value)
self.collected_plants[name] = value self.collected_plants[name] = value

View File

@ -2,28 +2,28 @@ import definitions
import random import random
class Tractor: class Tractor:
def __init__(self, amount_of_seeds, collected_plants, fertilizer, fuel, water_level, x, y): def __init__(self, amount_of_seeds, collected_plants, fertilizer, fuel, water_level, x, y):
self.amount_of_seeds = amount_of_seeds self.amount_of_seeds = amount_of_seeds #amount_of_seeds to słownik, przechowuje informacje o posiadanej ilości ziaren dla danej rośliny
self.collected_plants = collected_plants self.collected_plants = collected_plants #collected_plants to słownik, przechowuje informacje o zebranych plonach
self.fertilizer = fertilizer self.fertilizer = fertilizer #fertilizer to słownik, przechowuje informacje o ilości posiadanego nawozu dla konkretnej rośliny
self.fuel = fuel self.fuel = fuel #aktualna ilość paliwa
self.water_level = water_level self.water_level = water_level #aktualna ilość wody do podlewania
self.x = x self.x = x
self.y = y self.y = y
def get_all_amount_of_seeds(self): def get_all_amount_of_seeds(self): #zwraca łączną ilość ziaren (suma ziaren dla wszystkich roślin)
return self.amount_of_seeds["beetroot"] + self.amount_of_seeds["carrot"] + self.amount_of_seeds["potato"] + self.amount_of_seeds["wheat"] return self.amount_of_seeds["beetroot"] + self.amount_of_seeds["carrot"] + self.amount_of_seeds["potato"] + self.amount_of_seeds["wheat"]
def get_amount_of_seeds(self, name): def get_amount_of_seeds(self, name): #zwraca łączną ilość ziaren dla podanej rośliny (name)
return self.amount_of_seeds[name] return self.amount_of_seeds[name]
def set_amount_of_seeds(self, name, value): def set_amount_of_seeds(self, name, value): #dla podanej rośliny (name) ustawia łączną ilość ziaren (value)
self.amount_of_seeds[name] = value self.amount_of_seeds[name] = value
def get_all_collected_plants(self): def get_all_collected_plants(self): #zwraca łączną ilość zebranych plonów (suma plonów wszystkich roślin)
return self.collected_plants["beetroot"] + self.collected_plants["carrot"] + self.collected_plants["potato"] + self.collected_plants["wheat"] return self.collected_plants["beetroot"] + self.collected_plants["carrot"] + self.collected_plants["potato"] + self.collected_plants["wheat"]
def get_collected_plants(self, name): def get_collected_plants(self, name): #zwraca łączną ilość zebranych plonów dla podanej rośliny (name)
return self.collected_plants[name] return self.collected_plants[name]
def set_collected_plants(self, name, value): def set_collected_plants(self, name, value): #dla podanej rośliny (name) ustawia łączną ilość zebranych plonów (value)
self.collected_plants[name] = value self.collected_plants[name] = value
def get_fertilizer(self, name): def get_fertilizer(self, name): #zwraca łączną ilość posiadanego nawozu dla podanej rośliny (name)
return self.fertilizer[name] return self.fertilizer[name]
def set_fertilizer(self, name, value): def set_fertilizer(self, name, value): #dla podanej rośliny (name) ustawia ilość posiadanego nawozu (value)
self.fertilizer[name] = value self.fertilizer[name] = value
def get_fuel(self): def get_fuel(self):
return self.fuel return self.fuel
@ -49,18 +49,14 @@ class Tractor:
self.x = self.x + definitions.BLOCK_SIZE self.x = self.x + definitions.BLOCK_SIZE
def move_up(self): def move_up(self):
self.y = self.y - definitions.BLOCK_SIZE self.y = self.y - definitions.BLOCK_SIZE
def station_restore(self, station1): def station_restore(self, station1): #aktualizuje stan stacji pod względem oddanych plonów oraz uzupełnia zapasy traktora
station1.set_collected_plants("beetroot", station1.set_collected_plants("beetroot", station1.get_collected_plants("beetroot") + self.get_collected_plants("beetroot"))
station1.get_collected_plants("beetroot") + self.get_collected_plants("beetroot"))
self.set_collected_plants("beetroot", 0) self.set_collected_plants("beetroot", 0)
station1.set_collected_plants("carrot", station1.set_collected_plants("carrot", station1.get_collected_plants("carrot") + self.get_collected_plants("carrot"))
station1.get_collected_plants("carrot") + self.get_collected_plants("carrot"))
self.set_collected_plants("carrot", 0) self.set_collected_plants("carrot", 0)
station1.set_collected_plants("potato", station1.set_collected_plants("potato", station1.get_collected_plants("potato") + self.get_collected_plants("potato"))
station1.get_collected_plants("potato") + self.get_collected_plants("potato"))
self.set_collected_plants("potato", 0) self.set_collected_plants("potato", 0)
station1.set_collected_plants("wheat", station1.set_collected_plants("wheat", station1.get_collected_plants("wheat") + self.get_collected_plants("wheat"))
station1.get_collected_plants("wheat") + self.get_collected_plants("wheat"))
self.set_collected_plants("wheat", 0) self.set_collected_plants("wheat", 0)
self.set_amount_of_seeds("beetroot", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE) self.set_amount_of_seeds("beetroot", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE)
self.set_amount_of_seeds("carrot", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE) self.set_amount_of_seeds("carrot", definitions.TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE)
@ -72,7 +68,7 @@ class Tractor:
self.set_fertilizer("wheat", definitions.TRACTOR_FERTILIZER) self.set_fertilizer("wheat", definitions.TRACTOR_FERTILIZER)
self.set_fuel(definitions.TRACTOR_FUEL) self.set_fuel(definitions.TRACTOR_FUEL)
self.set_water_level(definitions.TRACTOR_WATER_LEVEL) self.set_water_level(definitions.TRACTOR_WATER_LEVEL)
def do_work(self, map1, station1, tractor1_rect): def do_work(self, map1, station1, tractor1_rect): #jaką pracę traktor ma wykonać na danym polu, na którym aktualnie przebywa (zmienia stan logiczny danego pola)
loop = True loop = True
if self.get_all_amount_of_seeds() == 0: if self.get_all_amount_of_seeds() == 0:
loop = False loop = False
@ -149,7 +145,7 @@ class Tractor:
field.get_soil().set_water_level(False) field.get_soil().set_water_level(False)
field.get_soil().set_state(False) field.get_soil().set_state(False)
self.set_collected_plants("wheat", self.get_collected_plants("wheat") + 1) self.set_collected_plants("wheat", self.get_collected_plants("wheat") + 1)
def is_move_allowed(self, move, tractor1_rect): def is_move_allowed(self, move, tractor1_rect): #sprawdza czy dany ruch, który chce wykonać traktor jest możliwy, zwraca prawdę lub fałsz
if move == 1 and tractor1_rect.y + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.HEIGHT: if move == 1 and tractor1_rect.y + definitions.BLOCK_SIZE + definitions.BLOCK_SIZE <= definitions.HEIGHT:
return True return True
elif move == 2 and tractor1_rect.x - definitions.BLOCK_SIZE >= 0: elif move == 2 and tractor1_rect.x - definitions.BLOCK_SIZE >= 0:
@ -160,7 +156,7 @@ class Tractor:
return True return True
else: else:
return False return False
def tractor1_handle_movement(self, tractor1_rect): def tractor1_handle_movement(self, tractor1_rect): #odpowiada za poruszanie się traktora po mapie
loop = True loop = True
while loop and self.get_fuel() > 0: while loop and self.get_fuel() > 0:
random1 = random.randint(1, 4) random1 = random.randint(1, 4)