using System using System Collections Generic using System Text namesp

  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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Collections.Generic;
using System.Text;
namespace Tumon.Game
{
/// <summary>
/// Действия героя
/// </summary>
interface IHero
{
/// <summary>
/// Получение действия от другого героя
/// </summary>
/// <param name="strikeTyp">Тип удара</param>
/// <param name="power">Сила удара</param>
void GetAttack(Knowledge strikeTyp, int power);
/// <summary>
/// Применение действия на другого героя
/// </summary>
/// <param name="hitHero"></param>
/// <param name="hitKnowledge"></param>
void GiveAttack(IHero hitHero, Knowledge hitKnowledge);
void NextRound();
}
/// <summary>
/// Герой
/// </summary>
abstract class Hero : IHero
{
/// <summary>
/// Показатель здоровья
/// </summary>
protected int health;
abstract public int Health { get; set; }
/// <summary>
/// Уровень
/// </summary>
protected int level;
abstract public int Level { get; set; }
/// <summary>
/// Опыт
/// </summary>
protected int experience;
abstract public int Experience { get; set; }
/// <summary>
/// Показатель маны
/// </summary>
protected int manna;
abstract public int Manna { get; set; }
/// <summary>
/// Знания и навыки которые имеет герой
/// </summary>
protected List<Knowledge> heroKnowledges = new List<Knowledge>();
abstract public List<Knowledge> HeroKnowledges { get; set; }
/// <summary>
/// Знания и навыки действующие в данный момент
/// </summary>
protected List<Knowledge> activeKnowledges = new List<Knowledge>();
abstract public List<Knowledge> ActiveKnowledges { get; set; }
/// <summary>
/// Получение нанесенного удара
/// </summary>
/// <param name="strikeTyp">Тип удара</param>
/// <param name="power">Сила удара</param>
abstract public void GetAttack(Knowledge strikeTyp, int power);
/// <summary>
/// Взаимодействовать с героем
/// </summary>
/// <param name="hitHero"></param>
abstract public void GiveAttack(IHero hitHero, Knowledge hitKnowledge);
/// <summary>
/// Воздействие эффектов
/// </summary>
public void NextRound()
{
for (int i = 0; i < ActiveKnowledges.Count; i++)
{
UseEffect(ActiveKnowledges[i], ActiveKnowledges[i].Power);
if (ActiveKnowledges[i].ActiveTime == 0) ActiveKnowledges[i] = null;
}
ActiveKnowledges.RemoveAll(delegate(Knowledge kn) { return kn == null; });
}
abstract public void UseEffect(Knowledge strikeTyp, int power);
}
class Hacker:Hero
{
private Random rnd = new Random();
/// <summary>
/// Показатель здоровья
/// </summary>
public override int Health { get { return health; } set { health = value; } }
/// <summary>
/// Уровень
/// </summary>
public override int Level { get { return level; } set { level = value; } }
/// <summary>
/// Опыт
/// </summary>
public override int Experience { get { return experience; } set { experience = value; } }
/// <summary>
/// Показатель маны
/// </summary>
public override int Manna { get { return manna; } set { manna = value; } }
/// <summary>
/// Знания и навыки которые имеет герой
/// </summary>
public override List<Knowledge> HeroKnowledges { get { return heroKnowledges; } set { heroKnowledges = value; } }
/// <summary>
/// Знания и навыки действующие в данный момент
/// </summary>
public override List<Knowledge> ActiveKnowledges { get { return activeKnowledges; } set { activeKnowledges = value; } }
/// <summary>
/// Получение нанесенного удара
/// </summary>
/// <param name="strikeTyp">Тип удара</param>
/// <param name="power">Сила удара</param>
public override void GetAttack(Knowledge strikeTyp, int power)
{
NextRound();
UseEffect(strikeTyp, power);
if (strikeTyp.ActiveTime > 0 || strikeTyp.ActiveTime == -1) ActiveKnowledges.Add(strikeTyp);
}
/// <summary>
/// Взаимодействовать с героем
/// </summary>
/// <param name="hitHero"></param>
public override void GiveAttack(IHero hitHero, Knowledge hitKnowledge)
{
int power = (int)(((float)rnd.Next(1, 4) / 4) * level * hitKnowledge.Power);
hitHero.GetAttack(hitKnowledge, level * hitKnowledge.Power);
}
public override void UseEffect(Knowledge strikeTyp, int power)
{
Health = Health + power;
if (strikeTyp.ActiveTime > 0) strikeTyp.ActiveTime--;
OnAttack(new AttackEvent(strikeTyp,power));
}
public Hacker()
:this(1, new List<Knowledge>(0))
{
}
public Hacker(int hackerlevel)
: this(hackerlevel, new List<Knowledge>(0))
{
}
public Hacker(int hackerlevel, List<Knowledge> hackerKnowledge)
{
Level = hackerlevel;
Experience = 0;
health = 100;
heroKnowledges.Add(new HandAttack());
heroKnowledges.AddRange(hackerKnowledge);
}
public delegate void AttackEventDelegate(object obj, AttackEvent e);
public event AttackEventDelegate Attack;
private void OnAttack(AttackEvent e)
{
if (Attack != null) Attack(this,e);
}
}
class AttackEvent : EventArgs
{
private int attackPower;
public int AttackPower { get { return attackPower; } set { attackPower = value; } }
private Knowledge attackKnowledge;
public Knowledge AttackKnowledge { get { return attackKnowledge; } set { attackKnowledge = value; } }
public AttackEvent(Knowledge knowledge, int power)
{
AttackKnowledge = knowledge;
AttackPower = power;
}
}
class MainClass
{
public static void Main()
{
List<Knowledge> kn = new List<Knowledge>();
kn.Add(new VirusAttack());
Hacker hk1 = new Hacker(1);
hk1.Attack += new Hacker.AttackEventDelegate(Attackhk1);
Hacker hk2 = new Hacker(1, kn);
hk2.Attack += new Hacker.AttackEventDelegate(Attackhk2);
hk2.GiveAttack(hk1, hk2.HeroKnowledges[1]);
while (hk1.Health > 0 && hk2.Health > 0)
{
hk1.GiveAttack(hk2, hk1.HeroKnowledges[0]);
hk2.GiveAttack(hk1, hk2.HeroKnowledges[0]);
}
}
static void Attackhk1(object obj,AttackEvent e)
{
Console.WriteLine("герой 1 атакован: " + e.AttackKnowledge.Name + " (" + e.AttackPower + ")");
}
static void Attackhk2(object obj, AttackEvent e)
{
Console.WriteLine("герой 2 атакован: " + e.AttackKnowledge.Name + " (" + e.AttackPower + ")");
}
}
}