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

View File

@@ -11,12 +11,12 @@ namespace Frontend
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[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()));
// }
}
}

View File

@@ -28,19 +28,22 @@ namespace WorldOfPeacecraft
private Thread ParserThread;
private LinkedList<string> Message;
private Regex LastLineRegex;
private Backend backend;
//private Backend backend;
private Player DummyPlayer;
public Parser ()
{
ParserThread = new Thread (new ThreadStart (this.RunParser));
Message = new LinkedList<string> ();
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;
@@ -51,6 +54,7 @@ namespace WorldOfPeacecraft
BufferFilledEvent.WaitOne ();
}
lock (Buffer) {
Message.AddLast (Buffer.Dequeue ());
}
if (IsCompletePackage ()) {
@@ -67,6 +71,11 @@ namespace WorldOfPeacecraft
ProcessData (mainBlock);
}
public Player getDummyPlayer()
{
return DummyPlayer;
}
private void ProcessData (Block parentBlock)
{
if (parentBlock.GetStringValue ("ans") != null) {
@@ -131,7 +140,7 @@ namespace WorldOfPeacecraft
ProcessPlayer (block);
break;
case MessMapcell:
ProcessMapcell (block);
//ProcessMapcell (block);
break;
default:
ThrowUnknownBlockException (updateBlock, block);
@@ -147,11 +156,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;
}
}
@@ -252,10 +261,11 @@ 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 ITile MapMapcell (Block cellBlock)
{
CheckBlocksSize(cellBlock, 1, 1);
int x = cellBlock.GetIntValue("col");
@@ -263,6 +273,7 @@ namespace WorldOfPeacecraft
Block propsBlock = cellBlock.GetBlocks ().First.Value;
// TODO Fertigstellen
}
*/
private void ThrowUnknownBlockException (Block parentBlock, Block childBlock)
{
@@ -301,13 +312,18 @@ namespace WorldOfPeacecraft
BufferFilledEvent.Set ();
}
}
public Queue<string> getBuffer()
{
return Buffer;
}
private class Block
{
private string Name;
private LinkedList<Block> Blocks = new LinkedList<Block> ();
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)
{
@@ -378,6 +394,8 @@ namespace WorldOfPeacecraft
{
return bool.Parse (Values [name]);
}
}
}
}

View File

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