Skip to content

Rpg Maria #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: Marija_Popova
Choose a base branch
from
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
41 changes: 0 additions & 41 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,5 @@ public void Test1()
{
Assert.True(true);
}

[Fact]
public void TestNullMass()
{
var res = Program.MyFunction(0.0, 0.0);
Assert.Equal(double.PositiveInfinity, res);
}

[Fact]
public void TaskBWork()
{
List<double> arr = new List<double> { 1.02, 1.21, 1.5, 2.3, 2.71 };
List<double> resB = Program.TaskB(2.0, arr);
List<double> exp = new List<double> { 0.02526278072091896, 0.02489759880547166, 0.024164084643521107, 0.021702665452373534, 0.020418098612637083 };
for (int i = 0; i < 5; i++)
{
Assert.Equal(exp[i], resB[i], 3);
}
}

[Fact]
public void TaskAWork()
{
double a = 2.0;
double xn = 1.2;
double xk = 4.2;
double dx = 0.6;
List<double> resA = Program.TaskA(a, xn, xk, dx);
List<double> exp = new List<double> { 0.025, 0.023, 0.021, 0.02, 0.018 };
for (int i = 0; i < resA.Count; i++)
{
Assert.Equal(exp[i], resA[i], 3);
}
}

[Fact]
public void XnMoreThanXkAndUncorrectDx()
{
List<double> res = Program.TaskA(2.0, 4.2, 1.2, 0.7);
Assert.Equal(res, new List<double>());
}
}
}
66 changes: 0 additions & 66 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,8 @@ namespace CourseApp
{
public class Program
{
public static double MyFunction(double a, double x)
{
var y = Math.Pow(Math.Log10(a + x), 2) / Math.Pow(a + x, 2);
return y;
}

public static List<double> TaskA(double a, double xn, double xk, double dx)
{
if (xk < xn)
{
return new List<double>();
}
else
{
List<double> y = new List<double>((int)((xk - xn) / dx));
for (var x = xn; x < xk; x += dx)
{
y.Add(MyFunction(a, x));
}

return y;
}
}

public static List<double> TaskB(double a, List<double> x)
{
List<double> y = new List<double>();

for (var i = 0; i < x.Count; i++)
{
y.Add(MyFunction(a, x[i]));
}

return y;
}

public static void Main(string[] args)
{
const double a = 2.0;
const double xn = 1.2;
const double xk = 4.2;
const double dx = 0.6;
Console.WriteLine("Task A:");
foreach (var item in TaskA(a, xn, xk, dx))
{
Console.WriteLine($"y = {item}");
}

List<double> x = new List<double> { 1.16, 1.32, 1.47, 1.65, 1.93 };
Console.WriteLine("Task B:");
foreach (var item in TaskB(a, x))
{
Console.WriteLine($"y = {item}");
}

Console.WriteLine();

Animal[] masss = new Animal[2];
masss[0] = new Mouse("Larisa", 2, false, true);
masss[1] = new Cat("Kyza", 7, true, true);
foreach (var item in masss)
{
Console.WriteLine(item.ToString());
Console.WriteLine(item.Voice());
Console.WriteLine();
}

Console.ReadLine();
}
}
}
30 changes: 30 additions & 0 deletions RPG.Tests/RPG.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RPG\RPG.csproj" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
103 changes: 103 additions & 0 deletions RPG.Tests/RPGTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using Xunit;
using RPG;

namespace RPG.Tests
{
public class RPGTests
{
[Fact]
public void CreationTest()
{
Player knight = new Knight();
Player archer = new Archer();
Player wizard = new Wizard();

if (knight.Health > 0 && knight.Strength > 0 && archer.Health > 0 && archer.Strength > 0 && wizard.Health > 0 && wizard.Strength > 0)
{
Assert.True(true);
}
}

[Fact]
public void KnightSkillsTest()
{
Player knight = new Knight();

int damage;
string skillName;

knight.Skill(out skillName, out damage);

if ((skillName == "Удар возмездия" || skillName == "Буря клинков" || skillName == "Удар смерти") && damage > 0)
{
Assert.True(true);
}
}

[Fact]
public void ArcherSkillsTest()
{
Player archer = new Archer();

int damage;
string skillName;

archer.Skill(out skillName, out damage);

if (skillName == "Огненные стрелы" && archer.buff && damage == 0)
{
Assert.True(true);
}
else if ((skillName == "Стрела правосудия" || skillName == "Шквал стрел") && damage > 0)
{
Assert.True(true);
}
}

[Fact]
public void WizardSkillsTest()
{
Player wizard = new Wizard();

int damage;
string skillName;

wizard.Skill(out skillName, out damage);

if (skillName == "Заворожение" && wizard.sleepTime > 0 && damage == 0)
{
Assert.True(true);
}
else if (skillName == "Огненный шар" && damage > 0)
{
Assert.True(true);
}
}

[Fact]
public void GetDamageTest()
{
Player wizard = new Wizard();

int health = wizard.GetDamage(30);

Assert.Equal(wizard.maxHealth - 30, health);
}

[Fact]
public void AtackTest()
{
Player archer = new Archer();

int damage;

archer.Atack(out damage);

if (damage > 0)
{
Assert.True(true);
}
}
}
}
63 changes: 63 additions & 0 deletions RPG/Archer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;

namespace RPG
{
public class Archer : Player
{
public Archer()
: base()
{
typeClass = "Лучник";
skills = new string[] { "Огненные стрелы", "Шквал стрел", "Стрела правосудия" };
}

public override void Skill(out string skillName, out int damage)
{
int probability = random.Next(0, 100);
if (!buff)
{
if (probability <= 20)
{
skillName = "Стрела правосудия";
}
else if (probability <= 90)
{
skillName = "Огненные стрелы";
}
else
{
skillName = "Шквал стрел";
}
}
else
{
if (probability <= 70)
{
skillName = "Стрела правосудия";
}
else
{
skillName = "Шквал стрел";
}
}

switch (skillName)
{
case "Стрела правосудия":
damage = (int)(Strength * 1.5);
break;
case "Шквал стрел":
damage = (int)(Strength * 2.5);
break;
case "Огненные стрелы":
buffName = "Огненные стрелы";
buff = true;
damage = 0;
break;
default:
damage = 0;
break;
}
}
}
}
Loading