96 lines
3.3 KiB
C#
96 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
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 Board
|
|
{
|
|
static int _rows = 9;
|
|
static int _columns = 9;
|
|
List<Tile> _tiles = new List<Tile>();
|
|
private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(_columns, new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png");
|
|
|
|
public Board(List<IObject> objects, GarbageCollector garbageCollector)
|
|
{
|
|
for (int r = 0; r < _rows; r++)
|
|
{
|
|
for (int c = 0; c < _columns; c++)
|
|
{
|
|
Road road = new Road(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png");
|
|
_tiles.Add(new Tile()
|
|
{
|
|
Data = string.Format(""),
|
|
Object = road
|
|
});
|
|
}
|
|
}
|
|
|
|
foreach(var item in objects)
|
|
{
|
|
_tiles[item.Location.X + item.Location.Y].Object = item;
|
|
}
|
|
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 void BoardRefresh(List<IObject> objects, GarbageCollector garbageCollector)
|
|
//{
|
|
// foreach (var item in objects)
|
|
// {
|
|
// _tiles[item.Location.X + item.Location.Y * _columns].Object = item;
|
|
// }
|
|
|
|
// 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
|
|
{
|
|
get { return _rows; }
|
|
set { _rows = value; }
|
|
}
|
|
|
|
public int Columns
|
|
{
|
|
get { return _columns; }
|
|
set { _columns = value; }
|
|
}
|
|
|
|
public List<Tile> Tiles
|
|
{
|
|
get { return _tiles; }
|
|
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;
|
|
}
|
|
}
|
|
}
|