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 { int _rows; int _columns; List _tiles = new List(); private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"); public Board(int rows, int columns, List objects, GarbageCollector garbageCollector) { _rows = rows; _columns = columns; 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 * 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 { get { return _rows; } set { _rows = value; } } public int Columns { get { return _columns; } set { _columns = value; } } public List 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; } } }