diff --git a/src/Parser.cs b/src/Parser.cs index 8b247ac..228f633 100644 --- a/src/Parser.cs +++ b/src/Parser.cs @@ -28,22 +28,19 @@ namespace WorldOfPeacecraft private Thread ParserThread; private LinkedList Message; private Regex LastLineRegex; - //private Backend backend; - private Player DummyPlayer; + private Backend backend; public Parser () { ParserThread = new Thread (new ThreadStart (this.RunParser)); Message = new LinkedList (); LastLineRegex = new Regex ("^end:[0-9]+$"); - } private void RunParser () { while (true) { bool waitRequired = false; - //Console.WriteLine(Buffer.Dequeue()); lock (Buffer) { if (Buffer.Count == 0) { waitRequired = true; @@ -54,7 +51,6 @@ namespace WorldOfPeacecraft BufferFilledEvent.WaitOne (); } lock (Buffer) { - Message.AddLast (Buffer.Dequeue ()); } if (IsCompletePackage ()) { @@ -71,11 +67,6 @@ namespace WorldOfPeacecraft ProcessData (mainBlock); } - public Player getDummyPlayer() - { - return DummyPlayer; - } - private void ProcessData (Block parentBlock) { if (parentBlock.GetStringValue ("ans") != null) { @@ -140,7 +131,7 @@ namespace WorldOfPeacecraft ProcessPlayer (block); break; case MessMapcell: - //ProcessMapcell (block); + ProcessMapcell (block); break; default: ThrowUnknownBlockException (updateBlock, block); @@ -156,11 +147,11 @@ namespace WorldOfPeacecraft switch (block.GetName ()) { case MessPlayer: Player player = MapPlayer (block); - //backend.removePlayer (player); + backend.removePlayer (player); break; case MessDragon: Dragon dragon = MapDragon (block); - //backend.removeDragon (dragon); + backend.removeDragon (dragon); break; } } @@ -178,8 +169,9 @@ namespace WorldOfPeacecraft } Map map = new Map(height, width); foreach (Block cell in cellsBlock.GetBlocks()) { - // TODO Fertigstellen + map.SetTile(MapMapcell(cell)); } + backend.SetMap(map); } private void ProcessMessage (Block mesBlock) @@ -215,12 +207,25 @@ namespace WorldOfPeacecraft } - private void ProcessPlayer (Block block) + private void ProcessPlayer (Block playerBlock) { + int points = playerBlock.GetIntValue ("points"); + int id = playerBlock.GetIntValue ("id"); + bool busy = playerBlock.GetBoolValue ("busy"); + string desc = playerBlock.GetStringValue ("desc"); + int x = playerBlock.GetIntValue ("x"); + int y = playerBlock.GetIntValue ("y"); + //Player p = new Player(points, id, busy, desc, x, y,); } + //"points:",INT, "id:",INT,"type:Player","busy:"BOOLEAN,"desc:"STRING,"x:",INT,"y:",INT, - private void ProcessYourid (Block block) + + private void ProcessYourid (Block yourIdBlock) { + LinkedList unnamedValues = yourIdBlock.GetUnnamedValues (); + string stringValue = unnamedValues.First.Value; + int intValue = int.Parse (stringValue); + //YourID id = new YourID (intValue); } private void ProcessTime (Block block) @@ -261,19 +266,43 @@ namespace WorldOfPeacecraft string desc = playerBlock.GetStringValue ("desc"); int x = playerBlock.GetIntValue ("x"); int y = playerBlock.GetIntValue ("y"); - DummyPlayer = new Player(id, x, y, desc, busy, score); return new Player (id, x, y, desc, busy, score); } - /*private ITile MapMapcell (Block cellBlock) + private Tile MapMapcell (Block cellBlock) { - CheckBlocksSize(cellBlock, 1, 1); - int x = cellBlock.GetIntValue("col"); - int y = cellBlock.GetIntValue("row"); + CheckBlocksSize (cellBlock, 1, 1); + int x = cellBlock.GetIntValue ("col"); + int y = cellBlock.GetIntValue ("row"); Block propsBlock = cellBlock.GetBlocks ().First.Value; - // TODO Fertigstellen + bool walkable = false; + bool wall = false; + bool forest = false; + bool water = false; + bool huntable = false; + foreach (string prop in propsBlock.GetUnnamedValues()) { + switch (prop) { + case "WALKABLE": + walkable = true; + break; + case "WALL": + wall = true; + break; + case "FOREST": + forest = true; + break; + case "WATER": + water = true; + break; + case "HUNTABLE": + huntable = true; + break; + default: + throw new ParsingException("Unknown mapcell-property '" + prop + "'"); + } + } + return new Tile(x,y,walkable, wall, forest, huntable, water); } - */ private void ThrowUnknownBlockException (Block parentBlock, Block childBlock) { @@ -312,18 +341,13 @@ namespace WorldOfPeacecraft BufferFilledEvent.Set (); } } - - public Queue getBuffer() - { - return Buffer; - } private class Block { private string Name; private LinkedList Blocks = new LinkedList (); private Dictionary Values = new Dictionary (); - private LinkedList UnnamedValues = new LinkedList (); + private LinkedList UnnamedValues; public Block (String[] message, int start, int end) { @@ -394,8 +418,6 @@ namespace WorldOfPeacecraft { return bool.Parse (Values [name]); } - - } } }