private static void SettingTheBoardForUser(Map map, Point point, CustomFigure customFig, string moves, byte spaces) { Random rnd = new Random(); byte size = map.GetSize; byte countFigures = 0; byte countUnsuccessful = 0; while (countFigures != size) { point.SetX = (byte)rnd.Next(0, size); point.SetY = (byte)rnd.Next(0, size); if (map.IsFreeSpace(point.GetX, point.GetY, customFig)) { countFigures++; map.SetUserOnMap(point, customFig, moves, spaces, ref countFigures); } else { countUnsuccessful++; if (countUnsuccessful == size * size) { map.ClearMap(); Console.WriteLine(" There may be no solution for the current figure!\n Please try again!"); break; } } } }
public void SetUserOnMap(Point point, CustomFigure customFig, string moves, byte spaces, ref byte countFigures) { byte _posX = point.GetX; byte _posY = point.GetY; board[_posX, _posY] = customFig.GetLook; customFig.SetUserFightPos(ref _posX, ref _posY, moves, spaces, ref countFigures, board, size); }
private static void StartProgram() { Console.OutputEncoding = Encoding.UTF8; Point point = new Point(); byte size = 0; byte spaces = 0; char fig; string command = ""; string moves = ""; ShowPicks(); while (command != "stop") { Console.Write(" Pick Figure: "); fig = char.Parse(Console.ReadLine()); if (IsUserDefindFig(fig)) { CustomFigure customFig = new CustomFigure(fig); Console.Write(" Choose figure fighting positons: "); moves = Console.ReadLine(); Console.Write(" Choose figure fighting spaces: "); spaces = byte.Parse(Console.ReadLine()); try { Console.Write(" Map Size: "); size = byte.Parse(Console.ReadLine()); if (spaces > size) { spaces = size; } Map map = new Map(size); SettingTheBoardForUser(map, point, customFig, moves, spaces); map.ShowMap(customFig.GetLook); } catch (OverflowException) { OverflowMessage(); } } else { ChessFigure figure = new ChessFigure(fig); try { Console.Write(" Map Size: "); size = byte.Parse(Console.ReadLine()); Map map = new Map(size); SettingTheBoard(map, point, figure); map.ShowMap(figure.GetLook); } catch (OverflowException) { OverflowMessage(); } } command = Console.ReadLine(); } }