-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.cs
172 lines (143 loc) · 4.94 KB
/
Inventory.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Linq;
namespace oopd_011
{
class Inventory
{
List<Item> inventory = new List<Item>();
public void AddToInventory(Item item)
{
inventory.Add(item);
}
public void DisplayFood(Pet pet)
{
List<Food> invFood = new List<Food>();
Console.WriteLine();
Console.WriteLine("FOOD\n");
foreach (Item item in inventory)
{
if (item.GetType() == typeof(Food))
{
Food invFoodItem = (Food)item;
invFood.Add(invFoodItem);
}
}
if (invFood.Count == 0)
{
Console.WriteLine("No food in the inventory");
}
else
{
foreach (Food food in invFood)
{
int x = 0;
Console.WriteLine();
Console.WriteLine($"{x}. {food.itemName}");
Console.WriteLine($"Uses: {food.uses}");
x++;
}
int userStringSelection;
Console.WriteLine("Make your selection: ");
userStringSelection = Convert.ToInt32(Console.ReadLine());
Food userSelectedItem = invFood.ElementAt(userStringSelection);
if (userSelectedItem.uses - 1 < 0)
{
Console.WriteLine($"{userSelectedItem.itemName} depleted");
invFood.Remove(userSelectedItem);
inventory.Remove(userSelectedItem);
}
else
{
pet.EatFood(userSelectedItem);
}
}
}
public void DisplayToy(Pet pet)
{
List<Toy> invToy = new List<Toy>();
Console.WriteLine();
Console.WriteLine("TOYS\n");
foreach (Item item in inventory)
{
if (item.GetType() == typeof(Toy))
{
Toy invToyItem = (Toy)item;
invToy.Add(invToyItem);
}
}
if (invToy.Count == 0)
{
Console.WriteLine("No toys in the inventory");
}
else
{
foreach (Toy toy in invToy)
{
int x = 0;
Console.WriteLine();
Console.WriteLine($"{x}. {toy.itemName}");
Console.WriteLine($"Uses: {toy.uses}");
x++;
}
int userStringSelection;
Console.WriteLine("Make your selection: ");
userStringSelection = Convert.ToInt32(Console.ReadLine());
Toy userSelectedItem = invToy.ElementAt(userStringSelection);
if (userSelectedItem.uses - 1 < 0)
{
Console.WriteLine($"{userSelectedItem.itemName} depleted");
invToy.Remove(userSelectedItem);
inventory.Remove(userSelectedItem);
}
else
{
pet.PlayWithToy(userSelectedItem);
}
}
}
public void DisplayMedicine(Pet pet)
{
List<Medicine> invMedicine = new List<Medicine>();
Console.WriteLine();
Console.WriteLine("MEDICINE\n");
foreach (Item item in inventory)
{
if (item.GetType() == typeof(Medicine))
{
Medicine invMedicineItem = (Medicine)item;
invMedicine.Add(invMedicineItem);
}
}
if (invMedicine.Count == 0)
{
Console.WriteLine("No medicine in the inventory");
}
else
{
foreach (Medicine medicine in invMedicine)
{
int x = 0;
Console.WriteLine();
Console.WriteLine($"{x}. {medicine.itemName}");
Console.WriteLine($"Uses: {medicine.uses}");
x++;
}
int userStringSelection;
Console.WriteLine("Make your selection: ");
userStringSelection = Convert.ToInt32(Console.ReadLine());
Medicine userSelectedItem = invMedicine.ElementAt(userStringSelection);
if (userSelectedItem.uses - 1 < 0)
{
Console.WriteLine($"{userSelectedItem.itemName} depleted");
invMedicine.Remove(userSelectedItem);
inventory.Remove(userSelectedItem);
}
else
{
pet.TakeMedicine(userSelectedItem);
}
}
}
}
}