From a4e93684a25c3db67397c5c6d106a932a5ff9c34 Mon Sep 17 00:00:00 2001 From: Edgar Carballo Date: Wed, 19 Jul 2017 20:51:09 -0700 Subject: [PATCH] Draw the game border --- Serpentina/UniverseControl.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Serpentina/UniverseControl.cs b/Serpentina/UniverseControl.cs index eb4435e..d599270 100644 --- a/Serpentina/UniverseControl.cs +++ b/Serpentina/UniverseControl.cs @@ -1,6 +1,8 @@ using System; using CE; using CE.Console.Controls; +using CE.Console; +using CE.Color; namespace Serpentina { @@ -15,12 +17,14 @@ public class UniverseControl : Control internal SnakeCollection _snakes; internal readonly Size _fieldSize; internal ConsoleColor _backgroundColor = ConsoleColor.Black; + FullColorInfo _edgeColor; [Newtonsoft.Json.JsonConstructor] public UniverseControl () { _snakes = new SnakeCollection (); _fieldSize = new Size (X_SIZE, Y_SIZE); + _edgeColor = new FullColorInfo (ConsoleColor.White, _backgroundColor); } /// Pre iteration cycle setup. @@ -44,8 +48,26 @@ public override void DoDraw () Section.Clear (BackgroundColor); foreach (var snake in _snakes) snake.Draw (this); + + DrawBorder (Section, _edgeColor); } + static void DrawBorder (BufferSection section, FullColorInfo color) + { + var area = section.GetArea (); + var top = '/' + new string ('=', area.Size.Width - 2) + '\\'; + section.CursorLocation = Point.Zero; + section.Write (top); + for (int i = 1; i <= area.Size.Height - 2; i++) + { + section.CursorLocation = new Point (area.Left, i); + section.Write ("|"); + section.CursorLocation = new Point (area.Right, i); + section.Write ("|"); + } + var bot = '\\' + new string ('=', area.Size.Width - 2) + '/'; + section.Write (bot); + } /// Request the optimal size for this control. protected override Size RequestSize () {