Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using AutoApp;
using Xunit;

public class Auto_Tests
public class AutoTests
{
[Fact]
public void Test1()
Expand Down
82 changes: 82 additions & 0 deletions CourseApp.Tests/RPGsagaTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace RPGsagaApp.Tests
{
using RPGsagaApp;
using Xunit;

public class RPGsagaTest
{
[Fact]
public void Test1()
{
Assert.True(true);
}

[Fact]
public void TestConstructor()
{
var hero1 = new Knight(50, 20, "(Рыцарь) Ричард", "Удар возмездя");
Assert.Equal(50, hero1.Health);
Assert.Equal(20, hero1.Power);
Assert.Equal("(Рыцарь) Ричард", hero1.Name);

var hero2 = new Archer(50, 20, "(Лучник) Леголас", "Огненные стрелы");
Assert.Equal(50, hero2.Health);
Assert.Equal(20, hero2.Power);
Assert.Equal("(Лучник) Леголас", hero2.Name);

while ((hero1.Health > 0) && (hero2.Health > 0))
{
hero1.Action();
hero2.Damage();
if (hero2.Health <= 0)
{
break;
}

hero2.Action();
hero1.Damage();
if (hero1.Health <= 0)
{
break;
}
}
}

[Fact]
public void TestConstructor2()
{
var hero1 = new Knight(50, 20, "(Рыцарь) Зигфрид", "Удар возмездя");
Assert.Equal(50, hero1.Health);
Assert.Equal(20, hero1.Power);
Assert.Equal("(Рыцарь) Зигфрид", hero1.Name);

var hero2 = new Magician(50, 20, "(Маг) Дамблдор", "Заворожение");
Assert.Equal(50, hero2.Health);
Assert.Equal(20, hero2.Power);
Assert.Equal("(Маг) Дамблдор", hero2.Name);

while ((hero1.Health > 0) && (hero2.Health > 0))
{
hero2.Action();
hero1.Damage();
if (hero1.Health <= 0)
{
break;
}

hero1.Action();
hero2.Damage();
if (hero2.Health <= 0)
{
break;
}
}
}

[Fact]

public void TestConstructorFinal()
{
}
}
}
46 changes: 43 additions & 3 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace AutoApp
namespace CourseApp
{
using System;
using AutoApp;
using RPGsagaApp;

public class Program
{
Expand All @@ -23,13 +25,51 @@ public static void Main(string[] args)
Automobile minibus = new Minibus("Маршрутка");
Automobile bus = new Bus("Автобус");
Automobile trolleybus = new Trolleybus("Троллейбус");
Console.WriteLine("--------------------------");
Console.WriteLine(" ");
Console.WriteLine(minibus.Display());
minibus.Move();
Console.WriteLine(bus.Display());
bus.Move();
Console.WriteLine(trolleybus.Display());
trolleybus.Move();
Console.WriteLine("-------------------------------------------------");

Game saga = new Game();
saga.Print();

Game rpg = new Game(100, 35, "(Рыцарь) Артур", "Удар возмездия");
int characterHealth = rpg.Health;
int characterPower = rpg.Power;
string characterName = rpg.Name;
string characterAbility = rpg.Ability;
Console.WriteLine($"Здоровье: {characterHealth} Сила: {characterPower} Имя: {characterName} Способность: {characterAbility}");

rpg.Health = 50;
rpg.Power = 20;
rpg.Name = "(Рыцарь) Ричард";
rpg.Ability = "Удар возмездия";
Console.WriteLine(rpg.Print());

Hero knight1 = new Knight(50, 20, "(Рыцарь) Ричард", "Удар возмездия");
Hero knight2 = new Knight(50, 20, "(Рыцарь) Зигфрид", "Удар возмездия");
Hero archer = new Archer(50, 20, "(Лучник) Леголас", "Огненные стрелы");
Hero magician = new Magician(50, 20, "(Маг) Дамблдор", "Заворожение");
Console.WriteLine(" ");

Game fight1 = new Game();
Console.WriteLine(fight1.EnterFight(1));
Console.WriteLine(fight1.Advertisement(knight1, archer));
fight1.Fight(knight1, archer);

Game fight2 = new Game();
fight2.EnterFight(1);
fight2.Advertisement(knight2, magician);
fight2.Fight(knight2, magician);

Game fightFinal = new Game();
fightFinal.EnterFight(2);
fightFinal.Advertisement(knight1, knight2);
fightFinal.Fight(knight1, knight2);
}
}
}
}
19 changes: 19 additions & 0 deletions CourseApp/RPGsaga/Archer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace RPGsagaApp
{
using System;

public class Archer : Hero
{
public Archer(int health, int power, string name, string ability)
: base(health, power, name, ability)
{
}

public override string AbilityDisplay()
{
Console.WriteLine($"Лучник {Name} использует {Ability}");
Health = Health - 2;
return $" {Name} периодически получает урон {Health} от способности {Ability}";
}
}
}
63 changes: 63 additions & 0 deletions CourseApp/RPGsaga/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace RPGsagaApp
{
using System;

public class Game
{
public Game()
{
}

public Game(int health, int power, string name, string ability)
{
Health = health;
Power = power;
Name = name;
Ability = ability;
}

public int Health { get; set; }

public int Power { get; set; }

public string Name { get; set; }

public string Ability { get; set; }

public string Print()
{
return $"Здоровье: {Health} Сила: {Power} Имя: {Name} Способность: {Ability}";
}

public string EnterFight(int n_kon)
{
return $"Кон. {n_kon};";
}

public string Advertisement(Hero hero1, Hero hero2)
{
return $"{hero1.Name} vs {hero2.Name}";
}

public Hero Fight(Hero hero1, Hero hero2)
{
hero1.Action();
hero2.Damage();
if (hero2.Health <= 0)
{
Console.WriteLine($"{hero2.Name} погибает");
return hero1;
}

hero2.Action();
hero1.Damage();
if (hero1.Health <= 0)
{
Console.WriteLine($"{hero1.Name} погибает");
return hero2;
}

return hero1;
}
}
}
39 changes: 39 additions & 0 deletions CourseApp/RPGsaga/Hero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace RPGsagaApp
{
using System;

public abstract class Hero
{
private int defaultHealth;

public Hero(int health, int power, string name, string ability)
{
Health = health;
defaultHealth = Health;
Power = power;
Name = name;
Ability = ability;
}

public int Health { get; set; }

public int Power { get; set; }

public string Name { get; set; }

public string Ability { get; set; }

public abstract string AbilityDisplay();

public void Action()
{
Console.WriteLine($"{Name} наносит урон {Power} противнику");
}

public void Damage()
{
Health = Health - Power;
Console.WriteLine($"{Name} получил урон {Power} и теряет {Health} единицы жизни");
}
}
}
16 changes: 16 additions & 0 deletions CourseApp/RPGsaga/Knight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace RPGsagaApp
{
public class Knight : Hero
{
public Knight(int health, int power, string name, string ability)
: base(health, power, name, ability)
{
}

public override string AbilityDisplay()
{
Power = Power + 30;
return $"Рыцарь {Name} использует {Ability} и наносит урон {Power} противнику";
}
}
}
10 changes: 10 additions & 0 deletions CourseApp/RPGsaga/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace RPGsagaApp
{
public class Logger
{
public string GameOver(Hero winner)
{
return $"Победителем становится {winner}!";
}
}
}
18 changes: 18 additions & 0 deletions CourseApp/RPGsaga/Magician.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace RPGsagaApp
{
using System;

public class Magician : Hero
{
public Magician(int health, int power, string name, string ability)
: base(health, power, name, ability)
{
}

public override string AbilityDisplay()
{
Console.WriteLine($"Маг {Name} использует {Ability}");
return $"{Name} пропускает ход из-за способности {Ability}";
}
}
}
Loading