Test Commit mit ParserTestKlasse
This commit is contained in:
11
DummyBackend.cs
Normal file
11
DummyBackend.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace inf3
|
||||
{
|
||||
class DummyBackend
|
||||
{
|
||||
}
|
||||
}
|
||||
40
ParserTest.cs
Normal file
40
ParserTest.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Frontend;
|
||||
using WorldOfPeacecraft;
|
||||
using System.Threading;
|
||||
|
||||
namespace inf3
|
||||
{
|
||||
public class ParserTest
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
Parser p = new Parser();
|
||||
|
||||
p.AddToBuffer("begin:5");
|
||||
//Console.WriteLine(p.getBuffer().Dequeue());
|
||||
p.AddToBuffer("begin:upd");
|
||||
p.AddToBuffer("begin:player");
|
||||
p.AddToBuffer("id:3");
|
||||
p.AddToBuffer("typ:Player");
|
||||
p.AddToBuffer("busy:false");
|
||||
p.AddToBuffer("desc:Player3");
|
||||
p.AddToBuffer("x:3");
|
||||
p.AddToBuffer("y:15");
|
||||
p.AddToBuffer("points:0");
|
||||
p.AddToBuffer("end:player");
|
||||
p.AddToBuffer("end:upd");
|
||||
p.AddToBuffer("end:5");
|
||||
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
Console.WriteLine(p.getDummyPlayer());
|
||||
Console.ReadLine();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
inf3.csproj
12
inf3.csproj
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -39,10 +39,14 @@
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DummyBackend.cs" />
|
||||
<Compile Include="ParserTest.cs" />
|
||||
<Compile Include="src\Receiver.cs" />
|
||||
<Compile Include="src\Sender.cs" />
|
||||
<Compile Include="src\DefaultGui\DefaultGui.Designer.cs" />
|
||||
<Compile Include="src\DefaultGui\DefaultGui.cs" />
|
||||
<Compile Include="src\DefaultGui\DefaultGui.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="src\DefaultGui\IBackend.cs" />
|
||||
<Compile Include="src\DefaultGui\IPositionable.cs" />
|
||||
<Compile Include="src\DefaultGui\ITile.cs" />
|
||||
@@ -57,7 +61,5 @@
|
||||
<Compile Include="src\StringUtils.cs" />
|
||||
<Compile Include="src\ParsingException.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="src\DefaultGui\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
</Project>
|
||||
@@ -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()));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,5 +18,10 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
return Score;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Player: " + Id + " " + PosX + " " + PosY + " " + Desc + " " + Busy + " " + Score;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user