8000 Add PeopleBase, some food and Examine for items · EpicSharpCode/StrategyExample@ea7dae0 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea7dae0

Browse files
EpicSharpCodeEpicSharpCode
EpicSharpCode
authored and
EpicSharpCode
committed
Add PeopleBase, some food and Examine for items
1 parent 52c6fce commit ea7dae0

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace StrategyExample.Item
8+
{
9+
internal class RottenApple : ItemBase
10+
{
11+
public RottenApple()
12+
{
13+
name = "Rotten Apple";
14+
selfcost = 0;
15+
SetEatableBehaviour(new NotEatable());
16+
}
17+
}
18+
}

StrategyExample/Item/ItemBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ItemBase
1111
public string name { get; set; }
1212
public float selfcost { get; set; }
1313

14-
public IEatable eatableBehaviour { get; private set; }
14+
public IEatable eatableBehaviour;
1515

1616
public ItemBase() { }
1717

@@ -24,7 +24,10 @@ public ItemBase(string _name, float _selfcost)
2424
}
2525

2626
public void SetEatableBehaviour(IEatable ieatable) => eatableBehaviour = ieatable;
27-
public void TryEat() => eatableBehaviour.Eat();
27+
public void TryEat() { Console.WriteLine($"I try to eat \"{name}\""); eatableBehaviour.Eat(); }
28+
public void Examine() {
29+
string eatableState = eatableBehaviour.GetType().Equals(new Eatable().GetType()) ? "eatable" : "not eatable";
30+
Console.WriteLine($"It's seems to be \"{name}\" and it's {eatableState}"); }
2831

2932
}
3033
}

StrategyExample/People/PeopleBase.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using StrategyExample.Item;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace StrategyExample
9+
{
10+
public class PeopleBase
11+
{
12+
public string name { get; private set; }
13+
public DateTime birthday { get; private set; }
14+
15+
public Inventory inventory;
16+
17+
public PeopleBase(string _name, DateTime _birthday, int _inventoryCapacity)
18+
{
19+
name = _name;
20+
birthday = _birthday;
21+
Console.WriteLine($"I am {name}. My birthday {birthday.ToString("d")}");
22+
23+
inventory = new Inventory(_inventoryCapacity);
24+
}
25+
}
26+
}

StrategyExample/Program.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ namespace StrategyExample
99
{
1010
internal class Program
1111
{
12-
public static Inventory inventory = new Inventory(10);
12+
public static List<PeopleBase> characters = new List<PeopleBase>();
1313

1414
public static void Main(string[] args)
1515
{
16-
inventory.AddItem(new Tomato());
17-
inventory.items[0].TryEat();
16+
characters.Add(new PeopleBase("Leo", new DateTime(1997, 10, 15), 10));
17+
var man = characters[0];
18+
19+
man.inventory.AddIt 67E6 em(new Tomato());
20+
man.inventory.items[0].Examine();
21+
man.inventory.items[0].TryEat();
22+
man.inventory.AddItem(new RottenApple());
23+
man.inventory.items[1].Examine();
24+
man.inventory.items[1].TryEat();
1825

1926
Console.ReadLine();
2027
}

StrategyExample/StrategyExample.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
<ItemGroup>
4646
<Compile Include="Item\Behaviours\Food\Eatable.cs" />
4747
<Compile Include="Item\Behaviours\Food\IEatable.cs" />
48+
<Compile Include="Item\Food\RottenApple.cs" />
4849
<Compile Include="Item\Food\Tomato.cs" />
4950
<Compile Include="Item\Behaviours\Food\NotEatable.cs" />
5051
<Compile Include="Item\Inventory.cs" />
5152
<Compile Include="Item\ItemBase.cs" />
53+
<Compile Include="People\PeopleBase.cs" />
5254
<Compile Include="Program.cs" />
5355
<Compile Include="Properties\AssemblyInfo.cs" />
5456
</ItemGroup>

0 commit comments

Comments
 (0)
0