Dodano grafiki domu, śmieciarki i skrzyżowania, interfejs IObject po którym dziedziczą obiekty na mapie, model śmieciarki i drogi, zmieniono nazwę Home.cs na House.cs, dodano pole Object w Tile, ale usunięto atrybut Background. Dodano łączenie obrazków i rysowanie śmieciarki.
This commit is contained in:
parent
bc8c6ae912
commit
22814fc944
@ -13,5 +13,6 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
@ -71,7 +72,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Models\Board.cs" />
|
<Compile Include="Models\Board.cs" />
|
||||||
<Compile Include="Interfaces\IObject.cs" />
|
<Compile Include="Interfaces\IObject.cs" />
|
||||||
<Compile Include="Models\Home.cs" />
|
<Compile Include="Models\GarbageCollectorWPF.cs" />
|
||||||
|
<Compile Include="Models\House.cs" />
|
||||||
|
<Compile Include="Models\Road.cs" />
|
||||||
<Compile Include="Models\Tile.cs" />
|
<Compile Include="Models\Tile.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 27 KiB |
BIN
Trunk/Interface/CzokoŚmieciarka.WPF/Images/garbageCollector.png
Normal file
BIN
Trunk/Interface/CzokoŚmieciarka.WPF/Images/garbageCollector.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 18 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 3.1 KiB |
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace CzokoŚmieciarka.WPF.Models
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
{
|
{
|
||||||
@ -11,5 +12,7 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
{
|
{
|
||||||
Coords Location { get; set; }
|
Coords Location { get; set; }
|
||||||
string ImagePath { get; set; }
|
string ImagePath { get; set; }
|
||||||
|
string Data { get; set; }
|
||||||
|
ImageBrush Image { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
<ItemsControl ItemsSource="{Binding Tiles}">
|
<ItemsControl ItemsSource="{Binding Tiles}">
|
||||||
<ItemsControl.Resources>
|
<ItemsControl.Resources>
|
||||||
<DataTemplate DataType="{x:Type models:Tile}">
|
<DataTemplate DataType="{x:Type models:Tile}">
|
||||||
<Grid Background="{Binding Background}">
|
<Grid Background="{Binding Object.Image}">
|
||||||
<TextBlock Text="{Binding Data}"></TextBlock>
|
<TextBlock Text="{Binding Object.Data}"></TextBlock>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ItemsControl.Resources>
|
</ItemsControl.Resources>
|
||||||
|
@ -13,6 +13,9 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
using CzokoŚmieciarka.DataModels.Models;
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
using CzokoŚmieciarka.WPF.Models;
|
using CzokoŚmieciarka.WPF.Models;
|
||||||
|
|
||||||
@ -24,18 +27,37 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public List<IObject> Objects = new List<IObject>();
|
public List<IObject> Objects = new List<IObject>();
|
||||||
|
public GarbageCollector garbageCollector = new GarbageCollector(new Coords(0,0), new List<AGarbageCollectorContainer>());
|
||||||
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Objects.Add(new Home()
|
Objects.Add(new House()
|
||||||
{
|
{
|
||||||
ImagePath = @"C:\Users\s434678\Source\Repos\Czoko_Smieciarka\Trunk\Interface\CzokoŚmieciarka.WPF\Images\house.png",
|
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png",
|
||||||
Location = new Coords(10, 12)
|
Image = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))),
|
||||||
|
Location = new Coords(3, 2),
|
||||||
|
Data = "House"
|
||||||
});
|
});
|
||||||
this.DataContext = new Board(8, 10, Objects);
|
Objects.Add(new House()
|
||||||
|
{
|
||||||
|
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png",
|
||||||
|
Image = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))),
|
||||||
|
Location = new Coords(5, 8),
|
||||||
|
Data = "House"
|
||||||
|
});
|
||||||
|
Objects.Add(new House()
|
||||||
|
{
|
||||||
|
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png",
|
||||||
|
Image = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))),
|
||||||
|
Location = new Coords(7, 5),
|
||||||
|
Data = "House"
|
||||||
|
});
|
||||||
|
garbageCollector.Position.X += 1;
|
||||||
|
this.DataContext = new Board(9, 9, Objects, garbageCollector);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
|
||||||
namespace CzokoŚmieciarka.WPF.Models
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
{
|
{
|
||||||
@ -13,28 +17,36 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
int _rows;
|
int _rows;
|
||||||
int _columns;
|
int _columns;
|
||||||
List<Tile> _tiles = new List<Tile>();
|
List<Tile> _tiles = new List<Tile>();
|
||||||
|
private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png");
|
||||||
|
|
||||||
public Board(int rows, int columns, List<IObject> Objects)
|
public Board(int rows, int columns, List<IObject> objects, GarbageCollector garbageCollector)
|
||||||
{
|
{
|
||||||
_rows = rows;
|
_rows = rows;
|
||||||
_columns = columns;
|
_columns = columns;
|
||||||
ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri(@"C:\Users\s434678\Source\Repos\Czoko_Smieciarka\Trunk\Interface\CzokoŚmieciarka.WPF\Images\intersection.png")));
|
|
||||||
for (int r = 0; r < rows; r++)
|
for (int r = 0; r < rows; r++)
|
||||||
{
|
{
|
||||||
for (int c = 0; c < columns; c++)
|
for (int c = 0; c < columns; c++)
|
||||||
{
|
{
|
||||||
|
Road road = new Road(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png");
|
||||||
_tiles.Add(new Tile()
|
_tiles.Add(new Tile()
|
||||||
{
|
{
|
||||||
Data = string.Format("Dirt {0}", r * 10 + c),
|
Data = string.Format(""),
|
||||||
Background = imgBrush
|
Object = road
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var item in Objects)
|
foreach(var item in objects)
|
||||||
{
|
{
|
||||||
_tiles[item.Location.X + item.Location.Y].Background = new ImageBrush(new BitmapImage(new Uri(@item.ImagePath)));
|
_tiles[item.Location.X + item.Location.Y * columns].Object = item;
|
||||||
|
_tiles[item.Location.X + item.Location.Y * columns].Object.Image = item.Image;
|
||||||
|
_tiles[item.Location.X + item.Location.Y * columns].Object.Data = item.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
garbageCollectorWPF.Move(columns, garbageCollector);
|
||||||
|
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps(
|
||||||
|
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
|
||||||
|
new Bitmap(garbageCollectorWPF.ImagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Rows
|
public int Rows
|
||||||
@ -54,5 +66,22 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
get { return _tiles; }
|
get { return _tiles; }
|
||||||
set { _tiles = value; }
|
set { _tiles = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ImageBrush MergedBitmaps(Bitmap bmp1, Bitmap bmp2)
|
||||||
|
{
|
||||||
|
using (Graphics g = Graphics.FromImage(bmp1))
|
||||||
|
{
|
||||||
|
g.DrawImage(bmp2, new Point(0,0));
|
||||||
|
}
|
||||||
|
MemoryStream ms = new MemoryStream();
|
||||||
|
((System.Drawing.Bitmap)bmp1).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
||||||
|
BitmapImage image = new BitmapImage();
|
||||||
|
image.BeginInit();
|
||||||
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
|
image.StreamSource = ms;
|
||||||
|
image.EndInit();
|
||||||
|
ImageBrush result = new ImageBrush(image);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
|
{
|
||||||
|
public class GarbageCollectorWPF : IObject
|
||||||
|
{
|
||||||
|
public Coords Location { get; set; }
|
||||||
|
|
||||||
|
public void Move(int columns, GarbageCollector garbageCollector)
|
||||||
|
{
|
||||||
|
Location.X = garbageCollector.Position.X;
|
||||||
|
Location.Y = garbageCollector.Position.Y * columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ImagePath { get; set; }
|
||||||
|
public string Data { get; set; }
|
||||||
|
public ImageBrush Image { get; set; }
|
||||||
|
|
||||||
|
public GarbageCollectorWPF(Coords location, string imagePath)
|
||||||
|
{
|
||||||
|
Location = location;
|
||||||
|
ImagePath = imagePath;
|
||||||
|
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -3,13 +3,16 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
using CzokoŚmieciarka.DataModels.Models;
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
|
||||||
namespace CzokoŚmieciarka.WPF.Models
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
{
|
{
|
||||||
public class Home : IObject
|
public class House : IObject
|
||||||
{
|
{
|
||||||
public Coords Location { get; set; }
|
public Coords Location { get; set; }
|
||||||
public string ImagePath { get; set; }
|
public string ImagePath { get; set; }
|
||||||
|
public string Data { get; set; }
|
||||||
|
public ImageBrush Image { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
25
Trunk/Interface/CzokoŚmieciarka.WPF/Models/Road.cs
Normal file
25
Trunk/Interface/CzokoŚmieciarka.WPF/Models/Road.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
|
{
|
||||||
|
public class Road: IObject
|
||||||
|
{
|
||||||
|
public Coords Location { get; set; }
|
||||||
|
public string ImagePath { get; set; }
|
||||||
|
public string Data { get; set; }
|
||||||
|
public ImageBrush Image { get; set; }
|
||||||
|
|
||||||
|
public Road(string imagePath)
|
||||||
|
{
|
||||||
|
ImagePath = imagePath;
|
||||||
|
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,6 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
public class Tile
|
public class Tile
|
||||||
{
|
{
|
||||||
public string Data { get; set; }
|
public string Data { get; set; }
|
||||||
public ImageBrush Background { get; set; }
|
public IObject Object { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user