Merge branch 'master' of manuel-voegele.de:inf3
This commit is contained in:
12
Message.cs
Normal file
12
Message.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace inf3
|
||||
{
|
||||
public class Message
|
||||
{
|
||||
public Message ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@
|
||||
<Compile Include="src\Backend.cs" />
|
||||
<Compile Include="src\StringUtils.cs" />
|
||||
<Compile Include="src\ParsingException.cs" />
|
||||
<Compile Include="src\Message.cs" />
|
||||
<Compile Include="src\Opponent.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
</Project>
|
||||
@@ -42,6 +42,16 @@ namespace Frontend
|
||||
Players.Remove (player.GetId ());
|
||||
}
|
||||
|
||||
public void clearPlayers ()
|
||||
{
|
||||
Players.Clear ();
|
||||
}
|
||||
|
||||
public void clearDragons ()
|
||||
{
|
||||
Dragons.Clear ();
|
||||
}
|
||||
|
||||
public Player getPlayer (int playerId)
|
||||
{
|
||||
return Players[playerId];
|
||||
|
||||
19
src/Message.cs
Normal file
19
src/Message.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace inf3
|
||||
{
|
||||
public class Message
|
||||
{
|
||||
int sourceID;
|
||||
string source;
|
||||
string text;
|
||||
|
||||
public Message (int srcid, string src, string txt)
|
||||
{
|
||||
sourceID = srcid;
|
||||
source = src;
|
||||
text = txt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
src/Opponent.cs
Normal file
21
src/Opponent.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace inf3
|
||||
{
|
||||
public class Opponent
|
||||
{
|
||||
int id_;
|
||||
int points_;
|
||||
int total_;
|
||||
enum Decision {DRAGON, STAGHUNT, SKIRMISH};
|
||||
Decision d_;
|
||||
|
||||
public Opponent (int id, int points, int total, Decision d)
|
||||
{
|
||||
id_ = id;
|
||||
points_ = points;
|
||||
total_ = total;
|
||||
d_ = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
143
src/Parser.cs
143
src/Parser.cs
@@ -30,6 +30,8 @@ namespace WorldOfPeacecraft
|
||||
private Regex LastLineRegex;
|
||||
private Backend backend;
|
||||
|
||||
enum Decision {DRAGON, STAGHUNT, SKIRMISH};
|
||||
|
||||
public Parser ()
|
||||
{
|
||||
ParserThread = new Thread (new ThreadStart (this.RunParser));
|
||||
@@ -56,15 +58,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 aMessage) {
|
||||
errormsg += "\n\t" + line;
|
||||
}
|
||||
Console.WriteLine(errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessData (Block parentBlock)
|
||||
@@ -153,6 +164,9 @@ namespace WorldOfPeacecraft
|
||||
Dragon dragon = MapDragon (block);
|
||||
backend.removeDragon (dragon);
|
||||
break;
|
||||
default:
|
||||
ThrowUnknownBlockException(deleteBlock, block);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,11 +193,13 @@ namespace WorldOfPeacecraft
|
||||
int srcid = mesBlock.GetIntValue ("srcid");
|
||||
string src = mesBlock.GetStringValue ("src");
|
||||
string txt = mesBlock.GetStringValue ("txt");
|
||||
//Message m = new Message (srcid, src, txt);
|
||||
Message m = new Message (srcid, src, txt);
|
||||
//TODO Herausfinden wie wir das oben lösen (gilt für alle Funktionenstümpfe)
|
||||
}
|
||||
|
||||
private void ProcessAnswer (Block block)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
private void ProcessResult (Block procBlock)
|
||||
@@ -192,19 +208,56 @@ namespace WorldOfPeacecraft
|
||||
int round = procBlock.GetIntValue ("round");
|
||||
bool running = procBlock.GetBoolValue ("running");
|
||||
int delay = procBlock.GetIntValue ("delay");
|
||||
//ProcessOpponent (procBlock.GetBlocks ());
|
||||
LinkedList <Block> block = procBlock.GetBlocks ();
|
||||
ProcessOpponent (block.First.Value);
|
||||
//Result r = new Result(round, running, delay);
|
||||
}
|
||||
//"round:",INT,"running:",BOOLEAN,"delay:",INT,"begin:opponents:"OPPONENT,OPPONENT","end:opponents",
|
||||
|
||||
private void ProcessOpponent(Block block)
|
||||
private void ProcessOpponent(Block oppBlock)
|
||||
{
|
||||
//TODO
|
||||
int id = oppBlock.GetIntValue ("id");
|
||||
int points = oppBlock.GetIntValue ("points");
|
||||
int total = oppBlock.GetIntValue ("total");
|
||||
LinkedList <string> unnamedValue = oppBlock.GetUnnamedValues ();
|
||||
string stringValue = unnamedValue.First.Value;
|
||||
Decision d;
|
||||
if (stringValue == "DRAGON")
|
||||
d = Decision.DRAGON;
|
||||
if (stringValue == "STAGHUNT")
|
||||
d = Decision.STAGHUNT;
|
||||
if (stringValue == "SKIRMISH")
|
||||
d = Decision.SKIRMISH;
|
||||
|
||||
}
|
||||
//DRAGON|STAGHUNT|SKIRMISH
|
||||
|
||||
private void ProcessDecision(Block block)
|
||||
{
|
||||
//TODO -> Wafa
|
||||
//OK das ist hier so'n bissle der gleiche scheiß wie "Answer" wie soll das gehn, ohne Block!?
|
||||
//Maybe not TODO?
|
||||
}
|
||||
|
||||
private void ProcessChallenge (Block block)
|
||||
private void ProcessChallenge (Block challengeBlock)
|
||||
{
|
||||
|
||||
//TODO -> Samed
|
||||
int id = challengeBlock.GetIntValue("id");
|
||||
String type;
|
||||
switch (challengeBlock.GetStringValue())
|
||||
{
|
||||
case "DRAGON":
|
||||
type = "Dragon";
|
||||
break;
|
||||
case "STAGHUNT":
|
||||
type = "Staghunt";
|
||||
break;
|
||||
case "SKIRMISCH":
|
||||
type = "Skirmisch";
|
||||
break;
|
||||
}
|
||||
bool accepted = challengeBlock.GetBoolValue("accepted");
|
||||
//Challenge c = new Challenge(id, type, accepted);
|
||||
//CHALLENGE: "begin:challenge","id:",INT,"type:",("DRAGON"|"STAGHUNT"|"SKIRMISH"),"accepted:",BOOLEAN,"end:challenge"
|
||||
}
|
||||
|
||||
private void ProcessPlayer (Block playerBlock)
|
||||
@@ -217,8 +270,11 @@ namespace WorldOfPeacecraft
|
||||
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 ProcessMapcell (Block mapcellBlock)
|
||||
{
|
||||
backend.getMapObject().SetTile(MapMapcell(mapcellBlock));
|
||||
}
|
||||
|
||||
private void ProcessYourid (Block yourIdBlock)
|
||||
{
|
||||
@@ -226,26 +282,55 @@ namespace WorldOfPeacecraft
|
||||
string stringValue = unnamedValues.First.Value;
|
||||
int intValue = int.Parse (stringValue);
|
||||
//YourID id = new YourID (intValue);
|
||||
//TODO Herausfinden wie wir das oben lösen
|
||||
}
|
||||
|
||||
private void ProcessTime (Block block)
|
||||
private void ProcessTime (Block timeBlock)
|
||||
{
|
||||
LinkedList <string> unnamedValues = timeBlock.GetUnnamedValues ();
|
||||
string stringValue = unnamedValues.First.Value;
|
||||
long longValue = long.Parse (stringValue);
|
||||
//Time t = new Time(longValue);
|
||||
}
|
||||
|
||||
private void ProcessOnline (Block block)
|
||||
private void ProcessOnline (Block onlineBlock)
|
||||
{
|
||||
LinkedList <string> unnamedValues = onlineBlock.GetUnnamedValues ();
|
||||
string stringValue = unnamedValues.First.Value;
|
||||
int intValue = int.Parse (stringValue);
|
||||
//Online o = new Online(intValue);
|
||||
}
|
||||
|
||||
private void ProcessEntities (Block block)
|
||||
private void ProcessEntities (Block entitiesBlock)
|
||||
{
|
||||
backend.clearDragons ();
|
||||
backend.clearPlayers ();
|
||||
foreach (Block entityBlock in entitiesBlock.GetBlocks ()) {
|
||||
switch (entityBlock.GetName()) {
|
||||
case MessPlayer:
|
||||
backend.SetPlayer(MapPlayer(entityBlock));
|
||||
break;
|
||||
case MessDragon:
|
||||
backend.SetDragon(MapDragon(entityBlock));
|
||||
break;
|
||||
default:
|
||||
ThrowUnknownBlockException(entitiesBlock, entityBlock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessPlayers (Block block)
|
||||
private void ProcessPlayers (Block playersBlock)
|
||||
{
|
||||
backend.clearPlayers ();
|
||||
foreach (Block playerBlock in playersBlock.GetBlocks ()) {
|
||||
backend.SetPlayer(MapPlayer(playerBlock));
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessDragon (Block block)
|
||||
private void ProcessDragon (Block dragonBlock)
|
||||
{
|
||||
backend.SetDragon(MapDragon(dragonBlock));
|
||||
}
|
||||
|
||||
private Dragon MapDragon (Block dragonBlock)
|
||||
@@ -298,7 +383,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);
|
||||
@@ -401,22 +486,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user