Projektdatei committed

This commit is contained in:
2014-04-03 10:33:41 +02:00
parent aa1e295425
commit 46b820f2b6
21 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Connector
{
class Program
{
static void connect()
{
Thread t1, t2;
Receiver receiver = new Receiver();
Sender sender = new Sender();
String message = Console.ReadLine();
t1 = new Thread(() => receiver.receive());
t2 = new Thread(() => sender.send(message));
t1.Start();
t2.Start();
}
static void Main(string[] args)
{
connect();
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Connector
{
class Receiver
{
Int32 port = 80;
private TcpClient client;
private NetworkStream inStream;
Byte[] data;
public void receive()
{
client = new TcpClient("localhost", port);
inStream = client.GetStream();
data = new Byte[256];
String responseData = String.Empty;
Int32 bytes = inStream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
Console.WriteLine("Received: {0}", responseData);
inStream.Close();
client.Close();
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Connector
{
class Sender
{
Int32 port = 80;
private TcpClient client;
private NetworkStream outStream;
Byte[] data;
// ASCIIEncoding encoder;
// byte[] buffer;
public void send(string message)
{
//buffer = encoder.GetBytes(message);
client = new TcpClient("localhost", port);
data = System.Text.Encoding.ASCII.GetBytes(message);
outStream = client.GetStream();
//message = Console.ReadLine();
outStream.Write(data, 0, data.Length);
Console.WriteLine("Sent: {0}", message);
outStream.Close();
client.Close();
}
}
}

87
src/DefaultGui/DefaultGui.Designer.cs generated Normal file
View File

@@ -0,0 +1,87 @@
namespace Frontend
{
partial class DefaultGui
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.chatInput = new System.Windows.Forms.TextBox();
this.chatWindow = new System.Windows.Forms.RichTextBox();
this.board = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// chatInput
//
this.chatInput.BackColor = System.Drawing.SystemColors.Window;
this.chatInput.Location = new System.Drawing.Point(23, 455);
this.chatInput.Name = "chatInput";
this.chatInput.Size = new System.Drawing.Size(350, 20);
this.chatInput.TabIndex = 0;
//
// chatWindow
//
this.chatWindow.Location = new System.Drawing.Point(23, 368);
this.chatWindow.Name = "chatWindow";
this.chatWindow.ReadOnly = true;
this.chatWindow.Size = new System.Drawing.Size(350, 81);
this.chatWindow.TabIndex = 1;
this.chatWindow.Text = "";
//
// board
//
this.board.Location = new System.Drawing.Point(23, 12);
this.board.Name = "board";
this.board.Size = new System.Drawing.Size(350, 350);
this.board.TabIndex = 2;
//
// DefaultGui
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(398, 487);
this.Controls.Add(this.board);
this.Controls.Add(this.chatWindow);
this.Controls.Add(this.chatInput);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "DefaultGui";
this.ShowIcon = false;
this.Text = "Default GUI";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox chatInput;
private System.Windows.Forms.RichTextBox chatWindow;
private System.Windows.Forms.Panel board;
}
}

View File

@@ -0,0 +1,274 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Frontend
{
/// <summary>
/// This is a very, very basic GUI. It communicates with any IBackend, takes the map and existing entities and renders them in a generic fashion.
/// The space will be devided evenly among the ITiles of a map. That means: bigger maps will result in very tiny cells on the GUI.
/// No scrolling or any fancy mechanisms.
/// Entities will also be displayed in a generic way: players are rendered in yellow, dragons are red. No IDs, names or whatsoever.
/// It also offers basic functionality to communicate with the backend to input commands via the chat. So you can do some testing by manually entering commands like "/get:map".
/// The GUI also consists of a chat-window, featuring incoming chat-messages and a input-box, to send messages to the IBackend (which have to be handled there!).
/// Pressing ENTER sends the text in the input-box and also switches between chat-mode and walk-mode. In walk-mode, pressing WASD causes the frontend to send move-commands to the IBackend.
/// As you can see, this is just rudimentary functionality and rendering and you might wish (and are invited) to extend the class, modify the existing sourcecode or even write your very own implementation to have a more appealing GUI that fits your needs.
///
/// To get this to work, you will have to let your backend implemented the provided IBackend-interface (and of course the other provided interfaces where needed). Then
/// </summary>
public partial class DefaultGui : Form
{
private IBackend backend;
public DefaultGui(IBackend backend) : base()
{
if (backend == null)
{
throw new ArgumentNullException("invalid value for 'backend': null");
}
this.backend = backend;
InitializeComponent();
// we usually don't have a console in a form-project. This enables us to see debug-output anyway
AllocConsole();
this.board.Paint += board_PaintMap;
this.board.Paint += board_PaintEntities;
this.chatInput.KeyPress += chat_KeyPress;
this.board.KeyPress += board_KeyPress;
}
/// <summary>
/// Handles keypresses the chatInput-field receives.
/// Having ENTER pressed, causes the field to be emptied and have the trimmed text in the field sent to the backend.
/// If the input starts with "/", it will be handled as command (like ask:mv:up and such).
/// All other messages will be treated as chat-messages and have to be wrapped by the backend as such.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void chat_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Enter)
{
string input = this.chatInput.Text.Trim();
this.chatInput.Text = "";
// ignore empty input
if (input != "")
{
if (input.StartsWith("/"))
{
input = input.Substring(1, input.Length-1);
this.backend.sendCommand(input);
}
else
{
this.backend.sendChat(input);
}
}
this.board.Focus();
}
}
/// <summary>
/// Handles keypresses when the board is focused. This is whenever the chatinput is NOT focused.
/// Will handle WASD as triggers for the movement.
/// A: left
/// W: up
/// S: down
/// D: right
/// Pressing ENTER causes the chatinput to be focused again.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void board_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
// fall-through-cases for capital letters
switch (e.KeyChar)
{
case (char)Keys.Enter:
this.chatInput.Focus();
break;
case 'a':
case 'A':
this.backend.sendCommand("ask:mv:lft");
break;
case 'd':
case 'D':
this.backend.sendCommand("ask:mv:rgt");
break;
case 'w':
case 'W':
this.backend.sendCommand("ask:mv:up");
break;
case 's':
case 'S':
this.backend.sendCommand("ask:mv:dwn");
break;
}
}
/// <summary>
/// Handler to paint the tiles in the map
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void board_PaintMap(object sender, System.Windows.Forms.PaintEventArgs e) {
Size tileSize = this.getTileSize();
ITile[][] cells = this.backend.getMap();
// validity checked beforehand in getTileSize
Debug.Assert(cells != null);
BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate(this.board.CreateGraphics(), this.board.DisplayRectangle);
Graphics g = this.CreateGraphics();
for(int x = 0; x < cells.Length; x++) {
for(int y = 0; y < cells[x].Length; y++) {
this.drawMapTile(buffer.Graphics, cells[x][y], x * tileSize.Width, y * tileSize.Height, tileSize.Width, tileSize.Height);
}
}
buffer.Render();
}
/// <summary>
/// Handler to paint all entities Dragons first, then the Players
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void board_PaintEntities(object sender, System.Windows.Forms.PaintEventArgs e)
{
List<IPositionable> dragons = this.backend.getDragons();
foreach (IPositionable dragon in dragons)
{
this.drawDragon(e.Graphics, dragon);
}
List<IPositionable> players = this.backend.getPlayers();
foreach (IPositionable player in players)
{
this.drawPlayer(e.Graphics, player);
}
}
/// <summary>
/// Draws a tile of the map on a graphics object.
/// By default, it will draw a rectangle (colour will be dependent of the attributes of the tile).
/// WATER: blue
/// FOREST: dark green
/// HUNTABLE: light green
/// UNWALKABLE: grey
/// else: peach
/// It will have a black 1px border.
/// </summary>
/// <param name="g">the graphics-object to draw on</param>
/// <param name="tile">the tile-object that implements ITile</param>
/// <param name="absX">absolute pixel x-position of the upper left corner of the tile, relative to the upper left corner of the graphics-object</param>
/// <param name="absY">absolute pixel y-position of the upper left corner of the tile, relative to the upper left corner of the graphics-object</param>
/// <param name="width">width of the tile in pixels</param>
/// <param name="height">height of the tile in pixels</param>
protected void drawMapTile(Graphics g, ITile tile, int absX, int absY, int width, int height)
{
Color colour = Color.BurlyWood;
if (tile.isForest())
{
if (tile.isHuntable())
{
colour = Color.YellowGreen;
}
else
{
colour = Color.Green;
}
}
else if (tile.isWater())
{
colour = Color.Blue;
}
else if (!tile.isWalkable())
{
colour = Color.DimGray;
}
g.FillRectangle(new SolidBrush(colour), absX, absY, width, height);
g.DrawRectangle(new Pen(new SolidBrush(Color.Black)), new Rectangle(absX, absY, width, height));
}
/// <summary>
/// Draws a player on the graphics.
/// By default, players will be represented by a centered dark-yellow rectangle that takes up half of the cells size.
/// </summary>
/// <param name="g">the graphics-object to draw on</param>
/// <param name="player">the player to draw</param>
protected void drawPlayer(Graphics g, IPositionable player)
{
Size tileSize = this.getTileSize();
g.FillRectangle(new SolidBrush(Color.DarkGoldenrod),
player.getXPosition() * tileSize.Width + tileSize.Width / 2 - tileSize.Width / 4,
player.getYPosition() * tileSize.Height + tileSize.Height / 2 - tileSize.Height / 4,
tileSize.Width/2,
tileSize.Height/2);
}
/// <summary>
/// Draws a dragon on the graphics.
/// By default, dragons will be represented by a centered red rectangle that takes up half of the cells size.
/// </summary>
/// <param name="g">the graphics-object to draw on</param>
/// <param name="dragon">the dragon to draw</param>
protected void drawDragon(Graphics g, IPositionable dragon)
{
Size tileSize = this.getTileSize();
g.FillRectangle(new SolidBrush(Color.DarkRed),
dragon.getXPosition() * tileSize.Width + tileSize.Width / 2 - tileSize.Width / 4,
dragon.getYPosition() * tileSize.Height + tileSize.Height / 2 - tileSize.Height / 4,
tileSize.Width / 2,
tileSize.Height / 2);
}
/// <summary>
/// Devides the space of the board-panel equally among the tiles of the map.
/// For intance, if the board is 100px wide and the map consists of 5 cells in y-direction
/// each tile will have a width of 100px/5 = 20px. Same for the height.
/// </summary>
/// <returns>the size of one tile to fit the whole map on the board</returns>
protected Size getTileSize()
{
IPositionable[][] cells = this.backend.getMap();
if (cells == null)
{
throw new ArgumentNullException("backend returned null as map");
}
if (cells.Length == 0)
{
throw new IndexOutOfRangeException("outer dimension of the retrieved map has length 0");
}
if (cells[0].Length == 0)
{
throw new IndexOutOfRangeException("inner dimension of the retrieved map has length 0");
}
int cellWidth = this.board.Size.Width / cells.Length;
int cellHeight = this.board.Size.Height / cells[0].Length;
return new Size(cellWidth, cellHeight);
}
/// <summary>
/// Appends a chat-message to the chat-window as a new line. Can be called from the backend or other participants to display incoming chat-messages.
/// Messages will always be displays in the fasion of:
/// sender: message
/// </summary>
/// <param name="sender">the source of the message</param>
/// <param name="message">the message itself</param>
public void appendChatMessage(string sender, string message)
{
this.chatWindow.AppendText(sender + ": " + message + "\r\n");
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frontend
{
/// <summary>
/// Interface that should be implemented by the class that represents your backend.
/// </summary>
public interface IBackend
{
/// <summary>
/// Method to get an arbitrary collection of dragons
/// </summary>
/// <returns>a list of dragons that are currently on the map</returns>
List<IPositionable> getDragons();
/// <summary>
/// Method to get an arbitrary collection of players
/// </summary>
/// <returns>list of players that are currently on the map</returns>
List<IPositionable> getPlayers();
/// <summary>
/// Method to get a 2d-grid-representation of the map. The map doesn't actually has to be a 2d-array, but you should
/// somehow be able to convert it into one.
/// </summary>
/// <returns>a 2d-array of ITiles, representing the map</returns>
ITile[][] getMap();
/// <summary>
/// Sends a command to the server (such as ask:mv:dwn)
/// </summary>
/// <param name="command">the command to send</param>
void sendCommand(string command);
/// <summary>
/// Sends a chatmessage to broadcast. This is basically any text, wrapped in the chat-command.
/// So this method will ultimately call sendCommand() after forming a chat-command from the text.
/// </summary>
/// <param name="message">the text to send as chatmessage</param>
void sendChat(string message);
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frontend
{
/// <summary>
/// Interface your positionable objects should implement. Such as the dragons and players.
/// This enables the frontend to determine the current position of said objects to render them at the correct space.
/// </summary>
public interface IPositionable
{
/// <summary>
/// Getter for the x-position
/// </summary>
/// <returns>the x-position</returns>
int getXPosition();
/// <summary>
/// Getter for the y-position
/// </summary>
/// <returns>the y-position</returns>
int getYPosition();
}
}

20
src/DefaultGui/ITile.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Frontend
{
/// <summary>
/// Interface that should be implemented by your class that represents one field in the grid.
/// It has to provide methods to check for its properties, which are independed from the way you actually store those properties.
/// </summary>
public interface ITile : IPositionable
{
bool isWalkable();
bool isForest();
bool isHuntable();
bool isWater();
}
}

22
src/DefaultGui/Program.cs Normal file
View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Frontend
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new DefaultGui(new Backend()));
}
}
}

View File

@@ -0,0 +1,79 @@
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

@@ -0,0 +1,28 @@
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

@@ -0,0 +1,53 @@
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}
}

89
src/Dragon.cs Normal file
View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Dragon
{
public int id;
public int posX;
public int posY;
public int points;
public string type;
public bool busy;
public Dragon(int id, int posX, int posY, int points, string type, bool busy)
{
this.setId(id);
this.setPosX(posX);
this.setPosY(posY);
this.setPoints(points);
this.setType(type);
this.setBusy(busy);
}
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return id;
}
public void setPosX(int x)
{
this.posX = x;
}
public int getPosX()
{
return posX;
}
public void setPosY(int y)
{
this.posY = y;
}
public int getPosY()
{
return posY;
}
public void setPoints(int points)
{
this.points = points;
}
public int getPoints()
{
return points;
}
public void setType(string type)
{
this.type = type;
}
public string getType()
{
return type;
}
public void setBusy(bool busy)
{
this.busy = busy;
}
public bool getBusy()
{
return busy;
}
}

28
src/Map.cs Normal file
View File

@@ -0,0 +1,28 @@
using System;
public class Map
{
public Tile[,] map;
public Map(int height, int width)
{
map = new Tile[height, width];
}
public void setTile(Tile t)
{
int x= t.getX();
int y= t.getY();
map.SetValue(t, x, y);
}
public Tile getTile(int x, int y)
{
return map.GetValue(x,y);
}
}

89
src/Player.cs Normal file
View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Player
{
public int id;
public int posX;
public int posY;
public int points;
public string type;
public bool busy;
public Player(int id, int posX, int posY, int points, string type, bool busy)
{
this.setId(id);
this.setPosX(posX);
this.setPosY(posY);
this.setPoints(points);
this.setType(type);
this.setBusy(busy);
}
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return id;
}
public void setPosX(int x)
{
this.posX = x;
}
public int getPosX()
{
return posX;
}
public void setPosY(int y)
{
this.posY = y;
}
public int getPosY()
{
return posY;
}
public void setPoints(int points)
{
this.points = points;
}
public int getPoints()
{
return points;
}
public void setType(string type)
{
this.type = type;
}
public string getType()
{
return type;
}
public void setBusy(bool busy)
{
this.busy = busy;
}
public bool getBusy()
{
return busy;
}
}

