/
romashov.z
/
PPAGame
Обзор
Документация
Войти
/
romashov.z
/
PPAGame
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
UI/ArmyRenderer.cs
103 строки
4 KB
Zakhar Romashov
Исправлен баг с id юнита и реализован весь функционал для последнего демо
28 май 2026, 23:32
28 май 2026, 23:32
c35199f
Код
Авторство
О чём код?
using System; namespace ArmyBattleGame { static class ArmyRenderer { public static void Print(Army army, string name) { Console.WriteLine(); int alive = 0; foreach (var u in army.AllUnits) if (u.IsAlive) alive++; ConsoleHelper.WriteLine($" {name} ({alive} живых, сетка {army.RowCount}×{army.ColumnCount})", ConsoleColor.Cyan); Console.WriteLine(new string('─', 60)); if (army.ColumnCount == 1) { PrintFlat(army); } else { PrintGrid(army); } } // Однопотоковый вывод (узкий мост) - сохранён прежний формат. private static void PrintFlat(Army army) { int idx = 0; for (int r = 0; r < army.RowCount; r++) { var u = army.GetAt(r, 0); if (u == null) continue; idx++; PrintUnitLine(idx, u); } } // Сетка для широкого моста / стенки. private static void PrintGrid(Army army) { for (int r = 0; r < army.RowCount; r++) { Console.Write($" Ряд {r + 1}: "); for (int c = 0; c < army.ColumnCount; c++) { var u = army.GetAt(r, c); if (u == null) { ConsoleHelper.Write("[ пусто ] ", ConsoleColor.DarkGray); } else { PrintUnitInline(u); } } Console.WriteLine(); } } private static void PrintUnitLine(int idx, IUnit u) { int barLength = 15; int filled = (int)Math.Round((u.Health / u.MaxHealth) * barLength); filled = Math.Clamp(filled, 0, barLength); string bar = new string('█', filled) + new string('░', barLength - filled); string extra = ExtraInfo(u); ConsoleHelper.Write($" {idx}. ", ConsoleColor.White); ConsoleHelper.Write($"{u.DisplayName,-14}", ConsoleColor.Yellow); Console.Write($" [{bar}] "); ConsoleHelper.Write( $"{u.Health:F0}/{u.MaxHealth:F0}", u.Health > u.MaxHealth * 0.3 ? ConsoleColor.Green : ConsoleColor.Red ); Console.Write($" Щит:{u.Shield}"); if (extra.Length > 0) ConsoleHelper.Write(extra, ConsoleColor.Magenta); Console.WriteLine(); } private static void PrintUnitInline(IUnit u) { string short_ = u.DisplayName.Length > 12 ? u.DisplayName.Substring(0, 12) : u.DisplayName; ConsoleHelper.Write($"{short_,-12}", ConsoleColor.Yellow); ConsoleHelper.Write( $" {u.Health:F0}/{u.MaxHealth:F0} ", u.Health > u.MaxHealth * 0.3 ? ConsoleColor.Green : ConsoleColor.Red ); } private static string ExtraInfo(IUnit u) => u switch { ArcherUnit a => $" R:{a.Range} P:{a.Power:F0}", HealerUnit h => $" R:{h.Range} HP:{h.HealPower:F0}", WizardUnit w => $" R:{w.Range} C:{w.CloneChance * 100:F0}%", BuffedHeavyUnit bh when bh.Buffs.Count > 0 => $" Снаряжение:{string.Join(",", bh.Buffs)}", _ => "" }; } }