Mehr code für den Parser

This commit is contained in:
2014-04-09 22:07:18 +02:00
parent ad0776f25d
commit 2504f06e98

View File

@@ -23,7 +23,6 @@ namespace WorldOfPeacecraft
public const string MessPlayers = "players";
public const string MessDragon = "dragon";
public const string MessMapcell = "cell";
private Queue<string> Buffer = new Queue<string> ();
private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false);
private Thread ParserThread;
@@ -72,7 +71,7 @@ namespace WorldOfPeacecraft
ProcessAnswer (parentBlock);
return;
}
CheckBlocksSize(parentBlock.GetBlocks(), 1, 1);
CheckBlocksSize (parentBlock, 1, 1);
Block block = parentBlock.GetBlocks ().First.Value;
switch (block.GetName ()) {
case MessUpdate:
@@ -119,8 +118,8 @@ namespace WorldOfPeacecraft
private void ProcessUpdate (Block updateBlock)
{
LinkedList<Block> blocks = updateBlock.GetBlocks ();
CheckBlocksSize (updateBlock, 1, 1);
LinkedList<Block> blocks = updateBlock.GetBlocks ();
Block block = blocks.First.Value;
switch (block.GetName ()) {
case MessDragon:
@@ -140,8 +139,8 @@ namespace WorldOfPeacecraft
private void ProcessDelete (Block deleteBlock)
{
LinkedList<Block> blocks = deleteBlock;
CheckBlocksSize (deleteBlock, 1, 1);
LinkedList<Block> blocks = deleteBlock.GetBlocks ();
Block block = blocks.First.Value;
switch (block.GetName ()) {
case MessPlayer:
@@ -155,9 +154,21 @@ namespace WorldOfPeacecraft
}
}
private void ProcessMap (Block block)
private void ProcessMap (Block mapBlock)
{
CheckBlocksSize (mapBlock, 1, 1);
Block cellsBlock = mapBlock.GetBlocks ().First.Value;
int height = mapBlock.GetIntValue ("height");
int width = mapBlock.GetIntValue ("width");
try {
CheckBlocksSize (cellsBlock, width * height, width * height);
} catch (ParsingException e) {
throw new ParsingException ("The received map is " + width + "x" + height + "=" + (width * height) + " cells large, but the received cellblock contained " + cellsBlock.GetBlocks ().Count, e);
}
Map map = new Map(height, width);
foreach (Block cell in cellsBlock.GetBlocks()) {
// TODO Fertigstellen
}
}
private void ProcessMessage (Block block)
@@ -200,20 +211,38 @@ namespace WorldOfPeacecraft
{
}
private void ProcessMapcell (Block block)
{
}
private void ProcessDragon (Block block)
{
}
private Dragon MapDragon (Block block)
private Dragon MapDragon (Block dragonBlock)
{
int id = dragonBlock.GetIntValue ("id");
bool busy = dragonBlock.GetBoolValue ("busy");
string desc = dragonBlock.GetStringValue ("desc");
int x = dragonBlock.GetIntValue ("x");
int y = dragonBlock.GetIntValue ("y");
return new Dragon (id, x, y, desc, busy);
}
private Player MapPlayer (Block block)
private Player MapPlayer (Block playerBlock)
{
int id = playerBlock.GetIntValue ("id");
int score = playerBlock.GetIntValue ("points");
bool busy = playerBlock.GetBoolValue ("busy");
string desc = playerBlock.GetStringValue ("desc");
int x = playerBlock.GetIntValue ("x");
int y = playerBlock.GetIntValue ("y");
return new Player (id, x, y, desc, busy, score);
}
private ITile MapMapcell (Block cellBlock)
{
CheckBlocksSize(cellBlock, 1, 1);
int x = cellBlock.GetIntValue("col");
int y = cellBlock.GetIntValue("row");
Block propsBlock = cellBlock.GetBlocks ().First.Value;
// TODO Fertigstellen
}
private void ThrowUnknownBlockException (Block parentBlock, Block childBlock)
@@ -227,11 +256,9 @@ namespace WorldOfPeacecraft
if (blocks.Count < min || (max >= 0 && blocks.Count > max)) {
if (min == max) {
throw new ParsingException ("The block '" + parentBlock.GetName () + "' has to contain exactly '" + min + "' Block, but contained '" + blocks.Count + "'");
}
else if (max < 0) {
} else if (max < 0) {
throw new ParsingException ("The block '" + parentBlock.GetName () + "' has to contain at least '" + min + "' Blocks, but contained '" + blocks.Count + "'");
}
else {
} else {
throw new ParsingException ("The block '" + parentBlock.GetName () + "' has to contain between '" + min + "' and '" + max + "' Blocks, but contained '" + blocks.Count + "'");
}
}