Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace CSLight
- {
- class Menu
- {
- static void Main(string[] args)
- {
- Fighter[] Fighters =
- {
- new Fighter("РЕКЕТИР", 95, 0, 20, true),
- new Fighter("БАНДИТ", 95, 3, 20, true),
- new Fighter("ГОПНИК", 95, 5, 20, true),
- new Fighter("БОКСЕР", 95, 7, 20, true),
- new Fighter("ПЕШЕХОД", 95, 9, 20, true)
- };
- Fighter LeftFighter = new Fighter();
- Fighter RightFighter = new Fighter();
- Fight Fight = new Fight(LeftFighter, RightFighter);
- Renderer renderer = new Renderer(LeftFighter, RightFighter, Fight);
- bool preparation = true, isFight;
- Console.SetWindowSize(100, 30);
- Console.CursorVisible = false;
- while (preparation == true)
- {
- Console.Clear();
- renderer.ShowAllFighters(ref Fighters);
- renderer.ShowArena();
- Console.SetCursorPosition(1, 10);
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("Имя первого бойца: ");
- string leftFighter = Console.ReadLine().ToUpper();
- Console.SetCursorPosition(65, 10);
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("Имя второго бойца: ");
- string rightFighter = Console.ReadLine().ToUpper();
- Console.ResetColor();
- isFight = true;
- while (isFight == true)
- {
- renderer.ShowFight(isFight, ref Fighters, leftFighter, rightFighter);
- if (LeftFighter.IsLeave == false)
- {
- isFight = false;
- }
- else if (RightFighter.IsLeave == false)
- {
- isFight = false;
- }
- }
- if (Fighters.Length == 1)
- {
- preparation = false;
- }
- }
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(40, 10);
- Console.WriteLine("Победитель: " + Fighters[0].FighterName);
- Console.ReadKey();
- }
- }
- class Fighter
- {
- public string FighterName;
- public float Health;
- public float Armor;
- public float Damage;
- public bool IsLeave;
- public Fighter() { }
- public Fighter(string fighterName, float health, float armor, float damage, bool isLeave)
- {
- FighterName = fighterName;
- Health = health;
- Armor = armor;
- Damage = damage;
- IsLeave = isLeave;
- }
- public void ShowFighter(int posX, int posY)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.SetCursorPosition(posX, posY);
- Console.WriteLine("Боец: " + FighterName);
- Console.SetCursorPosition(posX, ++posY);
- Console.WriteLine("Здоровье: " + Health);
- Console.SetCursorPosition(posX, ++posY);
- Console.WriteLine("Броня: " + Armor);
- Console.SetCursorPosition(posX, ++posY);
- Console.WriteLine("Урон: " + Damage);
- }
- }
- class Fight
- {
- public Fighter LeftFighter;
- public Fighter RightFighter;
- public Fight(Fighter leftFighter, Fighter rightFighter)
- {
- LeftFighter = leftFighter;
- RightFighter = rightFighter;
- }
- public void IsDead(ref Fighter[] fighters)
- {
- foreach (Fighter figter in fighters)
- {
- if (figter.IsLeave == false)
- {
- int index = 0;
- for (int i = 0; i < fighters.Length; ++i)
- {
- if (fighters[i].IsLeave == false)
- {
- index = i;
- break;
- }
- }
- Fighter[] tempFigters = new Fighter[fighters.Length - 1];
- for (int i = 0, j = 0; i < tempFigters.Length; ++i, ++j)
- {
- if (j == index)
- ++j;
- tempFigters[i] = fighters[j];
- }
- fighters = tempFigters;
- }
- }
- }
- public void TakingDamageLeftFighter(Fighter leftFighter, Fighter rightFighter)
- {
- leftFighter.Health -= (rightFighter.Damage - leftFighter.Armor);
- }
- public void TakingDamageRightFighter(Fighter leftFighter, Fighter rightFighter)
- {
- rightFighter.Health -= (leftFighter.Damage - rightFighter.Armor);
- }
- }
- class Renderer
- {
- public Fighter LeftFighter;
- public Fighter RightFighter;
- public Fight Fight;
- public bool IsFight = true;
- public char[,] Arena =
- {
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
- {'|',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',},
- {'=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=','=',}
- };
- public char[,] LeftFighterAppearance =
- {
- {' ','0',' ',' '},
- {'/','|','-','o'},
- {'/',' ','\\',' '}
- };
- public char[,] RightFighterAppearance =
- {
- {' ',' ','0',' '},
- {'o','-','|','\\'},
- {' ','/',' ','\\'}
- };
- public char[,] ClearFighter =
- {
- {' ',' ',' ',' '},
- {' ',' ',' ',' '},
- {' ',' ',' ',' '}
- };
- public Renderer(Fighter leftFighter, Fighter rightFighter, Fight fight)
- {
- LeftFighter = leftFighter;
- RightFighter = rightFighter;
- Fight = fight;
- }
- public void ShowArena()
- {
- int posY = 7;
- Console.SetCursorPosition(31, posY);
- for (int i = 0; i < Arena.GetLength(0); i++)
- {
- for(int j = 0; j < Arena.GetLength(1); j++)
- {
- Console.Write(Arena[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(31, ++posY);
- }
- }
- public void ShowFight(bool isFight, ref Fighter[] fighters, string leftFighter, string rightFighter)
- {
- foreach (Fighter fighter in fighters)
- {
- if (leftFighter == fighter.FighterName)
- LeftFighter = fighter;
- else if (leftFighter != fighter.FighterName)
- {
- isFight = false;
- }
- if (rightFighter != leftFighter && rightFighter == fighter.FighterName)
- RightFighter = fighter;
- else if (rightFighter != fighter.FighterName)
- {
- isFight = false;
- }
- }
- while (LeftFighter.IsLeave != false || RightFighter.IsLeave != false)
- {
- Console.SetCursorPosition(39, 5);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("<<<< БОЙ >>>>");
- Console.SetCursorPosition(33, 13);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(LeftFighter.FighterName);
- Console.SetCursorPosition(33, 14);
- Console.Write(LeftFighter.Health);
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.SetCursorPosition(44, 13);
- Console.Write("VS");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(53, 13);
- Console.Write(RightFighter.FighterName);
- Console.SetCursorPosition(53, 14);
- Console.Write(RightFighter.Health);
- Console.ResetColor();
- ShowLeftFighter();
- ShowRightFighter();
- Thread.Sleep(1000);
- ClearRightFighter();
- AttackRightFighter();
- Fight.TakingDamageLeftFighter(LeftFighter, RightFighter);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(33, 14);
- Console.Write(LeftFighter.Health);
- Console.ResetColor();
- Thread.Sleep(500);
- ClearAttackRightFighter();
- ShowRightFighter();
- if (LeftFighter.Health <= 0)
- {
- LeftFighter.IsLeave = false;
- break;
- }
- Thread.Sleep(1000);
- ClearLeftFighter();
- AttackLeftFighter();
- Fight.TakingDamageRightFighter(LeftFighter, RightFighter);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(53, 14);
- Console.Write(RightFighter.Health);
- Console.ResetColor();
- Thread.Sleep(500);
- ClearAttackLeftFighter();
- ShowLeftFighter();
- if (RightFighter.Health <= 0)
- {
- RightFighter.IsLeave = false;
- break;
- }
- }
- Fight.IsDead(ref fighters);
- }
- public void ShowAllFighters(ref Fighter[] fighters)
- {
- int posX = 0, posY = 0;
- foreach (Fighter fighter in fighters)
- {
- fighter.ShowFighter(posX, posY);
- posX += 20;
- posY = 0;
- }
- Console.ResetColor();
- }
- public void ShowLeftFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(36, posY);
- if (LeftFighter.IsLeave != false)
- {
- for (int i = 0; i < LeftFighterAppearance.GetLength(0); i++)
- {
- for (int j = 0; j < LeftFighterAppearance.GetLength(1); j++)
- {
- Console.Write(LeftFighterAppearance[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(36, ++posY);
- }
- }
- Console.ResetColor();
- }
- public void ClearLeftFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(36, posY);
- for (int i = 0; i < ClearFighter.GetLength(0); i++)
- {
- for (int j = 0; j < ClearFighter.GetLength(1); j++)
- {
- Console.Write(ClearFighter[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(36, ++posY);
- }
- }
- public void AttackLeftFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(48, posY);
- if (LeftFighter.IsLeave != false)
- {
- for (int i = 0; i < LeftFighterAppearance.GetLength(0); i++)
- {
- for (int j = 0; j < LeftFighterAppearance.GetLength(1); j++)
- {
- Console.Write(LeftFighterAppearance[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(48, ++posY);
- }
- }
- Console.ResetColor();
- }
- public void ClearAttackLeftFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(48, posY);
- for (int i = 0; i < ClearFighter.GetLength(0); i++)
- {
- for (int j = 0; j < ClearFighter.GetLength(1); j++)
- {
- Console.Write(ClearFighter[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(48, ++posY);
- }
- }
- public void ShowRightFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.SetCursorPosition(53, posY);
- if (RightFighter.IsLeave != false)
- {
- for (int i = 0; i < RightFighterAppearance.GetLength(0); i++)
- {
- for (int j = 0; j < RightFighterAppearance.GetLength(1); j++)
- {
- Console.Write(RightFighterAppearance[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(53, ++posY);
- }
- }
- Console.ResetColor();
- }
- public void ClearRightFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(53, posY);
- for (int i = 0; i < ClearFighter.GetLength(0); i++)
- {
- for (int j = 0; j < ClearFighter.GetLength(1); j++)
- {
- Console.Write(ClearFighter[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(53, ++posY);
- }
- }
- public void AttackRightFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.SetCursorPosition(41, posY);
- if (RightFighter.IsLeave != false)
- {
- for (int i = 0; i < RightFighterAppearance.GetLength(0); i++)
- {
- for (int j = 0; j < RightFighterAppearance.GetLength(1); j++)
- {
- Console.Write(RightFighterAppearance[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(41, ++posY);
- }
- }
- Console.ResetColor();
- }
- public void ClearAttackRightFighter()
- {
- int posY = 9;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(41, posY);
- for (int i = 0; i < ClearFighter.GetLength(0); i++)
- {
- for (int j = 0; j < ClearFighter.GetLength(1); j++)
- {
- Console.Write(ClearFighter[i, j]);
- }
- Console.WriteLine();
- Console.SetCursorPosition(41, ++posY);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement