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
2 changes: 1 addition & 1 deletion CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CourseApp.Tests
{
using Xunit;
using Vehicles;

public class DemoTest
{
Expand Down
30 changes: 30 additions & 0 deletions CourseApp.Tests/TestSaga.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CourseApp.Tests
{
using Xunit;
using Vehicles;

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

[Fact]
public void TestBattleWinner1()
{
var top = new Player("Knight", "top", 100, 10);
var low = new Player("Knight", "low", 10, 1);
var winner = Battle(top, low);
Assert.Equal(top, winner);
}
public void TestBattleWinner2()
{
top = new Player("Knight", "top", 100, 10);
low = new Player("Knight", "low", 10, 1);
var winner = Battle(low, top);
Assert.Equal(top, winner);
}
}
}
2 changes: 1 addition & 1 deletion CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 14 additions & 2 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using RPGSaga;

public class Program
{
public static void Main(string[] args)
{
var def = new Plane() { Speed = 1000, Height = 11000 };
var artur = new Knight() { Name = "Артур", Maxhealth = 80, Power = 5 };
artur.Greetings();
artur.DealDamage();
artur.VengStrike();
var mc = new MultiplyChars();
var twoheros = mc.CreateN(2);
foreach (var player in twoheros)
{
player.Greetings();
}

/* var def = new Plane() { Speed = 1000, Height = 11000 };
var ssj = new Copter() { Name = "SSJ100", Speed = 800, Diagonal = 8.2 };
var airbus = new Plane("Airbus", -1, 9500);
var pt300 = new Copter("ПТ300", 800, 5000);
Expand All @@ -18,7 +30,7 @@ public static void Main(string[] args)
foreach (var vehicle in transport)
{
Console.WriteLine(vehicle.Display());
}
} */
}
}
}
36 changes: 36 additions & 0 deletions CourseApp/RPGSaga/BattleMaker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class BattleMaker
{
public static Player Battle(Player player1, Player player2)
{
player1.health = player1.Maxhealth;
player2.health = player2.Maxhealth;
var winner = player1;
while (player1.health > 0 && player2.health > 0)
{
player1.DealDamage();
player2.health = player2.health - player1.Power;
if (player2.health <= 0)
{
winner = player1;
Console.WriteLine($"Игрок {player1} победил!");
return winner;
}
player2.DealDamage();
player1.health = player1.health - player2.Power;
if (player2.health <= 0)
{
winner = player2;
Console.WriteLine($"Игрок {player2} победил!");
return winner;
}
}
return winner;
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/RPGSaga/Bowman.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class Bowman : Player
{
public Bowman()
{
Name = "Лучник";
Maxhealth = 50;
Power = 7;
}

public Bowman(string name, double maxhealth, double power)
{
Name = name;
Maxhealth = maxhealth;
Power = power;
}

public double Firearrows()
{
var damage = 0;
Console.WriteLine($"{Name} стреляет огненной стрелой");
return damage;
}
}
}
19 changes: 19 additions & 0 deletions CourseApp/RPGSaga/CharFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class CharFactory
{
public Player CreateChar(string type, string name, double maxhealth, double power)
{
if (type == "Knight")
{
return new Knight(name, maxhealth, power);
}

return new Bowman(name, maxhealth, power);
}
}
}
17 changes: 17 additions & 0 deletions CourseApp/RPGSaga/GetName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class GetName
{
private List<string> namelist = new List<string>() { "Артур", "Ланселот", "Гавейн", "Мерлин", "Арагорн", "Боромир", "Гимли", "Леголас", "Робин" };

public string RandomName()
{
Random r = new Random();
return namelist[r.Next(0, namelist.Count)];
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/RPGSaga/Knight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class Knight : Player
{
public Knight()
{
Name = "Рыцарь";
Maxhealth = 80;
Power = 5;
}

public Knight(string name, double maxhealth, double power)
{
Name = name;
Maxhealth = maxhealth;
Power = power;
}

public double VengStrike()
{
var damage = Power * 1.3;
Console.WriteLine($"{Name} наносит {damage} урона");
return damage;
}
}
}
27 changes: 27 additions & 0 deletions CourseApp/RPGSaga/MatchMaker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class MatchMaker
{
public MatchMaker()
{
var multiplyheros = new MultiplyChars();
heros = multiplyheros.CreateN(N);
}
private int N = 4;
List<Player> heros;
public void Match()
{
for (int i = 1; i <= N; i += 2)
{
heros[i].Greetings();
heros[i + 1].Greetings();
BattleMaker.Battle(heros[i], heros[i + 1]);
/* return Battle(heros[i], heros[i + 1]); */
}
}
}
}
28 changes: 28 additions & 0 deletions CourseApp/RPGSaga/MultiplyChars.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public class MultiplyChars
{
private List<Player> heros;

public List<Player> CreateN(int n)
{
heros = new List<Player>();
var factory = new CharFactory();
for (int i = 1; i <= n; i++)
{
Random r = new Random();
double maxhealth = r.Next(1, 100);
double power = r.Next(1, 10);
var getname = new GetName();
string name = getname.RandomName();
heros.Add(factory.CreateChar("Bowman", name, maxhealth, power));
}

return heros;
}
}
}
100 changes: 100 additions & 0 deletions CourseApp/RPGSaga/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
namespace RPGSaga
{
using System;
using System.Collections.Generic;
using System.Text;

public abstract class Player
{
public string Type;
public double health;
private double maxhealth;
private double power;

public Player()
{
Name = "<Безымянный>";
Maxhealth = 100;
Power = 1;
}

public Player(string name, double maxhealth, double power)
{
Name = name;
Maxhealth = maxhealth;
Power = power;
}
public Player(string type, string name, double maxhealth, double power)
{
Type = type;
Name = name;
Maxhealth = maxhealth;
Power = power;
}
public string Name { get; set; }

public double Maxhealth
{
get
{
return maxhealth;
}

set
{
if (value > 0 && value <= 100)
{
maxhealth = value;
}
else
{
maxhealth = 50;
}
}
}

public double Health
{
get
{
return maxhealth;
}
}

public double Power
{
get
{
return power;
}

set
{
if (value > 0 && value <= 10)
{
power = value;
}
else
{
power = 5;
}
}
}

public void Greetings()
{
Console.WriteLine($"Игрок {Name} (здоровье {Maxhealth}, атака {Power}) готов к бою!");
}

public double DealDamage()
{
Console.WriteLine($"{Name} наносит {Power} урона");
return Power;
}

/* public double GetDamage()
{
Health = Health - damage
} */
}
}
Loading