-
Notifications
You must be signed in to change notification settings - Fork 24
saga #27
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
markkket
wants to merge
2
commits into
ISUCT:Hanaeva_Valerija_Nikolaevna
Choose a base branch
from
markkket:patch-1
base: Hanaeva_Valerija_Nikolaevna
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
saga #27
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace CourseApp | ||
{ | ||
using System; | ||
|
||
public class Archer : Player | ||
{ | ||
public Archer(int health, int strength, string name) | ||
: base(health, strength, name, "Огненная стрела", 1) | ||
{ | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "(Лучник) " + Name; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
namespace CourseApp | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class Game | ||
{ | ||
public static void Start() | ||
{ | ||
int count = CountOfPlayers(); // спрашиваем у пользователя число игроков | ||
List<Player> participant = GetPlayersList(count); // генерируем лист игроков | ||
Tourney(participant); // запускаем турнир | ||
} | ||
|
||
private static void Tourney(List<Player> participant) | ||
{ | ||
// играем до тех пор, пока не останется 1 игрок | ||
for (int i = 1; participant.Count != 1; i++) | ||
{ | ||
Logger.WriteRound(i); // передаем в логгер номер раунда | ||
Randomize(participant); // в начале каждого раунда случайным образом перемешиваем игроков | ||
Match(participant); // запускаем раунд | ||
} | ||
|
||
Logger.WriteWinner(participant[0]); // передаем в логгер последнего оставщегося игрока | ||
} | ||
|
||
private static void Match(List<Player> participant) | ||
{ | ||
// так как сражения происходят в парах, то обрабатывать будем до половины листа | ||
for (int i = 0; i < participant.Count / 2; i++) | ||
{ | ||
Player[] opponents = { participant[i * 2], participant[(i * 2) + 1] }; // записываем в массив пару бойцов | ||
Logger.WriteFight(opponents); // передаем в логгер созданный массив | ||
participant[i * 2] = Duel(opponents); // записываем в первое место пары победителя | ||
} | ||
|
||
// увеличиваем i на единицу, так как при удалении элемента массив сокращается и новый победитель оказывается на только что обработанном месте листа | ||
for (int i = 1; i < participant.Count; i++) | ||
{ | ||
participant.RemoveAt(i); // удаляем всех проигравших | ||
} | ||
} | ||
|
||
private static Player Duel(Player[] opponents) | ||
{ | ||
// используем for а не while из-за удобства наличия счетчика | ||
for (int i = 0; true; i++) | ||
{ | ||
string dbf_status = opponents[i % 2].DebaffStatus(); // проверяем какой дебаф действует на игрока | ||
Logger.WriteAction(opponents[i % 2], dbf_status); // передаем этот дебаф и игрока в логгер | ||
|
||
// если дебаф был с периодическим уроном, то передаем его | ||
if (dbf_status == "Огненная стрела") | ||
{ | ||
opponents[i % 2].GetDamage(2); | ||
} | ||
|
||
bool checkDeath = opponents[i % 2].CheckDeath(); // проверяем не умер ли первый игрок от периодического урона | ||
if (checkDeath) | ||
{ | ||
Logger.WriteDeath(opponents[i % 2]); // передаем в логер умершего игрока | ||
opponents[(i + 1) % 2].Refresh(); // восстанавливаем второго игрока | ||
return opponents[(i + 1) % 2]; // передаем его как победителя | ||
} | ||
|
||
// если дебаф на пропуск хода, соответсвенно пропускаем его | ||
if (dbf_status == "Заворожение") | ||
{ | ||
continue; | ||
} | ||
|
||
string playerAction = GetAction(opponents[i % 2]); // выбираем действие игрока | ||
|
||
// если действие не атакующие, передаем в логер игрока, совершившего действие, игрока, над которым соверешенно действие, и название действия | ||
if ((playerAction != "Атака") && (playerAction != "Удар возмездия")) | ||
{ | ||
Logger.WriteAction(opponents[i % 2], opponents[(i + 1) % 2], playerAction); | ||
opponents[(i + 1) % 2].SetDebaff(playerAction); // записываем его в дебаф | ||
} | ||
|
||
// если действие атакующие, получаем значение урона и передаем в логер игрока, совершившего действие, игрока, над которым соверешенно действие, и урон | ||
else | ||
{ | ||
float damage = opponents[i % 2].Attack(); | ||
Logger.WriteAction(opponents[i % 2], opponents[(i + 1) % 2], playerAction, damage); | ||
opponents[(i + 1) % 2].GetDamage(damage); // наносим урон | ||
} | ||
|
||
bool death = opponents[(i + 1) % 2].CheckDeath(); // проверяем не умер ли игрок после получения урона | ||
if (checkDeath) | ||
{ | ||
Logger.WriteDeath(opponents[(i + 1) % 2]); // передаем умершего игрока | ||
opponents[i % 2].Refresh(); // восстанавливаем победителя и возвращаем его | ||
return opponents[i % 2]; | ||
} | ||
} | ||
} | ||
|
||
private static string GetAction(Player inputP) | ||
{ | ||
Random rnd = new Random(); | ||
int chosen = rnd.Next(0, 4); // случайным образом генерируем дейтсвие игрока | ||
switch (chosen) | ||
{ | ||
case 0: | ||
// если игрок может совершить специальное действие возвращаем его название, иначе передаем команду об обычной атаке | ||
if (inputP.CheckAbility()) | ||
{ | ||
return inputP.Ability(); | ||
} | ||
|
||
return "Атака"; | ||
default: | ||
return "Атака"; | ||
} | ||
} | ||
|
||
private static int CountOfPlayers() | ||
{ | ||
// до тех пор, пока не введется корректное число, не возвращаем значение | ||
while (true) | ||
{ | ||
Console.WriteLine("Введите число игроков:"); | ||
int count = Convert.ToInt32(Console.ReadLine()); | ||
if (count <= 0) | ||
{ | ||
Console.WriteLine("Введите число больше 0"); | ||
} | ||
else if (count % 2 != 0) | ||
{ | ||
Console.WriteLine("Введите четное число"); | ||
} | ||
else | ||
{ | ||
return count; | ||
} | ||
} | ||
} | ||
|
||
private static void Randomize(List<Player> input) | ||
{ | ||
// переставляем элементы листа начиная с 0-го | ||
Random rnd = new Random(); | ||
for (int i = 0; i < input.Count; i++) | ||
{ | ||
int chosen = rnd.Next(i, input.Count); | ||
(input[i], input[chosen]) = (input[chosen], input[i]); // перестановка элементов местами | ||
} | ||
} | ||
|
||
private static List<Player> GetPlayersList(int count) | ||
{ | ||
// создаем лист и возрващаем его заполненный вариант | ||
List<Player> playerList = new List<Player>(); | ||
for (int i = 0; i < count; i++) | ||
{ | ||
playerList.Add(GenPlayer()); // добавляем игрока в лист | ||
} | ||
|
||
return playerList; | ||
} | ||
|
||
private static Player GenPlayer() | ||
{ | ||
string[] names = { "Рюрик", "Вещий Олег", "Игорь Старый", "Ольга", "Святослав", "Владимир I", "Ярослав Мудрый", "Всеволод Переяславский", "Владимир Мономах", "Юрий Долгорукий", "Андрей Боголюбский", "Всеволод Большое Гнездо", "Ярослав Всеволодович", "Александр Невский", "Даниил Московский", "Иван Калита" }; | ||
Random random = new Random(); | ||
|
||
// рандомно выбираем здоровье, силу, класс и имя, затем возрващаем полученного игрока | ||
int hlth = (int)random.NextInt64(20, 101); | ||
int str = (int)random.NextInt64(5, 21); | ||
int player_class = (int)random.NextInt64(0, 3); | ||
switch (player_class) | ||
{ | ||
case 0: | ||
return new Knight(hlth, str, names[random.Next(names.Length)]); // передаем в конструктор класса здоровье, силу и элемент массива имен со случайного места | ||
case 1: | ||
return new Mage(hlth, str, names[random.Next(names.Length)]); | ||
case 2: | ||
return new Archer(hlth, str, names[random.Next(names.Length)]); | ||
default: | ||
return new Knight(hlth, str, names[random.Next(names.Length)]); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace CourseApp | ||
{ | ||
using System; | ||
|
||
public class Knight : Player | ||
{ | ||
private bool powerup; | ||
|
||
public Knight(int health, int strength, string name) | ||
: base(health, strength, name, "Удар возмездия", 1) | ||
{ | ||
powerup = false; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "(Рыцарь) " + Name; | ||
} | ||
|
||
public override float Attack() // если была применена способность сильного удара, то возвращаем усиленный урон | ||
{ | ||
if (powerup) | ||
{ | ||
powerup = false; | ||
return (float)Math.Round(Strength * 1.3); | ||
} | ||
else | ||
{ | ||
return Strength; | ||
} | ||
} | ||
|
||
public override string Ability() // если была применена способность возвращаем название способности и устанавливаем флаг в "истина" | ||
{ | ||
AbilityLeft--; | ||
powerup = true; | ||
return AbilityName; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace CourseApp | ||
{ | ||
using System; | ||
|
||
public static class Logger | ||
{ | ||
public static void WriteWinner(Player winner) | ||
{ | ||
Console.WriteLine($"{winner.ToString()} ПОБЕДИЛ!"); | ||
} | ||
|
||
public static void WriteRound(int round) | ||
{ | ||
Console.WriteLine($"Раунд {round}."); | ||
} | ||
|
||
public static void WriteFight(Player[] opponents) | ||
{ | ||
Console.WriteLine($"{opponents[0].ToString()} VS {opponents[1].ToString()}"); | ||
} | ||
|
||
// у метода следующие перегрузки: применение способности по противнику, применение атакующей способности, действующие на игрока дебафы | ||
public static void WriteAction(Player firstP, Player secondP, string action) | ||
{ | ||
Console.WriteLine($"{firstP.ToString()} применяет ({action}) по противнику {secondP.ToString()}"); | ||
} | ||
|
||
public static void WriteAction(Player firstP, Player secondP, string action, float damage) | ||
{ | ||
switch (action) | ||
{ | ||
case "Атака": | ||
Console.WriteLine($"{firstP.ToString()} наносит урон {damage} противнику {secondP.ToString()}"); | ||
break; | ||
case "Удар возмездия": | ||
Console.WriteLine($"{firstP.ToString()} применяет ({action}) и наносит урон {damage} противнику {secondP.ToString()}"); | ||
break; | ||
} | ||
} | ||
|
||
public static void WriteAction(Player inputP, string action) | ||
{ | ||
switch (action) | ||
{ | ||
case "Огненная стрела": | ||
Console.WriteLine($"{inputP.ToString()} получает периодический урон {2} от ({action})"); | ||
break; | ||
case "Заворожение": | ||
Console.WriteLine($"{inputP.ToString()} пропускает ход из-за ({action})"); | ||
break; | ||
} | ||
} | ||
|
||
public static void WriteDeath(Player inputP) | ||
{ | ||
Console.WriteLine($"{inputP.ToString()} погибает"); | ||
Console.WriteLine(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace CourseApp | ||
{ | ||
using System; | ||
|
||
public class Mage : Player | ||
{ | ||
public Mage(int health, int strength, string name) | ||
: base(health, strength, name, "Заворожение", 1) | ||
{ | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "(Маг) " + Name; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тоже видел такое решение