public static Cell FindCellsInFieldOfView(Player enemyPlayer, Soldier soldier, Direction dir) { List <Cell> nextcells = new List <Cell>(); Cell cell = new Cell(); if (dir == Direction.Right) { for (int i = 1; i < soldier.FieldOfView + 1; i++) { nextcells = Cell.Cells.FindAll(item => item.Y == soldier.Location.Y); cell = nextcells.Find(item => item.X == soldier.Location.X + i); if (cell != null) { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): ищу противника в: {cell.X};{cell.Y}"); FindEnemyInCell(enemyPlayer, cell, soldier); } else { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): дальше граница карты"); } } } if (dir == Direction.Back) { for (int i = 1; i < soldier.FieldOfView + 1; i++) { nextcells = Cell.Cells.FindAll(item => item.Y == soldier.Location.Y - i); cell = nextcells.Find(item => item.X == soldier.Location.X + i); if (cell != null) { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): ищу противника в: {cell.X};{cell.Y}"); FindEnemyInCell(enemyPlayer, cell, soldier); } else { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): дальше граница карты"); } } } if (dir == Direction.Forward) { for (int i = 1; i < soldier.FieldOfView + 1; i++) { nextcells = Cell.Cells.FindAll(item => item.Y == soldier.Location.Y + i); cell = nextcells.Find(item => item.X == soldier.Location.X); if (cell != null) { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): ищу противника в: {cell.X};{cell.Y}"); FindEnemyInCell(enemyPlayer, cell, soldier); } else { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): дальше граница карты"); } } } if (dir == Direction.Left) { for (int i = 1; i < soldier.FieldOfView + 1; i++) { nextcells = Cell.Cells.FindAll(item => item.Y == soldier.Location.Y); cell = nextcells.Find(item => item.X == soldier.Location.X - i); if (cell != null) { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): ищу противника в: {cell.X};{cell.Y}"); FindEnemyInCell(enemyPlayer, cell, soldier); } else { Console.WriteLine($"{soldier.Name}({soldier.Location.X}:{soldier.Location.Y}): дальше граница карты"); } } } return(cell); }
public static void SoldierGo(Player enemyPlayer, Soldier soldier, Direction direction) { if (direction == Direction.Left) { Console.Clear(); if ((soldier.Location.GoLeft == true) && (soldier.Direction == Direction.Left)) { soldier.Points -= 2; List <Cell> xCells = Cell.Cells.FindAll(item => item.X == soldier.Location.X - 1); soldier.Location = xCells.Find(item => item.Y == soldier.Location.Y); Console.WriteLine($"{soldier.Name}:Я в квадрате {soldier.Location.X};{soldier.Location.Y} {Cell.GetTerrain(soldier.Location)}"); FindCellsInFieldOfView(enemyPlayer, soldier, soldier.Direction); } else if (soldier.Location.GoLeft != true) { Console.WriteLine($"{soldier.Name}: в данном направлении прохода нет, командир!"); } else if (soldier.Direction != Direction.Left) { Console.WriteLine($"{soldier.Name}: сначала нужно туда развернуться, командир!"); } } if (direction == Direction.Right) { Console.Clear(); if ((soldier.Location.GoRight == true) && (soldier.Direction == Direction.Right)) { soldier.Points -= 2; List <Cell> xCells = Cell.Cells.FindAll(item => item.X == soldier.Location.X + 1); soldier.Location = xCells.Find(item => item.Y == soldier.Location.Y); Console.WriteLine($"{soldier.Name}:Я в квадрате {soldier.Location.X};{soldier.Location.Y} {Cell.GetTerrain(soldier.Location)}"); FindCellsInFieldOfView(enemyPlayer, soldier, soldier.Direction); } else if (soldier.Location.GoRight != true) { Console.WriteLine($"{soldier.Name}: в данном направлении прохода нет, командир!"); } else if (soldier.Direction != Direction.Right) { Console.WriteLine($"{soldier.Name}: сначала нужно туда развернуться, командир!"); } } if (direction == Direction.Forward) { Console.Clear(); if ((soldier.Location.GoUp == true) && (soldier.Direction == Direction.Forward)) { soldier.Points -= 2; List <Cell> xCells = Cell.Cells.FindAll(item => item.X == soldier.Location.X); soldier.Location = xCells.Find(item => item.Y == soldier.Location.Y + 1); Console.WriteLine($"{soldier.Name}:Я в квадрате {soldier.Location.X};{soldier.Location.Y} {Cell.GetTerrain(soldier.Location)}"); FindCellsInFieldOfView(enemyPlayer, soldier, soldier.Direction); } else if (soldier.Location.GoUp != true) { Console.WriteLine($"{soldier.Name}: в данном направлении прохода нет, командир!"); } else if (soldier.Direction != Direction.Forward) { Console.WriteLine($"{soldier.Name}: сначала нужно туда развернуться, командир!"); } } if (direction == Direction.Back) { Console.Clear(); if ((soldier.Location.GoDown == true) && (soldier.Direction == Direction.Back)) { soldier.Points -= 2; List <Cell> xCells = Cell.Cells.FindAll(item => item.X == soldier.Location.X); soldier.Location = xCells.Find(item => item.Y == soldier.Location.Y - 1); Console.WriteLine($"{soldier.Name}:Я в квадрате {soldier.Location.X};{soldier.Location.Y} {Cell.GetTerrain(soldier.Location)}"); FindCellsInFieldOfView(enemyPlayer, soldier, soldier.Direction); } else if (soldier.Location.GoDown != true) { Console.WriteLine($"{soldier.Name}: в данном направлении прохода нет, командир!"); } else if (soldier.Direction != Direction.Back) { Console.WriteLine($"{soldier.Name}: сначала нужно туда развернуться, командир!"); } } }