-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeedling.cpp
More file actions
56 lines (47 loc) · 1.37 KB
/
Seedling.cpp
File metadata and controls
56 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Seedling.h"
#include "Growing.h"
#include "Withered.h"
#include "Plant.h"
#include <iostream>
std::string Seedling::getStateName() const { return "Seedling"; }
void Seedling::onEnter(Plant* plant)
{
std::cout << "[Seedling] onEnter: " << plant->getName() << "\n";
}
void Seedling::onExit(Plant* plant)
{
std::cout << "[Seedling] onExit: " << plant->getName() << "\n";
}
void Seedling::dailyTick(Plant* plant)
{
// Example rule-of-thumb: after 7 days and decent hydration, start Growing
if (plant->getAgeDays() >= 7 && plant->getHydrationLevel() >= 40)
{
plant->setState(new Growing());
return;
}
// Neglect rule-of-thumb: if hydration very low for a while, wither
if (plant->getHydrationLevel() <= 10 && plant->getAgeDays() > 3)
{
plant->setState(new Withered());
return;
}
}
void Seedling::water(Plant* plant)
{
// We can’t change hydration directly (no setter), so just log for now.
std::cout << "[Seedling] watered: " << plant->getName()
<< " (level=" << plant->getHydrationLevel() << ")\n";
}
void Seedling::fertilize(Plant* plant)
{
std::cout << "[Seedling] fertilized (mild effect)\n";
}
void Seedling::harvestAndStore(Plant* /*plant*/)
{
std::cout << "[Seedling] harvest ignored (too early)\n";
}
void Seedling::discard(Plant* plant)
{
plant->setState(new Withered());
}