From b8f41e1ee526828d890ef21f7e4e4e51eaff97d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 3 Apr 2014 13:04:22 +0200 Subject: [PATCH] =?UTF-8?q?Backend=20und=20Parser=20+=20Receiver=20=C3=BCb?= =?UTF-8?q?erarbeitet=20und=20un=C3=B6tige=20Klassen=20entfernt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inf3.csproj | 6 +- src/Backend.cs | 36 +++++++++++ src/DefaultGui/Program.cs | 14 ++--- src/DefaultGui/test/Backend.cs | 79 ----------------------- src/DefaultGui/test/Entity.cs | 28 --------- src/DefaultGui/test/MapCell.cs | 53 ---------------- src/Parser.cs | 112 ++++++--------------------------- src/Program.cs | 51 --------------- src/Receiver.cs | 8 +-- src/Start.cs | 14 ----- 10 files changed, 68 insertions(+), 333 deletions(-) create mode 100644 src/Backend.cs delete mode 100644 src/DefaultGui/test/Backend.cs delete mode 100644 src/DefaultGui/test/Entity.cs delete mode 100644 src/DefaultGui/test/MapCell.cs delete mode 100644 src/Program.cs delete mode 100644 src/Start.cs diff --git a/inf3.csproj b/inf3.csproj index f6ff4e4..e0326c1 100644 --- a/inf3.csproj +++ b/inf3.csproj @@ -47,17 +47,13 @@ - - - - - + diff --git a/src/Backend.cs b/src/Backend.cs new file mode 100644 index 0000000..18cee53 --- /dev/null +++ b/src/Backend.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using WorldOfPeacecraft; + +namespace Frontend +{ + public class Backend : IBackend + { + public Backend () + { + // Unsere Main-Methode + } + + public List getDragons() + { + return null; + } + + public List getPlayers() + { + return null; + } + + public Tile[][] getMap() + { + return null; + } + + public void sendCommand(string command) + { + } + + public void sendChat(string message) + { + } + } +} diff --git a/src/DefaultGui/Program.cs b/src/DefaultGui/Program.cs index 21fb1f9..1f23c87 100644 --- a/src/DefaultGui/Program.cs +++ b/src/DefaultGui/Program.cs @@ -11,12 +11,12 @@ namespace Frontend /// /// Der Haupteinstiegspunkt für die Anwendung. /// - //[STAThread] - //static void Main() - //{ - // Application.EnableVisualStyles(); - // Application.SetCompatibleTextRenderingDefault(false); - // Application.Run(new DefaultGui(new Backend())); - //} + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new DefaultGui(new Backend())); + } } } diff --git a/src/DefaultGui/test/Backend.cs b/src/DefaultGui/test/Backend.cs deleted file mode 100644 index c4d7688..0000000 --- a/src/DefaultGui/test/Backend.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Frontend -{ - /// - /// All classes in the test-directory are just classes to illustrate the concept of the frontend and its interfaces. - /// They are undocumented and not very well written and are using dummy-data with no connection to the actual server. - /// On purpose. Because you should come up with your own implementation. :) - /// - public class Backend : IBackend - { - public void sendCommand(string command) - { - Console.WriteLine("received command " + command); - } - - public void sendChat(string message) - { - Console.WriteLine("received chatmessage " + message); - } - - public List getDragons() { - List dragons = new List(); - dragons.Add(new Entity(0,1)); - return dragons; - - } - public List getPlayers() { - List players = new List(); - players.Add(new Entity(1, 1)); - return players; - } - - public ITile[][] getMap() - { - int size = 10; - // init - ITile[][] map = new ITile[size][]; - for (int i = 0; i < size; i++) - { - map[i] = new ITile[size]; - } - Random r = new Random(); - for (int x = 0; x < size; x++) - { - for (int y = 0; y < size; y++) - { - List attr = new List(); - switch (r.Next(0, 5)) - { - case 0: - attr.Add(MapCellAttribute.WATER); - break; - case 1: - attr.Add(MapCellAttribute.HUNTABLE); - attr.Add(MapCellAttribute.FOREST); - break; - case 2: - attr.Add(MapCellAttribute.FOREST); - break; - case 3: - attr.Add(MapCellAttribute.UNWALKABLE); - break; - case 4: - break; - - } - map[x][y] = new MapCell(x, y, attr); - } - } - return map; - } - - } -} diff --git a/src/DefaultGui/test/Entity.cs b/src/DefaultGui/test/Entity.cs deleted file mode 100644 index d7de5d2..0000000 --- a/src/DefaultGui/test/Entity.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Frontend -{ - public class Entity : IPositionable - { - int x, y; - public Entity(int x, int y) - { - this.x = x; - this.y = y; - } - - public int getXPosition() - { - return this.x; - } - - public int getYPosition() - { - return this.y; - } - } -} diff --git a/src/DefaultGui/test/MapCell.cs b/src/DefaultGui/test/MapCell.cs deleted file mode 100644 index b842bb2..0000000 --- a/src/DefaultGui/test/MapCell.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Frontend -{ - public class MapCell : ITile - { - private int x,y; - private List attributes; - public MapCell(int x, int y, List attributes) - { - this.x = x; - this.y = y; - this.attributes = new List(); - this.attributes.AddRange(attributes); - } - - public int getXPosition() - { - return this.x; - } - - public int getYPosition() - { - return this.y; - } - - public bool isWalkable() - { - return !this.attributes.Contains(MapCellAttribute.UNWALKABLE); - } - - public bool isForest() - { - return this.attributes.Contains(MapCellAttribute.FOREST); - } - - public bool isHuntable() - { - return this.attributes.Contains(MapCellAttribute.HUNTABLE); - } - - public bool isWater() - { - return this.attributes.Contains(MapCellAttribute.WATER); - } - } - - public enum MapCellAttribute {UNWALKABLE, WATER, FOREST, HUNTABLE} -} diff --git a/src/Parser.cs b/src/Parser.cs index 3043183..0cac17c 100644 --- a/src/Parser.cs +++ b/src/Parser.cs @@ -1,107 +1,35 @@ using System; +using System.Threading; +using System.Collections.Generic; namespace WorldOfPeacecraft { public class Parser { - private string fromServer; - private string toServer; - - public void convertIncoming(string fromServer) - { + private Queue Buffer; + private Thread ParserThread; + public Parser() + { + Buffer = new Queue(); } - public void convertOutgoing(string toServer) - { - + public void DoParse () + { + while (true) { + // Do awesome stuff + } } - - public void setMe() - { - - } - public object getDragons() - { - return null; - } - - public void getEnt() - { - - } + public void Stop () + { + ParserThread.Abort(); + } - public void getMe() - { - - } - - public void getMap() - { - - } - - public void getUsers() - { - - } - - public void getTime() - { - - } - - public void getOnline() - { - - } - - public void chat(String msg) - { - - } - - public void exit() - { - - } - - public void setOnlineInt(int online) - { - - } - - public int getOnlineInt() - { - return 0; - } - - - public void setPlayers() - { - - } - - public void getMes() - { - - } - - public void setMap() - { - - } - - public string getTimeFromServer() - { - return null; - } - - public void setDragons() - { - - } + public void AddToBuffer(string s) + { + Buffer.Enqueue(s); + } } } diff --git a/src/Program.cs b/src/Program.cs deleted file mode 100644 index d9cb985..0000000 --- a/src/Program.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Net.Sockets; -using System.Threading; -using System; -using WorldOfPeacecraft; - -public class Program -{ - private Receiver Rec; - private Sender Send; - private Thread SenderThread; - private Thread ReceiverThread; - - public static void Main () - { - Program program = new Program(); - program.StartThreads(); - } - - public Program () - { - TcpClient client = new TcpClient ("localhost", 9999); - Rec = new Receiver (client); - Send = new Sender (client); - } - - public void StartThreads () - { - ReceiverThread = new Thread(new ThreadStart(this.doReceive)); - ReceiverThread.Start (); - SenderThread = new Thread(new ThreadStart(this.doSend)); - SenderThread.Start(); - } - - public void doReceive () - { - string line; - while ((line = Rec.Receive()) != null) - { - Console.WriteLine(line); - } - SenderThread.Abort(); - } - - public void doSend () - { - while (true) { - Send.Send(Console.ReadLine()); - } - } - -} \ No newline at end of file diff --git a/src/Receiver.cs b/src/Receiver.cs index 2043b3f..e460d49 100644 --- a/src/Receiver.cs +++ b/src/Receiver.cs @@ -6,13 +6,13 @@ namespace WorldOfPeacecraft { class Receiver { - private TcpClient Client; private StreamReader Reader; + private Parser Parser; - public Receiver (TcpClient client) + public Receiver (TcpClient client, Parser parser) { - this.Client = client; - this.Reader = new StreamReader (Client.GetStream ()); + this.Parser = parser; + this.Reader = new StreamReader (client.GetStream ()); } public string Receive () diff --git a/src/Start.cs b/src/Start.cs deleted file mode 100644 index c793296..0000000 --- a/src/Start.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Threading; -using System.Net.Sockets; - -public class Start -{ - //public static void Main() - //{ - // TcpClient client = new TcpClient("localhost", 9999); - // Program program = new Program(client); - // program.StartThreads(); - //} - -} \ No newline at end of file