Player online list

This commit is contained in:
2014-05-09 10:38:08 +02:00
parent d0c9ec348b
commit b74a7aa301
7 changed files with 68 additions and 14 deletions

View File

@@ -9,28 +9,27 @@
<OutputType>Exe</OutputType>
<RootNamespace>inf3</RootNamespace>
<AssemblyName>inf3</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>True</DebugSymbols>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<ConsolePause>False</ConsolePause>
<ConsolePause>false</ConsolePause>
<additionalargs>/unsafe</additionalargs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<ConsolePause>False</ConsolePause>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -76,6 +75,8 @@
<Compile Include="src\Gui\MapPanel.cs" />
<Compile Include="src\Pathfinder.cs" />
<Compile Include="src\Gui\IEntity.cs" />
<Compile Include="src\Gui\OnlinePlayerList.cs" />
<Compile Include="src\Gui\IPlayer.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>

View File

@@ -45,7 +45,7 @@ namespace WorldOfPeacecraft
return Dragons.Values;
}
public IEnumerable<IEntity> GetPlayers ()
public IEnumerable<IPlayer> GetPlayers ()
{
return Players.Values;
}

View File

@@ -9,10 +9,12 @@ namespace WorldOfPeacecraft
class Gui : Form, IGui
{
private const int ChatWidth = 300;
private const int OnlinePlayerWidth = 100;
private IBackend Backend;
private MapPanel MapPanel;
private ChatPanel ChatPanel;
private OnlinePlayerList OnlinePlayerList;
public Gui ()
{
@@ -40,11 +42,14 @@ namespace WorldOfPeacecraft
{
ChatPanel = new ChatPanel (Backend);
MapPanel = new MapPanel (Backend);
OnlinePlayerList = new OnlinePlayerList (Backend);
this.SuspendLayout();
this.Size = new Size(400 + ChatWidth, 400);
MapPanel.Location = new Point(0,0);
this.Size = new Size(OnlinePlayerWidth + 400 + ChatWidth, 400);
OnlinePlayerList.Location = new Point(0,0);
OnlinePlayerList.Size = new Size(OnlinePlayerWidth, 400);
MapPanel.Location = new Point(OnlinePlayerWidth,0);
MapPanel.Size = new Size(400, 400);
ChatPanel.Location = new Point (400, 0);
ChatPanel.Location = new Point (OnlinePlayerWidth + 400, 0);
ChatPanel.Size = new Size (300, 400);
this.DoubleBuffered = true;
this.MaximizeBox = false;
@@ -52,6 +57,7 @@ namespace WorldOfPeacecraft
this.Text = "World of Peacecraft";
this.ShowIcon = false;
this.Controls.Add (OnlinePlayerList);
this.Controls.Add (MapPanel);
this.Controls.Add (ChatPanel);
@@ -70,8 +76,10 @@ namespace WorldOfPeacecraft
{
MapPanel.PerformLayout ();
this.SuspendLayout();
this.SetClientSizeCore(MapPanel.Width + ChatWidth, MapPanel.Height);
ChatPanel.Location = new Point (MapPanel.Width, 0);
this.SetClientSizeCore(OnlinePlayerWidth + MapPanel.Width + ChatWidth, MapPanel.Height);
OnlinePlayerList.Size = new Size(OnlinePlayerWidth, MapPanel.Height);
MapPanel.Location = new Point(OnlinePlayerWidth, 0);
ChatPanel.Location = new Point (OnlinePlayerWidth + MapPanel.Width, 0);
ChatPanel.Size = new Size (ChatWidth, MapPanel.Height);
this.ResumeLayout();
ChatPanel.UpdateData ();

View File

@@ -6,7 +6,7 @@ namespace WorldOfPeacecraft
{
ITile[,] GetMap();
IEnumerable<IEntity> GetPlayers();
IEnumerable<IPlayer> GetPlayers();
IEnumerable<IEntity> GetDragons();

7
src/Gui/IPlayer.cs Normal file
View File

@@ -0,0 +1,7 @@
namespace WorldOfPeacecraft
{
public interface IPlayer : IEntity
{
string GetName();
}
}

View File

@@ -0,0 +1,33 @@
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WorldOfPeacecraft
{
public class OnlinePlayerList : Panel
{
private IBackend Backend;
public OnlinePlayerList(IBackend backend)
{
this.Backend = backend;
SetStyle (ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
Font = new Font(Font, FontStyle.Bold);
}
protected override void OnPaint (PaintEventArgs e)
{
base.OnPaint (e);
Graphics g = e.Graphics;
g.FillRectangle (new SolidBrush (Color.White), this.DisplayRectangle);
g.DrawRectangle (new Pen(new SolidBrush (Color.Black)), 0, 0, Width - 1, Height - 1);
IEnumerable<IPlayer> players = Backend.GetPlayers ();
int count = 0;
Brush brush = new SolidBrush(Color.Black);
foreach (IPlayer player in players) {
g.DrawString(player.GetName(), Font, brush, 20, 10 + 20 * count);
count++;
}
}
}
}

View File

@@ -1,6 +1,6 @@
namespace WorldOfPeacecraft
{
public class Player : Entity
public class Player : Entity, IPlayer
{
private int Score;
@@ -19,6 +19,11 @@ namespace WorldOfPeacecraft
return Score;
}
public string GetName ()
{
return Desc;
}
public override string ToString()
{
return "Player: " + Id + " " + Coord.X + " " + Coord.Y + " " + Desc + " " + Busy + " " + Score;