2019-03-13 16:45:38 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-03-20 16:02:05 +01:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
2019-03-13 16:45:38 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Media;
|
2019-03-14 16:24:37 +01:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2019-03-20 16:02:05 +01:00
|
|
|
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
|
|
|
|
using CzokoŚmieciarka.DataModels.Models;
|
2019-03-26 22:47:45 +01:00
|
|
|
|
using CzokoŚmieciarka.WPF.Interfaces;
|
2019-03-13 16:45:38 +01:00
|
|
|
|
|
|
|
|
|
namespace CzokoŚmieciarka.WPF.Models
|
|
|
|
|
{
|
|
|
|
|
public class Board
|
|
|
|
|
{
|
2019-03-20 18:27:11 +01:00
|
|
|
|
static int _rows = 9;
|
|
|
|
|
static int _columns = 9;
|
2019-03-13 16:45:38 +01:00
|
|
|
|
List<Tile> _tiles = new List<Tile>();
|
|
|
|
|
|
2019-03-27 00:49:55 +01:00
|
|
|
|
public Board(List<AObject> objects, GarbageCollectorWPF garbageCollector)
|
2019-03-13 16:45:38 +01:00
|
|
|
|
{
|
2019-03-27 02:00:58 +01:00
|
|
|
|
foreach (var item in objects)
|
2019-03-13 16:45:38 +01:00
|
|
|
|
{
|
2019-03-26 22:47:45 +01:00
|
|
|
|
Tile tile = new Tile()
|
2019-03-13 16:45:38 +01:00
|
|
|
|
{
|
2019-03-26 22:47:45 +01:00
|
|
|
|
Data = item.Data,
|
|
|
|
|
Object = item
|
|
|
|
|
};
|
|
|
|
|
_tiles.Add(tile);
|
2019-03-13 16:45:38 +01:00
|
|
|
|
}
|
2019-03-27 00:49:55 +01:00
|
|
|
|
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
|
|
|
|
|
new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.ImagePath),
|
|
|
|
|
new Bitmap(garbageCollector.ImagePath));
|
2019-03-26 22:47:45 +01:00
|
|
|
|
}
|
2019-03-20 12:34:03 +01:00
|
|
|
|
|
2019-03-27 00:49:55 +01:00
|
|
|
|
public void BoardRefresh(List<AObject> objects, GarbageCollectorWPF garbageCollector)
|
2019-03-26 22:47:45 +01:00
|
|
|
|
{
|
|
|
|
|
foreach (var item in objects)
|
2019-03-20 12:34:03 +01:00
|
|
|
|
{
|
2019-03-26 23:25:01 +01:00
|
|
|
|
_tiles[item.Location.X + item.Location.Y].Object = item;
|
|
|
|
|
_tiles[item.Location.X + item.Location.Y].Object.RefreshImage();
|
2019-03-27 02:00:58 +01:00
|
|
|
|
|
2019-03-20 12:34:03 +01:00
|
|
|
|
}
|
2019-03-26 22:47:45 +01:00
|
|
|
|
|
2019-03-27 00:49:55 +01:00
|
|
|
|
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
|
|
|
|
|
new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.ImagePath),
|
|
|
|
|
new Bitmap(garbageCollector.ImagePath));
|
2019-03-13 16:45:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
}
|
2019-03-20 16:02:05 +01:00
|
|
|
|
|
|
|
|
|
private ImageBrush MergedBitmaps(Bitmap bmp1, Bitmap bmp2)
|
|
|
|
|
{
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp1))
|
|
|
|
|
{
|
2019-03-27 02:00:58 +01:00
|
|
|
|
g.DrawImage(bmp2, new Point(0, 0));
|
2019-03-20 16:02:05 +01:00
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2019-03-13 16:45:38 +01:00
|
|
|
|
}
|
2019-03-27 02:00:58 +01:00
|
|
|
|
}
|