Merge branch 'master' of manuel-voegele.de:inf3

This commit is contained in:
Wafa Sadri
2014-04-11 10:28:37 +02:00

View File

@@ -56,15 +56,24 @@ namespace WorldOfPeacecraft
if (IsCompletePackage ()) {
Parse ();
}
// TODO Try-catch. IMPORTANT!
}
}
private void Parse ()
{
String[] aMessage = Enumerable.ToArray (Message);
string[] aMessage = Enumerable.ToArray (Message);
Message.Clear();
try {
Block mainBlock = new Block (aMessage, 0, aMessage.Length - 1);
ProcessData (mainBlock);
} catch (ParsingException e) {
string errormsg = "Error while parsing message: " + e.Message + "\n";
errormsg += "Message:";
foreach (string line in errormsg) {
errormsg += "\n\t" + line;
}
Console.WriteLine(errormsg);
}
}
private void ProcessData (Block parentBlock)
@@ -153,6 +162,9 @@ namespace WorldOfPeacecraft
Dragon dragon = MapDragon (block);
backend.removeDragon (dragon);
break;
default:
ThrowUnknownBlockException(deleteBlock, block);
break;
}
}
@@ -185,6 +197,7 @@ namespace WorldOfPeacecraft
private void ProcessAnswer (Block block)
{
// TODO
}
private void ProcessResult (Block procBlock)
@@ -359,7 +372,7 @@ namespace WorldOfPeacecraft
huntable = true;
break;
default:
throw new ParsingException("Unknown mapcell-property '" + prop + "'");
throw new ParsingException("Unknown mapcell property '" + prop + "'");
}
}
return new Tile(x,y,walkable, wall, forest, huntable, water);
@@ -462,22 +475,48 @@ namespace WorldOfPeacecraft
public string GetStringValue (string name)
{
try {
return Values [name];
} catch (ArgumentOutOfRangeException e) {
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
}
}
public int GetIntValue (string name)
{
try {
return int.Parse (Values [name]);
} catch (ArgumentOutOfRangeException e) {
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
} catch (FormatException e) {
throw new ParsingException("The parameter '" + name + "' in block '" + Name + "' is not an integer (it was '" + Values [name] + "')", e);
} catch (OverflowException e) {
throw new ParsingException("The parameter '" + name + "' in blo '" + Name + "' does not fit into an integer (it was '" + Values [name] + "')", e);
}
}
public long GetLongValue (string name)
{
try {
return long.Parse (Values [name]);
} catch (ArgumentOutOfRangeException e) {
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
} catch (FormatException e) {
throw new ParsingException("The parameter '" + name + "' in block '" + Name + "' is not a long (it was '" + Values [name] + "')", e);
} catch (OverflowException e) {
throw new ParsingException("The parameter '" + name + "' in blo '" + Name + "' does not fit into a long (it was '" + Values [name] + "')", e);
}
}
public bool GetBoolValue (string name)
{
try {
return bool.Parse (Values [name]);
} catch (ArgumentOutOfRangeException e) {
throw new ParsingException ("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
} catch (FormatException e) {
throw new ParsingException ("The parameter '" + name + "' in block '" + Name + "' is not a bool (it was '" + Values [name] + "')", e);
}
}
}
}