From 85102482a5579e85763cf2fca8aac8b5177ba9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 1 May 2014 02:22:00 +0200 Subject: [PATCH] Entities werden nun auf die Map gezeichnet --- src/Backend.cs | 7 ++++--- src/Gui/Gui.cs | 25 +++++++++++++++++++++++++ src/Gui/IBackend.cs | 5 +++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Backend.cs b/src/Backend.cs index b302473..d80c5e4 100644 --- a/src/Backend.cs +++ b/src/Backend.cs @@ -27,15 +27,16 @@ namespace WorldOfPeacecraft Parse = new Parser (this, receiverBuffer); Rec = new Receiver (Client, receiverBuffer); Send = new Sender (Client, SenderBuffer); - SenderBuffer.AddLine("get:map"); + SenderBuffer.AddLine ("get:map"); + SenderBuffer.AddLine ("get:ents"); } - public IEnumerable getDragons () + public IEnumerable GetDragons () { return Dragons.Values; } - public IEnumerable getPlayers () + public IEnumerable GetPlayers () { return Players.Values; } diff --git a/src/Gui/Gui.cs b/src/Gui/Gui.cs index e9f345a..80c918d 100644 --- a/src/Gui/Gui.cs +++ b/src/Gui/Gui.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; @@ -54,6 +55,7 @@ namespace WorldOfPeacecraft Graphics g = buffer.Graphics; lock (Backend) { PaintMap (g); + PaintEntities (g); } buffer.Render(); } @@ -95,11 +97,34 @@ namespace WorldOfPeacecraft g.FillRectangle(new SolidBrush(color), posx, posy, tileSize, tileSize); } + public void PaintEntities (Graphics g) + { + IEnumerable dragons = Backend.GetDragons (); + IEnumerable players = Backend.GetPlayers (); + foreach (IPositionable dragon in dragons) { + PaintEntity (g, dragon); + } + foreach (IPositionable player in players) { + PaintEntity (g, player); + } + } + + public void PaintEntity (Graphics g, IPositionable entity) + { + int x = entity.GetX () * tileSize + tileSize / 2 - entitySize / 2; + int y = entity.GetY () * tileSize + tileSize / 2 - entitySize / 2; + g.FillRectangle (new SolidBrush (Color.Red), x, y, entitySize, entitySize); + g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, entitySize, entitySize); + } + public void PerformRefresh () { this.BeginInvoke(new MethodInvoker(delegate { ITile[,] map = Backend.GetMap(); + if (map == null) { + return; + } int mapWidth = (map.GetLength(0)) * tileSize; int mapHeight = (map.GetLength(1)) * tileSize; this.SuspendLayout(); diff --git a/src/Gui/IBackend.cs b/src/Gui/IBackend.cs index 85fe8cb..81c818f 100644 --- a/src/Gui/IBackend.cs +++ b/src/Gui/IBackend.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; namespace WorldOfPeacecraft { @@ -5,6 +6,10 @@ namespace WorldOfPeacecraft { ITile[,] GetMap(); + IEnumerable GetPlayers(); + + IEnumerable GetDragons(); + void Stop(); } }