-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
131 lines (117 loc) · 3.81 KB
/
Program.cs
File metadata and controls
131 lines (117 loc) · 3.81 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
namespace ConsoleApp1
{
// Интерфейс для бойцов
public interface IWarrior
{
string Name { get; set; }
double Health { get; set; }
double Attack();
double Block();
}
// Класс Воин, реализующий интерфейс IWarrior
public class Warrior : IWarrior
{
public string Name { get; set; }
public double Health { get; set; }
public double AttackMax { get; set; }
public double BlockMax { get; set; }
private readonly Random _random;
public Warrior(string name, double health, double attackMax, double blockMax)
{
Name = name;
Health = health;
AttackMax = attackMax;
BlockMax = blockMax;
_random = new Random();
}
public double Attack()
{
return _random.Next(1, (int)AttackMax);
}
public double Block()
{
return _random.Next(1, (int)BlockMax);
}
}
// Класс Бой
public class Battle
{
public static void StartFight(IWarrior warrior1, IWarrior warrior2)
{
while (true)
{
if (GetAttackResult(warrior1, warrior2) == "Game Over")
{
Console.WriteLine("Game Over");
break;
}
if (GetAttackResult(warrior2, warrior1) == "Game Over")
{
Console.WriteLine("Game Over");
break;
}
}
}
private static string GetAttackResult(IWarrior warriorA, IWarrior warriorB)
{
double warAAttkAmt = warriorA.Attack();
double warBBlkAmt = warriorB.Block();
double damageToWarB = warAAttkAmt - warBBlkAmt;
if (damageToWarB > 0)
{
warriorB.Health -= damageToWarB;
Console.WriteLine("{0} attacks {1} and deals {2} damage", warriorA.Name, warriorB.Name, damageToWarB);
Console.WriteLine("Blocked Amount: {0}", warBBlkAmt);
Console.WriteLine("{0} has {1} health\n", warriorB.Name, warriorB.Health);
}
else
{
Console.WriteLine("{0} unsuccessfully attacks {1}", warriorA.Name, warriorB.Name);
Console.WriteLine("Damage was blocked");
Console.WriteLine("{0} has {1} health\n", warriorB.Name, warriorB.Health);
}
if (warriorB.Health <= 0)
{
Console.WriteLine("{0} was killed. {1} wins\n", warriorB.Name, warriorA.Name);
return "Game Over";
}
else
{
return "Fight Again";
}
}
}
// Класс для вывода сообщения "START GAME"
public class GameStartMessage
{
public static void ShowStartMessage()
{
char[] array = { 'S', 'T', 'A', 'R', 'T', ' ', 'G', 'A', 'M', 'E' };
foreach (var a in array)
{
Console.Write(a);
Thread.Sleep(250);
}
Console.WriteLine();
}
}
// Класс Программа для запуска приложения
class Program
{
static void Main(string[] args)
{
GameStartMessage.ShowStartMessage();
IWarrior hero = new Warrior("Геральд", 1000, 100, 50);
IWarrior monster = new Warrior("Рошан", 700, 130, 70);
Battle.StartFight(hero, monster);
Console.ReadLine();
}
}
}