Skip to content

Commit

Permalink
Draw the game border
Browse files Browse the repository at this point in the history
  • Loading branch information
karv committed Jul 20, 2017
1 parent 77d4c3d commit a4e9368
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Serpentina/UniverseControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using CE;
using CE.Console.Controls;
using CE.Console;
using CE.Color;

namespace Serpentina
{
Expand All @@ -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.
Expand All @@ -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 ()
{
Expand Down

0 comments on commit a4e9368

Please sign in to comment.