public string MakeBoxAtPosition(BorderTester border, int startCol, int startRow) { Console.SetCursorPosition(startCol, startRow); string box = ""; for (int i = 1; i <= Height; i++) { box = ""; for (int j = 0; j <= Width; j++) { if (i == 1 && j != 0 && j != Width) { box += "-"; } else if (i == Height && j != 0 && j != Width) { box += "-"; } else if (j == 0 || j == Width) { box += "|"; } else { box += " "; } } Console.Write(box); if (i != Height) { Console.SetCursorPosition(startCol, i + startRow); } } return(" "); }
public string MakeBox(BorderTester border) { string box = ""; for (int i = 0; i <= Height; i++) { for (int j = 0; j <= Width; j++) { if (i == 0 && j != 0 && j != Width) { box += "-"; } else if (i == Height && j != 0 && j != Width) { box += "-"; } else if (j == 0 || j == Width) { box += "|"; } else { box += " "; } } box += "\n"; } return(box); }
static void Main(string[] args) { string[] lines = { "Attack", "Run Away", "Player Info" }; string[] roomInfoText = { "Its a stinky marsh full of creatures. Lets see if this wraps a third time or its broken", "This is an empty room" }; BorderTester Rectangle = new BorderTester(15, 10); string box = Rectangle.MakeBox(Rectangle); //Console.WriteLine(box); BorderTester playermenus = new BorderTester(15, 10); BorderTester roomInfo = new BorderTester(31, 5); playermenus.MakeBoxAtPosition(playermenus, 1, 0); playermenus.MakeBoxAtPosition(playermenus, 17, 0); roomInfo.MakeBoxAtPosition(roomInfo, 1, 10); BorderTester BattleArea = new BorderTester(40, 25); BattleArea.MakeBoxAtPosition(BattleArea, 40, 0); //Console.WriteLine(box); //Console.SetCursorPosition(1, 1); //string insideBoxTest = "Player actions"; Console.SetCursorPosition(2, 1); Console.WriteLine("Player actions"); Console.SetCursorPosition(2, 11); Console.WriteLine("Room Info"); Console.SetCursorPosition(41, 1); Console.WriteLine("Battle info"); Console.SetCursorPosition(18, 1); Console.WriteLine("Player info"); BorderTester.TextFormatter(playermenus, lines, 2, 2, true); BorderTester.TextFormatter(roomInfo, roomInfoText, 11, 2, false); //if (insideBoxTest.Length >= Rectangle.Width) //{ // Console.SetCursorPosition(2, 1); // string insideBoxTest1 = insideBoxTest.Substring((insideBoxTest.Length - (Rectangle.Width)) + 2); // string insideBoxTest2 = insideBoxTest.Substring(Rectangle.Width+1); // Console.WriteLine(insideBoxTest1); // Console.SetCursorPosition(1, 2); // Console.WriteLine(insideBoxTest2); // Console.SetCursorPosition(1, 11); //} Console.SetCursorPosition(0, 20); Console.WriteLine(roomInfoText[0].Length); //Console.WriteLine(Rectangle.MakeBoxAtPosition(Rectangle, 16)); //Console.WriteLine(Rectangle.MakeBoxAtPosition(Rectangle, 31)); }
public static void TextFormatter(BorderTester box, string[] menus, int startRow, int startCol, bool list) { Random rand = new Random(); int spaceIndex = 0; int r1 = rand.Next(0, menus.Length); if (list) { foreach (string menu in menus) { if (menu.Length < box.Width) { Console.SetCursorPosition(startCol, startRow); Console.WriteLine(menu); startRow++; } } } else { if (menus[r1].Length > box.Width) { string longText = menus[r1]; while (longText.Length >= box.Width) { spaceIndex = longText.LastIndexOf(' ', (box.Width)) + 1; Console.SetCursorPosition(startCol, startRow); Console.WriteLine(longText.Substring(0, spaceIndex)); longText = longText.Remove(0, spaceIndex); startRow++; } Console.SetCursorPosition(startCol, startRow); Console.WriteLine(longText); } else { Console.SetCursorPosition(startCol, startRow); Console.WriteLine(menus[r1]); } } }