Test Commit mit ParserTestKlasse

This commit is contained in:
Daniel Herrmann
2014-04-10 12:30:16 +02:00
parent 4833752a4b
commit 18f254e84d
6 changed files with 94 additions and 18 deletions

11
DummyBackend.cs Normal file
View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace inf3
{
class DummyBackend
{
}
}

40
ParserTest.cs Normal file
View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frontend;
using WorldOfPeacecraft;
using System.Threading;
namespace inf3
{
public class ParserTest
{
static void Main()
{
Parser p = new Parser();
p.AddToBuffer("begin:5");
//Console.WriteLine(p.getBuffer().Dequeue());
p.AddToBuffer("begin:upd");
p.AddToBuffer("begin:player");
p.AddToBuffer("id:3");
p.AddToBuffer("typ:Player");
p.AddToBuffer("busy:false");
p.AddToBuffer("desc:Player3");
p.AddToBuffer("x:3");
p.AddToBuffer("y:15");
p.AddToBuffer("points:0");
p.AddToBuffer("end:player");
p.AddToBuffer("end:upd");
p.AddToBuffer("end:5");
Thread.Sleep(1000);
Console.WriteLine(p.getDummyPlayer());
Console.ReadLine();
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -39,10 +39,14 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DummyBackend.cs" />
<Compile Include="ParserTest.cs" />
<Compile Include="src\Receiver.cs" /> <Compile Include="src\Receiver.cs" />
<Compile Include="src\Sender.cs" /> <Compile Include="src\Sender.cs" />
<Compile Include="src\DefaultGui\DefaultGui.Designer.cs" /> <Compile Include="src\DefaultGui\DefaultGui.Designer.cs" />
<Compile Include="src\DefaultGui\DefaultGui.cs" /> <Compile Include="src\DefaultGui\DefaultGui.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="src\DefaultGui\IBackend.cs" /> <Compile Include="src\DefaultGui\IBackend.cs" />
<Compile Include="src\DefaultGui\IPositionable.cs" /> <Compile Include="src\DefaultGui\IPositionable.cs" />
<Compile Include="src\DefaultGui\ITile.cs" /> <Compile Include="src\DefaultGui\ITile.cs" />
@@ -57,7 +61,5 @@
<Compile Include="src\StringUtils.cs" /> <Compile Include="src\StringUtils.cs" />
<Compile Include="src\ParsingException.cs" /> <Compile Include="src\ParsingException.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="src\DefaultGui\" />
</ItemGroup>
</Project> </Project>

View File

@@ -11,12 +11,12 @@ namespace Frontend
/// <summary> /// <summary>
/// Der Haupteinstiegspunkt für die Anwendung. /// Der Haupteinstiegspunkt für die Anwendung.
/// </summary> /// </summary>
[STAThread] //[STAThread]
static void Main() // static void Main()
{ // {
Application.EnableVisualStyles(); // Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); // Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new DefaultGui(new Backend())); // Application.Run(new DefaultGui(new Backend()));
} // }
} }
} }

View File

