-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo133.cs
85 lines (81 loc) · 2.59 KB
/
algo133.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
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
namespace HelloWorld
{
class Program
{
public class Fighter
{
public string Name;
public int Health, DamagePerAttack;
public Fighter(string name, int health, int damagePerAttack)
{
this.Name = name;
this.Health = health;
this.DamagePerAttack = damagePerAttack;
}
}
public static string declareWinner(Fighter fighter1, Fighter fighter2, string firstAttacker)
{
if (firstAttacker == fighter1.Name)
{
while (fighter1.Health > 0 || fighter2.Health > 0)
{
fighter2.Health -= fighter1.DamagePerAttack;
if (fighter2.Health <= 0)
{
return fighter1.Name;
}
fighter1.Health -= fighter2.DamagePerAttack;
if (fighter1.Health <= 0)
{
return fighter2.Name;
}
}
}
else if (firstAttacker == fighter2.Name)
{
while (fighter1.Health > 0 || fighter2.Health > 0)
{
fighter1.Health -= fighter2.DamagePerAttack;
if (fighter1.Health <= 0)
{
return fighter2.Name;
}
fighter2.Health -= fighter1.DamagePerAttack;
if (fighter2.Health <= 0)
{
return fighter1.Name;
}
}
}
return null;
/*
public class Kata
{
public static string declareWinner(Fighter fighter1, Fighter fighter2, string firstAttacker)
{
var (attacker, defender) = firstAttacker == fighter1.Name
? (fighter1, fighter2)
: (fighter2, fighter1);
while (true)
{
defender.Health -= attacker.DamagePerAttack;
if (defender.Health <= 0)
{
return attacker.Name;
}
(attacker, defender) = (defender, attacker);
}
}
}
*/
}
static void Main(string[] args)
{
Console.WriteLine(declareWinner(new Fighter("Lew", 10, 2), new Fighter("Harry", 5, 4), "Lew")); // "Lew"
}
}
}