Map-Zeichen-Logik in extra Klasse verschoben
This commit is contained in:
12
inf3.csproj
12
inf3.csproj
@@ -9,27 +9,26 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>inf3</RootNamespace>
|
<RootNamespace>inf3</RootNamespace>
|
||||||
<AssemblyName>inf3</AssemblyName>
|
<AssemblyName>inf3</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>True</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>False</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug</OutputPath>
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
<DefineConstants>DEBUG;</DefineConstants>
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<ConsolePause>False</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
<Optimize>True</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release</OutputPath>
|
<OutputPath>bin\Release</OutputPath>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<ConsolePause>False</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -80,6 +79,7 @@
|
|||||||
<Compile Include="src\Gui\ChatInputBox.cs" />
|
<Compile Include="src\Gui\ChatInputBox.cs" />
|
||||||
<Compile Include="src\Gui\ChatOutputBox.cs" />
|
<Compile Include="src\Gui\ChatOutputBox.cs" />
|
||||||
<Compile Include="src\Gui\IChatMessage.cs" />
|
<Compile Include="src\Gui\IChatMessage.cs" />
|
||||||
|
<Compile Include="src\Gui\MapPanel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ namespace WorldOfPeacecraft
|
|||||||
{
|
{
|
||||||
class Gui : Form, IGui
|
class Gui : Form, IGui
|
||||||
{
|
{
|
||||||
private const int TileSize = 32;
|
|
||||||
private const int EntitySize = 10;
|
|
||||||
private const int ChatWidth = 300;
|
private const int ChatWidth = 300;
|
||||||
private IBackend Backend;
|
private IBackend Backend;
|
||||||
|
|
||||||
private Panel Board = new Panel();
|
private MapPanel MapPanel;
|
||||||
private ChatPanel ChatPanel;
|
private ChatPanel ChatPanel;
|
||||||
|
|
||||||
public Gui ()
|
public Gui ()
|
||||||
@@ -36,11 +34,11 @@ namespace WorldOfPeacecraft
|
|||||||
public void InitializeComponents ()
|
public void InitializeComponents ()
|
||||||
{
|
{
|
||||||
ChatPanel = new ChatPanel (Backend);
|
ChatPanel = new ChatPanel (Backend);
|
||||||
|
MapPanel = new MapPanel (Backend);
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
this.Size = new Size(400 + ChatWidth, 400);
|
this.Size = new Size(400 + ChatWidth, 400);
|
||||||
Board.Location = new Point(0,0);
|
MapPanel.Location = new Point(0,0);
|
||||||
Board.Size = new Size(400, 400);
|
MapPanel.Size = new Size(400, 400);
|
||||||
Board.Paint += DoPaint;
|
|
||||||
ChatPanel.Location = new Point (400, 0);
|
ChatPanel.Location = new Point (400, 0);
|
||||||
ChatPanel.Size = new Size (300, 400);
|
ChatPanel.Size = new Size (300, 400);
|
||||||
this.DoubleBuffered = true;
|
this.DoubleBuffered = true;
|
||||||
@@ -49,7 +47,7 @@ namespace WorldOfPeacecraft
|
|||||||
this.Name = "WorldOfPeacecraft";
|
this.Name = "WorldOfPeacecraft";
|
||||||
this.ShowIcon = false;
|
this.ShowIcon = false;
|
||||||
|
|
||||||
this.Controls.Add (Board);
|
this.Controls.Add (MapPanel);
|
||||||
this.Controls.Add (ChatPanel);
|
this.Controls.Add (ChatPanel);
|
||||||
|
|
||||||
this.ResumeLayout();
|
this.ResumeLayout();
|
||||||
@@ -61,89 +59,15 @@ namespace WorldOfPeacecraft
|
|||||||
Backend.Stop ();
|
Backend.Stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoPaint (object source, PaintEventArgs args)
|
|
||||||
{
|
|
||||||
BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate (Board.CreateGraphics (), Board.DisplayRectangle);
|
|
||||||
Graphics g = buffer.Graphics;
|
|
||||||
lock (Backend) {
|
|
||||||
PaintMap (g);
|
|
||||||
PaintEntities (g);
|
|
||||||
}
|
|
||||||
buffer.Render();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PaintMap (Graphics g)
|
|
||||||
{
|
|
||||||
ITile[,] map = Backend.GetMap ();
|
|
||||||
if (map != null) {
|
|
||||||
for (int y = 0; y < map.GetLength(1); y++) {
|
|
||||||
for (int x = 0; x < map.GetLength(0); x++) {
|
|
||||||
PaintTile (g, map [x, y], x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g.FillRectangle(new SolidBrush(Color.White), Board.DisplayRectangle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PaintTile (Graphics g, ITile tile, int x, int y)
|
|
||||||
{
|
|
||||||
int posx = x * TileSize;
|
|
||||||
int posy = y * TileSize;
|
|
||||||
Color color;
|
|
||||||
if (tile.IsHuntable ()) {
|
|
||||||
color = Color.DarkGreen;
|
|
||||||
} // Stupid parenthesis
|
|
||||||
else if (tile.IsForest ()) {
|
|
||||||
color = Color.Green;
|
|
||||||
} else if (tile.IsWater ()) {
|
|
||||||
color = Color.Blue;
|
|
||||||
} else if (tile.IsWalkable ()) {
|
|
||||||
color = Color.Yellow;
|
|
||||||
} else if (tile.IsWall ()) {
|
|
||||||
color = Color.DarkGray;
|
|
||||||
} else {
|
|
||||||
color = Color.Black;
|
|
||||||
}
|
|
||||||
g.FillRectangle(new SolidBrush(color), posx, posy, TileSize, TileSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PaintEntities (Graphics g)
|
|
||||||
{
|
|
||||||
IEnumerable<IPositionable> dragons = Backend.GetDragons ();
|
|
||||||
IEnumerable<IPositionable> players = Backend.GetPlayers ();
|
|
||||||
foreach (IPositionable dragon in dragons) {
|
|
||||||
PaintEntity (g, dragon);
|
|
||||||
}
|
|
||||||
foreach (IPositionable player in players) {
|
|
||||||
PaintEntity (g, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PaintEntity (Graphics g, IPositionable entity)
|
|
||||||
{
|
|
||||||
int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2;
|
|
||||||
int y = entity.GetY () * TileSize + TileSize / 2 - EntitySize / 2;
|
|
||||||
g.FillRectangle (new SolidBrush (Color.Red), x, y, EntitySize, EntitySize);
|
|
||||||
g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PerformRefresh ()
|
public void PerformRefresh ()
|
||||||
{
|
{
|
||||||
this.BeginInvoke(new MethodInvoker(delegate
|
this.BeginInvoke(new MethodInvoker(delegate
|
||||||
{
|
{
|
||||||
ITile[,] map = Backend.GetMap();
|
MapPanel.PerformLayout ();
|
||||||
if (map == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int mapWidth = (map.GetLength(0)) * TileSize;
|
|
||||||
int mapHeight = (map.GetLength(1)) * TileSize;
|
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
this.SetClientSizeCore(mapWidth + ChatWidth, mapHeight);
|
this.SetClientSizeCore(MapPanel.Width + ChatWidth, MapPanel.Height);
|
||||||
Board.Size = new Size(mapWidth, mapHeight);
|
ChatPanel.Location = new Point (MapPanel.Width, 0);
|
||||||
ChatPanel.Location = new Point (mapWidth, 0);
|
ChatPanel.Size = new Size (ChatWidth, MapPanel.Height);
|
||||||
ChatPanel.Size = new Size (ChatWidth, mapHeight);
|
|
||||||
this.ResumeLayout();
|
this.ResumeLayout();
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
ChatPanel.UpdateData ();
|
ChatPanel.UpdateData ();
|
||||||
|
|||||||
99
src/Gui/MapPanel.cs
Normal file
99
src/Gui/MapPanel.cs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace WorldOfPeacecraft
|
||||||
|
{
|
||||||
|
public class MapPanel : Panel
|
||||||
|
{
|
||||||
|
private const int TileSize = 32;
|
||||||
|
private const int EntitySize = 10;
|
||||||
|
private IBackend Backend;
|
||||||
|
|
||||||
|
public MapPanel (IBackend backend)
|
||||||
|
{
|
||||||
|
Backend = backend;
|
||||||
|
this.Paint += DoPaint;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLayout (LayoutEventArgs levent)
|
||||||
|
{
|
||||||
|
ITile[,] map = Backend.GetMap ();
|
||||||
|
if (map != null) {
|
||||||
|
int mapWidth = (map.GetLength(0)) * TileSize;
|
||||||
|
int mapHeight = (map.GetLength(1)) * TileSize;
|
||||||
|
this.SetClientSizeCore(mapWidth, mapHeight);
|
||||||
|
}
|
||||||
|
base.OnLayout (levent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DoPaint (object source, PaintEventArgs args)
|
||||||
|
{
|
||||||
|
BufferedGraphics buffer = BufferedGraphicsManager.Current.Allocate (this.CreateGraphics (), this.DisplayRectangle);
|
||||||
|
Graphics g = buffer.Graphics;
|
||||||
|
lock (Backend) {
|
||||||
|
PaintMap (g);
|
||||||
|
PaintEntities (g);
|
||||||
|
}
|
||||||
|
buffer.Render();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PaintMap (Graphics g)
|
||||||
|
{
|
||||||
|
ITile[,] map = Backend.GetMap ();
|
||||||
|
if (map != null) {
|
||||||
|
for (int y = 0; y < map.GetLength(1); y++) {
|
||||||
|
for (int x = 0; x < map.GetLength(0); x++) {
|
||||||
|
PaintTile (g, map [x, y], x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.FillRectangle(new SolidBrush(Color.White), this.DisplayRectangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PaintTile (Graphics g, ITile tile, int x, int y)
|
||||||
|
{
|
||||||
|
int posx = x * TileSize;
|
||||||
|
int posy = y * TileSize;
|
||||||
|
Color color;
|
||||||
|
if (tile.IsHuntable ()) {
|
||||||
|
color = Color.DarkGreen;
|
||||||
|
} // Stupid parenthesis
|
||||||
|
else if (tile.IsForest ()) {
|
||||||
|
color = Color.Green;
|
||||||
|
} else if (tile.IsWater ()) {
|
||||||
|
color = Color.Blue;
|
||||||
|
} else if (tile.IsWalkable ()) {
|
||||||
|
color = Color.Yellow;
|
||||||
|
} else if (tile.IsWall ()) {
|
||||||
|
color = Color.DarkGray;
|
||||||
|
} else {
|
||||||
|
color = Color.Black;
|
||||||
|
}
|
||||||
|
g.FillRectangle(new SolidBrush(color), posx, posy, TileSize, TileSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PaintEntities (Graphics g)
|
||||||
|
{
|
||||||
|
IEnumerable<IPositionable> dragons = Backend.GetDragons ();
|
||||||
|
IEnumerable<IPositionable> players = Backend.GetPlayers ();
|
||||||
|
foreach (IPositionable dragon in dragons) {
|
||||||
|
PaintEntity (g, dragon);
|
||||||
|
}
|
||||||
|
foreach (IPositionable player in players) {
|
||||||
|
PaintEntity (g, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PaintEntity (Graphics g, IPositionable entity)
|
||||||
|
{
|
||||||
|
int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2;
|
||||||
|
int y = entity.GetY () * TileSize + TileSize / 2 - EntitySize / 2;
|
||||||
|
g.FillRectangle (new SolidBrush (Color.Red), x, y, EntitySize, EntitySize);
|
||||||
|
g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user