Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22s_info2_garden
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Röck, Thomas
22s_info2_garden
Commits
639e427c
Commit
639e427c
authored
3 years ago
by
Thomas Röck
Browse files
Options
Downloads
Patches
Plain Diff
v_1_2
parent
2945f0c9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
v_1_2/bed.py
+30
-0
30 additions, 0 deletions
v_1_2/bed.py
v_1_2/fruit.py
+4
-0
4 additions, 0 deletions
v_1_2/fruit.py
v_1_2/plant.py
+28
-0
28 additions, 0 deletions
v_1_2/plant.py
with
62 additions
and
0 deletions
v_1_2/bed.py
0 → 100644
+
30
−
0
View file @
639e427c
from
plant
import
Plant
class
Bed
:
def
__init__
(
self
,
location
:
str
)
->
None
:
self
.
location
=
location
self
.
plants
=
[]
self
.
water_level
=
0
def
__repr__
(
self
)
->
str
:
return
f
"
Bed
{
self
.
location
}
"
def
__str__
(
self
)
->
str
:
return
(
f
"
{
self
!r}
\n
"
f
"
Water level:
{
self
.
water_level
}
\n
"
f
"
{
len
(
self
.
plants
)
}
plants:
{
[
p
.
species
for
p
in
self
.
plants
]
}
"
)
def
plant_plant
(
self
,
plant
:
Plant
)
->
None
:
self
.
plants
.
append
(
plant
)
def
water
(
self
,
added_water
:
int
=
1
)
->
None
:
self
.
water_level
+=
added_water
def
update
(
self
)
->
None
:
for
plant
in
self
.
plants
:
if
self
.
water_level
<=
0
:
print
(
f
"
Bed
{
self
.
location
}
is out of water, plants can
'
t grow
"
)
return
self
.
water_level
-=
1
plant
.
grow
()
This diff is collapsed.
Click to expand it.
v_1_2/fruit.py
0 → 100644
+
4
−
0
View file @
639e427c
class
Fruit
:
def
__init__
(
self
,
name
:
str
,
calories
:
int
):
self
.
name
=
name
self
.
calories
=
calories
This diff is collapsed.
Click to expand it.
v_1_2/plant.py
0 → 100644
+
28
−
0
View file @
639e427c
import
random
from
copy
import
copy
from
fruit
import
Fruit
class
Plant
:
def
__init__
(
self
,
species
:
str
,
growth_factor
:
int
,
fruit_template
:
Fruit
):
self
.
species
=
species
self
.
growth_factor
=
growth_factor
self
.
fruit_template
=
fruit_template
self
.
size
=
1
self
.
fruits
=
[]
def
__repr__
(
self
):
return
f
"
{
self
.
species
}
"
def
__str__
(
self
):
return
f
"
{
self
.
species
}
of size
{
self
.
size
:
.
1
f
}
with
{
len
(
self
.
fruits
)
}
fruits
"
def
grow
(
self
):
self
.
size
*=
self
.
growth_factor
if
random
.
randrange
(
100
)
<
self
.
size
:
self
.
fruits
.
append
(
copy
(
self
.
fruit_template
))
def
pick
(
self
):
return
self
.
fruits
.
pop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment