Backend und Parser + Receiver überarbeitet und unötige Klassen entfernt

This commit is contained in:
2014-04-03 13:04:22 +02:00
parent fc947925a7
commit b8f41e1ee5
10 changed files with 68 additions and 333 deletions

View File

@@ -47,17 +47,13 @@
<Compile Include="src\DefaultGui\IPositionable.cs" /> <Compile Include="src\DefaultGui\IPositionable.cs" />
<Compile Include="src\DefaultGui\ITile.cs" /> <Compile Include="src\DefaultGui\ITile.cs" />
<Compile Include="src\DefaultGui\Program.cs" /> <Compile Include="src\DefaultGui\Program.cs" />
<Compile Include="src\DefaultGui\test\Backend.cs" />
<Compile Include="src\DefaultGui\test\Entity.cs" />
<Compile Include="src\DefaultGui\test\MapCell.cs" />
<Compile Include="src\Dragon.cs" /> <Compile Include="src\Dragon.cs" />
<Compile Include="src\Map.cs" /> <Compile Include="src\Map.cs" />
<Compile Include="src\Program.cs" />
<Compile Include="src\Start.cs" />
<Compile Include="src\Tile.cs" /> <Compile Include="src\Tile.cs" />
<Compile Include="src\Entity.cs" /> <Compile Include="src\Entity.cs" />
<Compile Include="src\Player.cs" /> <Compile Include="src\Player.cs" />
<Compile Include="src\Parser.cs" /> <Compile Include="src\Parser.cs" />
<Compile Include="src\Backend.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="src\DefaultGui\" /> <Folder Include="src\DefaultGui\" />

36
src/Backend.cs Normal file
View File

@@ -0,0 +1,36 @@
using System.Collections.Generic;
using WorldOfPeacecraft;
namespace Frontend
{
public class Backend : IBackend
{
public Backend ()
{
// Unsere Main-Methode
}
public List<Dragon> getDragons()
{
return null;
}
public List<Player> getPlayers()
{
return null;
}
public Tile[][] getMap()
{
return null;
}
public void sendCommand(string command)
{
}
public void sendChat(string message)
{
}
}
}

View File

@@ -11,12 +11,12 @@ namespace Frontend
/// <summary> /// <summary>
/// Der Haupteinstiegspunkt für die Anwendung. /// Der Haupteinstiegspunkt für die Anwendung.
/// </summary> /// </summary>
//[STAThread] [STAThread]
//static void Main() static void Main()
//{ {
// Application.EnableVisualStyles(); Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new DefaultGui(new Backend())); Application.Run(new DefaultGui(new Backend()));
//} }
} }
} }

View File

@@ -1,79 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frontend
{
/// <summary>
/// All classes in the test-directory are just classes to illustrate the concept of the frontend and its interfaces.
/// They are undocumented and not very well written and are using dummy-data with no connection to the actual server.
/// On purpose. Because you should come up with your own implementation. :)
/// </summary>
public class Backend : IBackend
{
public void sendCommand(string command)
{
Console.WriteLine("received command " + command);
}
public void sendChat(string message)
{
Console.WriteLine("received chatmessage " + message);
}
public List<IPositionable> getDragons() {
List<IPositionable> dragons = new List<IPositionable>();
dragons.Add(new Entity(0,1));
return dragons;
}
public List<IPositionable> getPlayers() {
List<IPositionable> players = new List<IPositionable>();
players.Add(new Entity(1, 1));
return players;
}
public ITile[][] getMap()
{
int size = 10;
// init
ITile[][] map = new ITile[size][];
for (int i = 0; i < size; i++)
{
map[i] = new ITile[size];
}
Random r = new Random();
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
List<MapCellAttribute> attr = new List<MapCellAttribute>();
switch (r.Next(0, 5))
{
case 0:
attr.Add(MapCellAttribute.WATER);
break;
case 1:
attr.Add(MapCellAttribute.HUNTABLE);
attr.Add(MapCellAttribute.FOREST);
break;
case 2:
attr.Add(MapCellAttribute.FOREST);
break;
case 3:
attr.Add(MapCellAttribute.UNWALKABLE);
break;
case 4:
break;
}
map[x][y] = new MapCell(x, y, attr);
}
}
return map;
}
}
}

View File

