Bilder in GUI eingebunden
This commit is contained in:
7
IEntity.cs
Normal file
7
IEntity.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
public interface IEntity : IPositionable
|
||||
{
|
||||
int GetId();
|
||||
}
|
||||
}
|
||||
12
inf3.csproj
12
inf3.csproj
@@ -9,27 +9,28 @@
|
||||
<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>
|
||||
@@ -74,6 +75,7 @@
|
||||
<Compile Include="src\Gui\IChatMessage.cs" />
|
||||
<Compile Include="src\Gui\MapPanel.cs" />
|
||||
<Compile Include="src\Pathfinder.cs" />
|
||||
<Compile Include="IEntity.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -40,12 +40,12 @@ namespace WorldOfPeacecraft
|
||||
this.SelfId = id;
|
||||
}
|
||||
|
||||
public IEnumerable<IPositionable> GetDragons ()
|
||||
public IEnumerable<IEntity> GetDragons ()
|
||||
{
|
||||
return Dragons.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<IPositionable> GetPlayers ()
|
||||
public IEnumerable<IEntity> GetPlayers ()
|
||||
{
|
||||
return Players.Values;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
public abstract class Entity : IPositionable
|
||||
public abstract class Entity : IEntity
|
||||
{
|
||||
public int Id;
|
||||
public Coordinate Coord;
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace WorldOfPeacecraft
|
||||
{
|
||||
ITile[,] GetMap();
|
||||
|
||||
IEnumerable<IPositionable> GetPlayers();
|
||||
IEnumerable<IEntity> GetPlayers();
|
||||
|
||||
IEnumerable<IPositionable> GetDragons();
|
||||
IEnumerable<IEntity> GetDragons();
|
||||
|
||||
IEnumerable<IChatMessage> GetChatMessages();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
@@ -10,11 +11,31 @@ namespace WorldOfPeacecraft
|
||||
private const int EntitySize = 10;
|
||||
private IBackend Backend;
|
||||
|
||||
private string ImagesFolder = "textures/";
|
||||
private Image BowAndArrow;
|
||||
private Image Dragon1;
|
||||
private Image Dragon2;
|
||||
private Image Dragon3;
|
||||
private Image Forest;
|
||||
private Image Knight;
|
||||
private Image Walkable;
|
||||
private Image Water;
|
||||
private Dictionary<int, int> dragonImageMappings = new Dictionary<int, int>();
|
||||
private Random random = new Random ();
|
||||
|
||||
public MapPanel (IBackend backend)
|
||||
{
|
||||
Backend = backend;
|
||||
this.Paint += DoPaint;
|
||||
this.PreviewKeyDown += board_KeyPress;
|
||||
this.PreviewKeyDown += board_KeyPress;
|
||||
BowAndArrow = Image.FromFile (ImagesFolder + "bow-and-arrow.png", false);
|
||||
Dragon1 = Image.FromFile (ImagesFolder + "dragon1.png");
|
||||
Dragon2 = Image.FromFile (ImagesFolder + "dragon2.png");
|
||||
Dragon3 = Image.FromFile (ImagesFolder + "dragon3.png");
|
||||
Forest = Image.FromFile (ImagesFolder + "forest.png");
|
||||
Knight = Image.FromFile (ImagesFolder + "knight.png");
|
||||
Walkable = Image.FromFile (ImagesFolder + "walkable.jpg");
|
||||
Water = Image.FromFile (ImagesFolder + "water.jpg");
|
||||
}
|
||||
|
||||
protected override void OnLayout (LayoutEventArgs levent)
|
||||
@@ -72,7 +93,9 @@ namespace WorldOfPeacecraft
|
||||
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);
|
||||
int posx = x * TileSize;
|
||||
int posy = y * TileSize;
|
||||
PaintTile (g, map [x, y], posx, posy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,44 +106,71 @@ namespace WorldOfPeacecraft
|
||||
|
||||
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;
|
||||
Image image = null;
|
||||
if (tile.IsWater ()) {
|
||||
image = Water;
|
||||
}
|
||||
else {
|
||||
image = Walkable;
|
||||
}
|
||||
if (image != null) {
|
||||
PaintImage (g, x, y, image);
|
||||
} else {
|
||||
g.FillRectangle(new SolidBrush(Color.Red), x, y, TileSize, TileSize);
|
||||
}
|
||||
if (tile.IsWall ()) {
|
||||
g.FillEllipse(new SolidBrush(Color.Gray), x + 3, y + 3, TileSize - 6 , TileSize - 6);
|
||||
}
|
||||
if (tile.IsForest ()) {
|
||||
PaintImage (g, x, y, Forest);
|
||||
}
|
||||
if (tile.IsHuntable ()) {
|
||||
PaintImage (g, x, y, BowAndArrow);
|
||||
}
|
||||
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, Color.Red);
|
||||
IEnumerable<IEntity> dragons = Backend.GetDragons ();
|
||||
IEnumerable<IEntity> players = Backend.GetPlayers ();
|
||||
foreach (IEntity dragon in dragons) {
|
||||
int id = dragon.GetId();
|
||||
if (!dragonImageMappings.ContainsKey(id))
|
||||
{
|
||||
dragonImageMappings[id] = random.Next (3);
|
||||
}
|
||||
Image image;
|
||||
switch (dragonImageMappings[id])
|
||||
{
|
||||
case 0:
|
||||
image = Dragon1;
|
||||
break;
|
||||
case 1:
|
||||
image = Dragon2;
|
||||
break;
|
||||
case 2:
|
||||
image = Dragon3;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("dragonImageMapping '" + dragonImageMappings[id] + "' doesn't exist");
|
||||
}
|
||||
PaintImage(g, dragon.GetX() * TileSize, dragon.GetY() * TileSize, image);
|
||||
}
|
||||
foreach (IPositionable player in players) {
|
||||
PaintEntity (g, player, Color.LightGreen);
|
||||
foreach (IEntity player in players) {
|
||||
PaintImage(g, player.GetX() * TileSize, player.GetY () * TileSize, Knight);
|
||||
}
|
||||
}
|
||||
|
||||
public void PaintImage (Graphics g, int posx, int posy, Image image)
|
||||
{
|
||||
int x = posx + (TileSize - image.Width) / 2;
|
||||
int y = posy + (TileSize - image.Height) / 2;
|
||||
g.DrawImage(image, x, y, image.Width, image.Height);
|
||||
}
|
||||
|
||||
public void PaintEntity (Graphics g, IPositionable entity, Color color)
|
||||
{
|
||||
int x = entity.GetX () * TileSize + TileSize / 2 - EntitySize / 2;
|
||||
int y = entity.GetY () * TileSize + TileSize / 2 - EntitySize / 2;
|
||||
g.FillRectangle (new SolidBrush (color), x, y, EntitySize, EntitySize);
|
||||
g.DrawRectangle (new Pen( new SolidBrush (Color.Black)), x, y, EntitySize, EntitySize);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user