50
src/Program.cs Normal file
View File

@@ -0,0 +1,50 @@
using System.Net.Sockets;
using System.Threading;
using System;
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());
}
}
}

21
src/Receiver.cs Normal file
View File

@@ -0,0 +1,21 @@
using System;
using System.IO;
using System.Net.Sockets;
class Receiver
{
private TcpClient Client;
private StreamReader Reader;
public Receiver (TcpClient client)
{
this.Client = client;
this.Reader = new StreamReader(Client.GetStream());
}
public string Receive ()
{
return Reader.ReadLine();
}
}

21
src/Sender.cs Normal file
View File

@@ -0,0 +1,21 @@
using System;
using System.IO;
using System.Net.Sockets;
using System.Text;
public class Sender
{
private TcpClient Client;
public Sender (TcpClient client)
{
this.Client = client;
}
public void Send (String message)
{
StreamWriter writer = new StreamWriter(Client.GetStream());
writer.WriteLine(message);
writer.Flush();
}
}

14
src/Start.cs Normal file
View File

@@ -0,0 +1,14 @@
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();
}
}

111
src/Tile.cs Normal file
View File

@@ -0,0 +1,111 @@
using System;
class Tile
{
public int x;
public int y;
public Dragon drag;
public Player playr;
public bool isWalkable;
public bool isForest;
public bool isHuntable;
public bool isWater;
public Tile(int posX, int posY, bool walkable, bool forest, bool huntable, bool water)
{
this.setX(posX);
this.setY(posY);
this.setWalkable(walkable);
this.setForest(forest);
this.setHuntable(huntable);
this.setWater(water);
}
public void setX(int x)
{
this.x = x;
}
public int getX()
{
return x;
}
public void setY(int y)
{
this.y = y;
}
public int getY()
{
return y;
}
public void setDragon(Dragon drag)
{
this.drag = drag;
}
public Dragon getDragon()
{
return drag;
}
public void setPlayer(Player playr)
{
this.playr = playr;
}
public Player getPlayer()
{
return playr;
}
public void setWalkable(bool walkable)
{
this.isWalkable = walkable;
}
public bool getWalkable()
{
return isWalkable;
}
public void setForest(bool forest)
{
this.isForest = forest;
}
public bool getForest()
{
return isForest;
}
public void setHuntable(bool huntable)
{
this.isHuntable = huntable;
}
public bool getHuntable()
{
return isHuntable;
}
public void setWater(bool water)
{
this.isWater = water;
}
public bool getWater()
{
return isWater;
}
}