Merge branch 'master' of manuel-voegele.de:inf3
Conflicts: src/Parser.cs
This commit is contained in:
@@ -28,22 +28,19 @@ 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;
|
||||||
@@ -54,7 +51,6 @@ namespace WorldOfPeacecraft
|
|||||||
BufferFilledEvent.WaitOne ();
|
BufferFilledEvent.WaitOne ();
|
||||||
}
|
}
|
||||||
lock (Buffer) {
|
lock (Buffer) {
|
||||||
|
|
||||||
Message.AddLast (Buffer.Dequeue ());
|
Message.AddLast (Buffer.Dequeue ());
|
||||||
}
|
}
|
||||||
if (IsCompletePackage ()) {
|
if (IsCompletePackage ()) {
|
||||||
@@ -71,11 +67,6 @@ 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) {
|
||||||
@@ -140,7 +131,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);
|
||||||
@@ -156,11 +147,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,8 +169,9 @@ namespace WorldOfPeacecraft
|
|||||||
}
|
}
|
||||||
Map map = new Map(height, width);
|
Map map = new Map(height, width);
|
||||||
foreach (Block cell in cellsBlock.GetBlocks()) {
|
foreach (Block cell in cellsBlock.GetBlocks()) {
|
||||||
// TODO Fertigstellen
|
map.SetTile(MapMapcell(cell));
|
||||||
}
|
}
|
||||||
|
backend.SetMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessMessage (Block mesBlock)
|
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 <string> unnamedValues = yourIdBlock.GetUnnamedValues ();
|
||||||
|
string stringValue = unnamedValues.First.Value;
|
||||||
|
int intValue = int.Parse (stringValue);
|
||||||
|
//YourID id = new YourID (intValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessTime (Block block)
|
private void ProcessTime (Block block)
|
||||||
@@ -261,19 +266,43 @@ 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 Tile MapMapcell (Block cellBlock)
|
||||||
{
|
{
|
||||||
CheckBlocksSize (cellBlock, 1, 1);
|
CheckBlocksSize (cellBlock, 1, 1);
|
||||||
int x = cellBlock.GetIntValue ("col");
|
int x = cellBlock.GetIntValue ("col");
|
||||||
int y = cellBlock.GetIntValue ("row");
|
int y = cellBlock.GetIntValue ("row");
|
||||||
Block propsBlock = cellBlock.GetBlocks ().First.Value;
|
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)
|
private void ThrowUnknownBlockException (Block parentBlock, Block childBlock)
|
||||||
{
|
{
|
||||||
@@ -313,17 +342,12 @@ 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 = new LinkedList<String> ();
|
private LinkedList<String> UnnamedValues;
|
||||||
|
|
||||||
public Block (String[] message, int start, int end)
|
public Block (String[] message, int start, int end)
|
||||||
{
|
{
|
||||||
@@ -394,8 +418,6 @@ namespace WorldOfPeacecraft
|
|||||||
{
|
{
|
||||||
return bool.Parse (Values [name]);
|
return bool.Parse (Values [name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user