@@ -28,19 +28,22 @@ namespace WorldOfPeacecraft
private Thread ParserThread; private Thread ParserThread;
private LinkedList<string> Message; private LinkedList<string> Message;
private Regex LastLineRegex; private Regex LastLineRegex;
private Backend backend; //private Backend backend;
private Player DummyPlayer;
public Parser () public Parser ()
{ {
ParserThread = new Thread (new ThreadStart (this.RunParser)); ParserThread = new Thread (new ThreadStart (this.RunParser));
Message = new LinkedList<string> (); Message = new LinkedList<string> ();
LastLineRegex = new Regex ("^end:[0-9]+$"); LastLineRegex = new Regex ("^end:[0-9]+$");
} }
private void RunParser () private void RunParser ()
{ {
while (true) { while (true) {
bool waitRequired = false; bool waitRequired = false;
//Console.WriteLine(Buffer.Dequeue());
lock (Buffer) { lock (Buffer) {
if (Buffer.Count == 0) { if (Buffer.Count == 0) {
waitRequired = true; waitRequired = true;
@@ -51,6 +54,7 @@ namespace WorldOfPeacecraft
BufferFilledEvent.WaitOne (); BufferFilledEvent.WaitOne ();
} }
lock (Buffer) { lock (Buffer) {
Message.AddLast (Buffer.Dequeue ()); Message.AddLast (Buffer.Dequeue ());
} }
if (IsCompletePackage ()) { if (IsCompletePackage ()) {
@@ -67,6 +71,11 @@ namespace WorldOfPeacecraft
ProcessData (mainBlock); ProcessData (mainBlock);
} }
public Player getDummyPlayer()
{
return DummyPlayer;
}
private void ProcessData (Block parentBlock) private void ProcessData (Block parentBlock)
{ {
if (parentBlock.GetStringValue ("ans") != null) { if (parentBlock.GetStringValue ("ans") != null) {
@@ -131,7 +140,7 @@ namespace WorldOfPeacecraft
ProcessPlayer (block); ProcessPlayer (block);
break; break;
case MessMapcell: case MessMapcell:
ProcessMapcell (block); //ProcessMapcell (block);
break; break;
default: default:
ThrowUnknownBlockException (updateBlock, block); ThrowUnknownBlockException (updateBlock, block);
@@ -147,11 +156,11 @@ namespace WorldOfPeacecraft
switch (block.GetName ()) { switch (block.GetName ()) {
case MessPlayer: case MessPlayer:
Player player = MapPlayer (block); Player player = MapPlayer (block);
backend.removePlayer (player); //backend.removePlayer (player);
break; break;
case MessDragon: case MessDragon:
Dragon dragon = MapDragon (block); Dragon dragon = MapDragon (block);
backend.removeDragon (dragon); //backend.removeDragon (dragon);
break; break;
} }
} }
@@ -252,10 +261,11 @@ namespace WorldOfPeacecraft
string desc = playerBlock.GetStringValue ("desc"); string desc = playerBlock.GetStringValue ("desc");
int x = playerBlock.GetIntValue ("x"); int x = playerBlock.GetIntValue ("x");
int y = playerBlock.GetIntValue ("y"); int y = playerBlock.GetIntValue ("y");
DummyPlayer = new Player(id, x, y, desc, busy, score);
return new Player (id, x, y, desc, busy, score); return new Player (id, x, y, desc, busy, score);
} }
private ITile MapMapcell (Block cellBlock) /*private ITile MapMapcell (Block cellBlock)
{ {
CheckBlocksSize(cellBlock, 1, 1); CheckBlocksSize(cellBlock, 1, 1);
int x = cellBlock.GetIntValue("col"); int x = cellBlock.GetIntValue("col");
@@ -263,6 +273,7 @@ namespace WorldOfPeacecraft
Block propsBlock = cellBlock.GetBlocks ().First.Value; Block propsBlock = cellBlock.GetBlocks ().First.Value;
// TODO Fertigstellen // TODO Fertigstellen
} }
*/
private void ThrowUnknownBlockException (Block parentBlock, Block childBlock) private void ThrowUnknownBlockException (Block parentBlock, Block childBlock)
{ {
@@ -302,12 +313,17 @@ namespace WorldOfPeacecraft
} }
} }
public Queue<string> getBuffer()
{
return Buffer;
}
private class Block private class Block
{ {
private string Name; private string Name;
private LinkedList<Block> Blocks = new LinkedList<Block> (); private LinkedList<Block> Blocks = new LinkedList<Block> ();
private Dictionary<String, String> Values = new Dictionary<String, String> (); private Dictionary<String, String> Values = new Dictionary<String, String> ();
private LinkedList<String> UnnamedValues; private LinkedList<String> UnnamedValues = new LinkedList<String> ();
public Block (String[] message, int start, int end) public Block (String[] message, int start, int end)
{ {
@@ -378,6 +394,8 @@ namespace WorldOfPeacecraft
{ {
return bool.Parse (Values [name]); return bool.Parse (Values [name]);
} }
} }
} }
} }

View File

@@ -18,5 +18,10 @@ namespace WorldOfPeacecraft
{ {
return Score; return Score;
} }
public override string ToString()
{
return "Player: " + Id + " " + PosX + " " + PosY + " " + Desc + " " + Busy + " " + Score;
}
} }
} }