Skip to content
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

Mishina_Violetta_Aleksandrovna #20

Open
wants to merge 12 commits into
base: Mishina_Violetta_Aleksandrovna
Choose a base branch
from
13 changes: 0 additions & 13 deletions CourseApp.Tests/DemoTest.cs

This file was deleted.

52 changes: 52 additions & 0 deletions CourseApp.Tests/Task_one/CountryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace CourseApp.Tests.Task_one
{
using System;
using System.IO;
using CourseApp.Task_one;
using Xunit;

[Collection("Sequential")]
public class CountryTests : IDisposable
{
private const string Inp1 = "England 121321 3213";

private const string Out1 = @"The country of England has a population of 121321 people and an area of 3213 km^2
Incorrect value of population.
Incorrect value of area.
The country of England has a population of 121321 people and an area of 15 km^2
";

public void Dispose()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
var standardIn = new StreamReader(Console.OpenStandardInput());
Console.SetOut(standardOut);
Console.SetIn(standardIn);
}

[Theory]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше вместо таких сложных тестов поменять код - тесты будут проще и не будет нарушаться принцип единой ответственности

[InlineData(Inp1, Out1)]
public void EditingWithAndWithoutErorrs(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
string[] buff = input.Split(' ');
Country one = new Country(buff[0], int.Parse(buff[1]), int.Parse(buff[2]));
one.Info();
one.Population = -15;
one.Square = 0;
one.Square = 15;
one.Info();

// assert
var output = stringWriter.ToString();
Assert.Equal($"{expected}", output);
}
}
}
4 changes: 1 addition & 3 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace CourseApp
{
using System;

public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World");
Game.Play();
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/Saga/Archer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CourseApp
{
using System;

public class Archer : Player
{
public Archer(int health, int strength, string name)
: base(health, strength, name, "Cтрелы любви")
{
}

public override string ToString()
{
return "(Лучница) " + Name;
}

public override string Ability()
{
if (AbilityLeft > 0)
{
AbilityLeft--;
return AbilityName;
}
else
{
return "нанесла урон";
}
}
}
}
185 changes: 185 additions & 0 deletions CourseApp/Saga/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
namespace CourseApp
{
using System;
using System.Collections.Generic;
using System.Linq;

public class Game
{
public static void Play()
{
int num = AskNum();
List<Player> playerList = PlayersList(num);
RNDList(ref playerList);
PlayGame(ref playerList);
}

private static void PlayGame(ref List<Player> playerList)
{
for (int i = 1; playerList.Count != 1; i++)
{
Logger.Write(i);
PlayRound(ref playerList);
}

Logger.Write(playerList[0]);
}

private static void PlayRound(ref List<Player> playerList)
{
for (int i = 0; i < playerList.Count / 2; i++)
{
Logger.Write(playerList[i * 2], playerList[(i * 2) + 1]);
playerList[i * 2] = Fight(playerList[i * 2], playerList[(i * 2) + 1]);
}

for (int i = 1; i < playerList.Count; i++)
{
playerList.RemoveAt(i);
}
}

private static Player Fight(Player first, Player second)
{
for (int i = 0; true; i++)
{
if (i != 0)
{
(first, second) = (second, first);
}

string debaffinf = first.DebaffInfo();
Logger.Write(first, debaffinf);
bool checkDeath = first.IsDeath();
if (checkDeath)
{
Logger.Write(first, true);
second.Update();
return second;
}

if (debaffinf == "Заколдованная пыль")
{
continue;
}

string action = PlayerAct();
if (action == "ab")
{
var actionisdone = first.Ability();
if (actionisdone != "нанесла урон")
{
if (actionisdone == "Розовый удар")
{
Logger.Write(first, second, actionisdone, (float)Math.Round(first.Attack() * 1.3f, 2));
second.Damage((float)Math.Round(first.Attack() * 1.3f, 2));
}
else
{
Logger.Write(first, second, actionisdone);
second.Debaff(actionisdone);
}
}
else
{
Logger.Write(first, second, actionisdone, first.Attack());
second.Damage(first.Attack());
}
}
else
{
Logger.Write(first, second, "нанесла урон", first.Attack());
second.Damage(first.Attack());
}

checkDeath = second.IsDeath();
if (checkDeath)
{
Logger.Write(second, true);
first.Update();
return first;
}
}
}

private static string PlayerAct()
{
Random rnd = new Random();
int action = rnd.Next(0, 2);
if (action == 0)
{
return "ab";
}
else
{
return "at";
}
}

private static int AskNum()
{
while (true)
{
Console.WriteLine("Введите четное количество игроков:");
int number = Convert.ToInt32(Console.ReadLine());
if (number <= 0)
{
Console.WriteLine("КАКОЕ НОЛЬ, КАК ИХ МЕНЬШЕ 2 МОЖЕТ БЫТЬ!");
}
else if (number % 2 != 0)
{
Console.WriteLine("ЧЕТНОЕ ДАЙ МНЕ!");
}
else
{
return number;
}
}
}

private static void RNDList(ref List<Player> input)
{
Random rnd = new Random();
Player[] buffer = input.ToArray();
for (int i = 0; i < input.Count; i++)
{
int pos = rnd.Next(i, buffer.Length);
(buffer[i], buffer[pos]) = (buffer[pos], buffer[i]);
}

input = buffer.ToList();
}

private static List<Player> PlayersList(int count)
{
List<Player> players = new List<Player>();
for (int i = 0; i < count; i++)
{
players.Add(PGen());
}

return players;
}

private static Player PGen()
{
Random rnd = new Random();
string[] name = { "Колмезер", "Мэлдебель", "Сьюбексика", "Вилоура", "Бонреетта", "Эрсэн", "Челриция", "Антлейси", "Кейоан", "Хоуелоун", "Дамсзен", "Анжиия", "Глозетда" };
int health = rnd.Next(1, 50);
int strength = rnd.Next(1, 20);
int classChouse = rnd.Next(0, 3);
if (classChouse == 0)
{
return new Warrior(health, strength, name[rnd.Next(name.Length)]);
}
else if (classChouse == 1)
{
return new Mage(health, strength, name[rnd.Next(name.Length)]);
}
else
{
return new Archer(health, strength, name[rnd.Next(name.Length)]);
}
}
}
}
62 changes: 62 additions & 0 deletions CourseApp/Saga/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace CourseApp
{
using System;
using System.Collections.Generic;

public static class Logger
{
public static void Write(Player winner)
{
Console.WriteLine($"{winner.ToString()} ПОБЕДИЛА!");
}

public static void Write(int round)
{
Console.WriteLine($"Раунд {round}");
}

public static void Write(Player first, Player second)
{
Console.WriteLine($"{first.ToString()} VS {second.ToString()}");
}

public static void Write(Player first, Player second, string action)
{
Console.WriteLine($"{first.ToString()} применила ({action}) по противнику {second.ToString()}");
}

public static void Write(Player first, Player second, string action, float damage)
{
if (action != "нанесла урон")
{
Console.WriteLine($"{first.ToString()} применила ({action}) и нанесла урон {damage} противнику {second.ToString()}");
}
else
{
Console.WriteLine($"{first.ToString()} нанесла урон {damage} противнику {second.ToString()}");
}
}

public static void Write(Player inputP, string debaff)
{
switch (debaff)
{
case "Cтрелы любви":
Console.WriteLine($"{inputP.ToString()} получила периодический урон 2 от ({debaff})");
break;
case "Заколдованная пыль":
Console.WriteLine($"{inputP.ToString()} пропустила ход из-за ({debaff})");
break;
}
}

public static void Write(Player inputP, bool isDeath)
{
if (isDeath)
{
Console.WriteLine($"{inputP.ToString()} погибла :)");
Console.WriteLine();
}
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/Saga/Mage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CourseApp
{
using System;

public class Mage : Player
{
public Mage(int health, int strength, string name)
: base(health, strength, name, "Заколдованная пыль")
{
}

public override string ToString()
{
return "(Волшебница) " + Name;
}

public override string Ability()
{
if (AbilityLeft > 0)
{
AbilityLeft--;
return AbilityName;
}
else
{
return "нанесла урон";
}
}
}
}
Loading