From 653e7cc3b75f8eca9800d70837caac2dfe1c4f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulski?= Date: Tue, 26 Mar 2019 23:20:41 +0100 Subject: [PATCH] =?UTF-8?q?co=C5=9B=20tam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfaces/AObject.cs | 5 +-- .../CzokoŚmieciarka.WPF/MainWindow.xaml.cs | 37 ++++++++++++++++--- .../CzokoŚmieciarka.WPF/Models/Board.cs | 18 ++++++--- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/Interfaces/AObject.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/Interfaces/AObject.cs index a66adc7..ba5e2f2 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/Interfaces/AObject.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/Interfaces/AObject.cs @@ -17,10 +17,9 @@ namespace CzokoŚmieciarka.WPF.Interfaces public string Data { get; set; } public ImageBrush Image { get; set; } - public ImageBrush RefreshImage() + public void RefreshImage() { - ImageBrush image = new ImageBrush(new BitmapImage(new Uri(ImagePath))); - return image; + Image = new ImageBrush(new BitmapImage(new Uri(ImagePath))); } } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs index c3853d8..e3e8ede 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs @@ -28,8 +28,8 @@ namespace CzokoŚmieciarka.WPF /// public partial class MainWindow : Window { - public GarbageCollector garbageCollector = new GarbageCollector(new Coords(0,0), new List()); - public Board board; + public GarbageCollector garbageCollector = new GarbageCollector(new Coords(1,1), new List()); + //public Board board; private int rows = 9; private int columns = 9; private List Objects = new List(); @@ -37,6 +37,8 @@ namespace CzokoŚmieciarka.WPF { InitializeComponent(); + List Objects = new List(); + for (int y = 0; y < rows; y++) { for(int x = 0; x < columns; x++) @@ -62,12 +64,36 @@ namespace CzokoŚmieciarka.WPF Objects[dump.Location.X + dump.Location.Y] = dump; - board = new Board(Objects, garbageCollector); + Board board = new Board(Objects, garbageCollector); this.DataContext = board; } private void MainWindow_OnKeyDown(object sender, KeyEventArgs e) { + List Objects = new List(); + for (int y = 0; y < rows; y++) + { + for (int x = 0; x < columns; x++) + { + Road road = new Road(columns, new Coords(x, y), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png"); + Objects.Add(road); + } + } + + House house = new House(columns, new Coords(0, 0)); + Objects[house.Location.X + house.Location.Y] = house; + house = new House(columns, new Coords(1, 0)); + Objects[house.Location.X + house.Location.Y] = house; + house = new House(columns, new Coords(2, 0)); + Objects[house.Location.X + house.Location.Y] = house; + DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), new TypeOfGarbage("glass", 0, 0)); + Objects[dump.Location.X + dump.Location.Y] = dump; + dump = new DumpWPF(columns, new Coords(2, 5), new TypeOfGarbage("plasticmetal", 0, 0)); + Objects[dump.Location.X + dump.Location.Y] = dump; + dump = new DumpWPF(columns, new Coords(3, 4), new TypeOfGarbage("organic", 0, 0)); + Objects[dump.Location.X + dump.Location.Y] = dump; + dump = new DumpWPF(columns, new Coords(3, 5), new TypeOfGarbage("paper", 0, 0)); + Objects[dump.Location.X + dump.Location.Y] = dump; if (e.Key == Key.Up) { garbageCollector.Position.Y -= 1; @@ -86,8 +112,9 @@ namespace CzokoŚmieciarka.WPF { garbageCollector.Position.X += 1; } - - this.DataContext = new Board(Objects, garbageCollector); + Board board = new Board(Objects, garbageCollector); + board.BoardRefresh(Objects, garbageCollector); + this.DataContext = board; } } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs index 2bc7c33..73fe780 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs @@ -18,7 +18,7 @@ namespace CzokoŚmieciarka.WPF.Models static int _rows = 9; static int _columns = 9; List _tiles = new List(); - private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(_columns, new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"); + private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(_columns, new Coords(1,1), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"); public Board(List objects, GarbageCollector garbageCollector) { @@ -38,17 +38,23 @@ namespace CzokoŚmieciarka.WPF.Models public void BoardRefresh(List objects, GarbageCollector garbageCollector) { + List tiles = new List(); + foreach (var item in objects) { - _tiles[item.Location.X + item.Location.Y].Object = item; - _tiles[item.Location.X + item.Location.Y].Object.Image = _tiles[item.Location.X + item.Location.Y].Object.RefreshImage(); - + Tile tile = new Tile() + { + Data = item.Data, + Object = item + }; + tiles.Add(tile); } 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), + 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)); + _tiles = tiles; } public int Rows