-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson47.cs
More file actions
188 lines (146 loc) · 3.51 KB
/
Lesson47.cs
File metadata and controls
188 lines (146 loc) · 3.51 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using System;
using System.Collections.Generic;
namespace Tired
{
public class Program
{
static void Main(string[] args)
{
}
}
public sealed class Game
{
private List<IUpdateable> _entities = new List<IUpdateable>();
private List<int> _garbageIndixes = new List<int>();
public void AddEntity(IUpdateable entity) => _entities.Add(entity);
public void Update()
{
UpdateEntities();
DestroyGarbage();
}
private void UpdateEntities()
{
for(int i = 0; i < _entities.Count; i++)
{
IUpdateable entity = _entities[i];
entity.Update();
if (entity.IsDestroyed() == true)
{
_garbageIndixes.Add(i);
}
}
}
private void DestroyGarbage()
{
foreach(int index in _garbageIndixes)
{
_entities.RemoveAt(index);
}
_garbageIndixes.Clear();
}
}
enum SoilderRole
{
Tank,
Damager,
Healer
}
public sealed class Damager : Soilder
{
private int _strength = 5;
private int critChance = 1;
public override void Update()
{
}
public override void Draw()
{
}
}
public abstract class Soilder : IUpdateable
{
private int _health = 100;
private int _maxHealth = 100;
private Soilder _target;
private Vector _position;
public bool IsDead
{
get
{
return Health <= 0;
}
}
public int MaxHealth
{
get
{
return _maxHealth;
}
private set
{
_maxHealth = value;
}
}
public int Health
{
get
{
return _health;
}
private set
{
int overHealth = (_health + value);
if (overHealth > MaxHealth)
{
value -= (overHealth - MaxHealth);
}
else if (value < 0)
{
value = 0;
}
_health = value;
}
}
public int Level { get; private set; } = 1;
public char DrawSymbol { get; private set; } = '_';
public Vector Position
{
get
{
return _position;
}
}
public abstract void Update();
public abstract void Draw();
public virtual void LevelUp(int levelCount)
{
SetMaxHealth( (Level - 1) * 25 + 100);
SetHealth(MaxHealth);
}
public void SetTarget(Soilder soilder) => _target = soilder;
public void SetPosition(Vector position) => _position = position;
public void AddPosition(Vector position) => _position += position;
public bool IsValidTarget() => (_target != null && _target.IsDestroyed() == false);
public void TakeDamage(int damageCount) => Health -= damageCount;
public void RestoreHealth(int restoreCount) => Health += restoreCount;
public int SetHealth(int health) => Health = health;
public int SetMaxHealth(int maxHealth) => MaxHealth = maxHealth;
public bool IsDestroyed() => IsDead;
}
public struct Vector
{
public int X;
public int Y;
public static Vector operator +(Vector a, Vector b) => new Vector { X = a.X + b.X, Y = a.Y + b.Y };
public static Vector operator -(Vector a, Vector b) => new Vector { X = a.X - b.X, Y = a.Y - b.Y };
}
public interface IUpdateable
{
public void Update();
public void Draw();
public bool IsDestroyed();
}
public static class Helper
{
public static int GetRandomValue(int minValue = 0, int maxValue = 1) => new Random().Next(minValue,maxValue);
}
}