@@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frontend
{
public class Entity : IPositionable
{
int x, y;
public Entity(int x, int y)
{
this.x = x;
this.y = y;
}
public int getXPosition()
{
return this.x;
}
public int getYPosition()
{
return this.y;
}
}
}

View File

@@ -1,53 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frontend
{
public class MapCell : ITile
{
private int x,y;
private List<MapCellAttribute> attributes;
public MapCell(int x, int y, List<MapCellAttribute> attributes)
{
this.x = x;
this.y = y;
this.attributes = new List<MapCellAttribute>();
this.attributes.AddRange(attributes);
}
public int getXPosition()
{
return this.x;
}
public int getYPosition()
{
return this.y;
}
public bool isWalkable()
{
return !this.attributes.Contains(MapCellAttribute.UNWALKABLE);
}
public bool isForest()
{
return this.attributes.Contains(MapCellAttribute.FOREST);
}
public bool isHuntable()
{
return this.attributes.Contains(MapCellAttribute.HUNTABLE);
}
public bool isWater()
{
return this.attributes.Contains(MapCellAttribute.WATER);
}
}
public enum MapCellAttribute {UNWALKABLE, WATER, FOREST, HUNTABLE}
}

View File

@@ -1,106 +1,34 @@
using System; using System;
using System.Threading;
using System.Collections.Generic;
namespace WorldOfPeacecraft namespace WorldOfPeacecraft
{ {
public class Parser public class Parser
{ {
private string fromServer; private Queue<string> Buffer;
private string toServer; private Thread ParserThread;
public void convertIncoming(string fromServer) public Parser()
{ {
Buffer = new Queue<string>();
} }
public void convertOutgoing(string toServer) public void DoParse ()
{ {
while (true) {
// Do awesome stuff
}
} }
public void setMe() public void Stop ()
{ {
ParserThread.Abort();
} }
public object getDragons() public void AddToBuffer(string s)
{ {
return null; Buffer.Enqueue(s);
}
public void getEnt()
{
}
public void getMe()
{
}
public void getMap()
{
}
public void getUsers()
{
}
public void getTime()
{
}
public void getOnline()
{
}
public void chat(String msg)
{
}
public void exit()
{
}
public void setOnlineInt(int online)
{
}
public int getOnlineInt()
{
return 0;
}
public void setPlayers()
{
}
public void getMes()
{
}
public void setMap()
{
}
public string getTimeFromServer()
{
return null;
}
public void setDragons()
{
} }
} }
} }

View File

@@ -1,51 +0,0 @@
using System.Net.Sockets;
using System.Threading;
using System;
using WorldOfPeacecraft;
public class Program
{
private Receiver Rec;
private Sender Send;
private Thread SenderThread;
private Thread ReceiverThread;
public static void Main ()
{
Program program = new Program();
program.StartThreads();
}
public Program ()
{
TcpClient client = new TcpClient ("localhost", 9999);
Rec = new Receiver (client);
Send = new Sender (client);
}
public void StartThreads ()
{
ReceiverThread = new Thread(new ThreadStart(this.doReceive));
ReceiverThread.Start ();
SenderThread = new Thread(new ThreadStart(this.doSend));
SenderThread.Start();
}
public void doReceive ()
{
string line;
while ((line = Rec.Receive()) != null)
{
Console.WriteLine(line);
}
SenderThread.Abort();
}
public void doSend ()
{
while (true) {
Send.Send(Console.ReadLine());
}
}
}

View File

@@ -6,13 +6,13 @@ namespace WorldOfPeacecraft
{ {
class Receiver class Receiver
{ {
private TcpClient Client;
private StreamReader Reader; private StreamReader Reader;
private Parser Parser;
public Receiver (TcpClient client) public Receiver (TcpClient client, Parser parser)
{ {
this.Client = client; this.Parser = parser;
this.Reader = new StreamReader (Client.GetStream ()); this.Reader = new StreamReader (client.GetStream ());
} }
public string Receive () public string Receive ()

View File

@@ -1,14 +0,0 @@
using System;
using System.Threading;
using System.Net.Sockets;
public class Start
{
//public static void Main()
//{
// TcpClient client = new TcpClient("localhost", 9999);
// Program program = new Program(client);
// program.StartThreads();
//}
}