Sign up
Login
New paste
Home
Archive
English
English
Sign up
Login
New Paste
Browse
using System; using System.Collections.Generic; namespace _6._8 { class Program { static void Main(string[] args) { Squad leftSquad = new Squad(); Squad rightSquad = new Squad(); War war = new War(leftSquad, rightSquad); Console.WriteLine("Сколько солдат будет в 1 стране?"); int leftSoldiersCount = Convert.ToInt32(Console.ReadLine()); leftSquad.Create(leftSoldiersCount); leftSquad.Show(); Console.WriteLine("\nСколько солдат будет во 2 стране?"); int rightSoldiersCount = Convert.ToInt32(Console.ReadLine()); rightSquad.Create(rightSoldiersCount); rightSquad.Show(); war.Shoot(); war.ShowWinner(); } } class War { private readonly Squad _firstSquad; private readonly Squad _secondSquad; public War(Squad firstSquad, Squad secondSquad) { _firstSquad = firstSquad; _secondSquad = secondSquad; } public void Shoot() { while (_firstSquad.CountSoldiers > 0 && _secondSquad.CountSoldiers > 0) { Console.WriteLine("Атакует 1 страна"); _firstSquad.Attack(_secondSquad, _firstSquad); Console.WriteLine("Атакует 2 страна"); _secondSquad.Attack(_firstSquad, _secondSquad); } } public void ShowWinner() { if (_firstSquad.CountSoldiers > 0) { Console.WriteLine($"Победила 1 страна."); } else { Console.WriteLine($"Победила 2 страна."); } } } class Squad { private List<Soldier> _soldiers; public int CountSoldiers => _soldiers.Count; public Squad() { _soldiers = new List<Soldier>(); } public Soldier GetSoldiers(int soldier) { return _soldiers[soldier]; } public void Create(int count) { while (count > _soldiers.Count) { Console.WriteLine("Выберите бойца в ваш отряд.\n1 - Штурмовик\n2 - Медик\n3 - Разведчик\n4 - Танкист\n5 - Огнеметчик"); int userInput = Convert.ToInt32(Console.ReadLine()); switch (userInput) { case 1: _soldiers.Add(new StormTrooper()); break; case 2: _soldiers.Add(new Support()); break; case 3: _soldiers.Add(new Scout()); break; case 4: _soldiers.Add(new Tankman()); break; case 5: _soldiers.Add(new Flamethrowerman()); break; default: _soldiers.Add(new Soldier()); break; } } Console.Clear(); } public void Show() { Console.WriteLine("Ваш отряд:"); foreach (var soldier in _soldiers) { soldier.ShowStats(); } } public void Attack(Squad defenderSquad,Squad attackerSquad) { Random random = new Random(); int defenderId = random.Next(0, defenderSquad.CountSoldiers); int attackerId = random.Next(0, attackerSquad.CountSoldiers); var defender = defenderSquad.GetSoldiers(defenderId); var attacker = attackerSquad.GetSoldiers(attackerId); defender.TakeDamage(attacker); Console.WriteLine($"{defender.Name} получают урон {attacker.Damage} от {attacker.Name}"); defender.ShowStats(); if (defender.Health <= 0) { Console.WriteLine($"{defender.Name} погиб."); defenderSquad._soldiers.Remove(defender); } } } class Soldier { public string Name { get; private set; } public int Health { get; private set; } public int Damage { get; private set; } public Soldier(string name = "Soldier", int health = 100, int damage = 10) { Name = name; Health = health; Damage = damage; } public void TakeDamage(Soldier soldier) { Health -= soldier.Damage; } public void ShowStats() { Console.WriteLine($"{Name}, HP - {Health}, damage - {Damage}"); } } class StormTrooper : Soldier { public StormTrooper() : base("Штурмовик", 100, 30) { } } class Support : Soldier { public Support() : base("Медик", 150, 15) { } } class Scout : Soldier { public Scout() : base("Разведчик", 80, 60) { } } class Tankman : Soldier { public Tankman() : base("Танкист", 200, 50) { } } class Flamethrowerman : Soldier { public Flamethrowerman() : base("Огнеметчик", 140, 40) { } } } {"mode":"full","isActive":false}
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree