From 9ff635db9f63cac0ad9a859bb595052d09eef2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulski?= Date: Wed, 27 Mar 2019 00:49:55 +0100 Subject: [PATCH] Usprawnienie poruszania --- .../CzokoŚmieciarka.DataModels.csproj | 1 + .../Enums/GarbageTypes.cs | 16 ++++++++ .../CzokoŚmieciarka.WPF.csproj | 1 + .../CzokoŚmieciarka.WPF/MainWindow.xaml | 3 +- .../CzokoŚmieciarka.WPF/MainWindow.xaml.cs | 41 ++++--------------- .../CzokoŚmieciarka.WPF/Models/Board.cs | 18 ++++---- .../Models/GarbageCollectorWPF.cs | 20 +++++++-- .../CzokoŚmieciarka.WPF/Models/House.cs | 3 +- .../CzokoŚmieciarka.WPF/Models/Trash.cs | 21 ++++++++++ 9 files changed, 77 insertions(+), 47 deletions(-) create mode 100644 Trunk/Components/CzokoŚmieciarka.DataModels/Enums/GarbageTypes.cs create mode 100644 Trunk/Interface/CzokoŚmieciarka.WPF/Models/Trash.cs diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj b/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj index 105b426..010f889 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj @@ -42,6 +42,7 @@ + diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/Enums/GarbageTypes.cs b/Trunk/Components/CzokoŚmieciarka.DataModels/Enums/GarbageTypes.cs new file mode 100644 index 0000000..ce58a4a --- /dev/null +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/Enums/GarbageTypes.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CzokoŚmieciarka.DataModels.Enums +{ + public enum GarbageType + { + Glass, + PlasticMetal, + Organic, + Paper + } +} diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/CzokoŚmieciarka.WPF.csproj b/Trunk/Interface/CzokoŚmieciarka.WPF/CzokoŚmieciarka.WPF.csproj index c866910..57bd972 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/CzokoŚmieciarka.WPF.csproj +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/CzokoŚmieciarka.WPF.csproj @@ -78,6 +78,7 @@ + Code diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml b/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml index dbdbc44..5947876 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:CzokoŚmieciarka.WPF" xmlns:models="clr-namespace:CzokoŚmieciarka.WPF.Models" mc:Ignorable="d" - Title="MainWindow" Height="800" Width="800" + Title="MainWindow" Height="800" Width="1000" KeyDown="MainWindow_OnKeyDown"> @@ -22,4 +22,5 @@ + diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs index e3e8ede..b9497a3 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using CzokoŚmieciarka.DataModels.Enums; using CzokoŚmieciarka.DataModels.GeneralModels.Models; using CzokoŚmieciarka.DataModels.Interfaces; using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; @@ -28,16 +29,15 @@ namespace CzokoŚmieciarka.WPF /// public partial class MainWindow : Window { - public GarbageCollector garbageCollector = new GarbageCollector(new Coords(1,1), new List()); //public Board board; - private int rows = 9; - private int columns = 9; + private static int rows = 9; + private static int columns = 9; + private GarbageCollectorWPF garbageCollector = new GarbageCollectorWPF(columns, new Coords(0, 0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"); private List Objects = new List(); public MainWindow() { InitializeComponent(); - List Objects = new List(); for (int y = 0; y < rows; y++) { @@ -70,47 +70,24 @@ namespace CzokoŚmieciarka.WPF 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; + garbageCollector.Move(columns, Direction.Up); } if (e.Key == Key.Down) { - garbageCollector.Position.Y += 1; + garbageCollector.Move(columns, Direction.Down); } if (e.Key == Key.Left) { - garbageCollector.Position.X -= 1; + garbageCollector.Move(columns, Direction.Left); } if (e.Key == Key.Right) { - garbageCollector.Position.X += 1; + garbageCollector.Move(columns,Direction.Right); } Board board = new Board(Objects, garbageCollector); board.BoardRefresh(Objects, garbageCollector); diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs index 487ca84..c4b8ba6 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Board.cs @@ -18,9 +18,8 @@ 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"); - public Board(List objects, GarbageCollector garbageCollector) + public Board(List objects, GarbageCollectorWPF garbageCollector) { foreach(var item in objects) { @@ -31,12 +30,12 @@ namespace CzokoŚmieciarka.WPF.Models }; _tiles.Add(tile); } - _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[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps( + new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.ImagePath), + new Bitmap(garbageCollector.ImagePath)); } - public void BoardRefresh(List objects, GarbageCollector garbageCollector) + public void BoardRefresh(List objects, GarbageCollectorWPF garbageCollector) { foreach (var item in objects) { @@ -45,10 +44,9 @@ namespace CzokoŚmieciarka.WPF.Models } - 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)); + _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)); } public int Rows diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/GarbageCollectorWPF.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/GarbageCollectorWPF.cs index 62c478e..ca45ed9 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/GarbageCollectorWPF.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/GarbageCollectorWPF.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Windows.Media.Imaging; +using CzokoŚmieciarka.DataModels.Enums; using CzokoŚmieciarka.DataModels.GeneralModels.Models; using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.WPF.Annotations; @@ -16,10 +17,23 @@ namespace CzokoŚmieciarka.WPF.Models { public class GarbageCollectorWPF : AObject, INotifyPropertyChanged { - public void Move(int columns, GarbageCollector garbageCollector) + public void Move(int columns, Direction direction) { - Location.X = garbageCollector.Position.X; - Location.Y = garbageCollector.Position.Y * columns; + switch (direction) + { + case (Direction.Up): + Location.Y = Location.Y + (-1 * columns); + break; + case (Direction.Down): + Location.Y = Location.Y + (1 * columns); + break; + case (Direction.Left): + Location.X = Location.X + (-1); + break; + case (Direction.Right): + Location.X = Location.X + (1); + break; + } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/House.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/House.cs index fa8612c..ab3da73 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/House.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/House.cs @@ -12,12 +12,13 @@ namespace CzokoŚmieciarka.WPF.Models { public class House : AObject { + public List Trashes = new List(4); public House(int columns, Coords location) { ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"; Image = new ImageBrush(new BitmapImage(new Uri(ImagePath))); Location = new Coords(location.X, location.Y*columns); - Data = "House"; + Data = ""; } } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Trash.cs b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Trash.cs new file mode 100644 index 0000000..ad59a69 --- /dev/null +++ b/Trunk/Interface/CzokoŚmieciarka.WPF/Models/Trash.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CzokoŚmieciarka.DataModels.Enums; + +namespace CzokoŚmieciarka.WPF.Models +{ + public class Trash + { + public GarbageType Type { get; set; } + public int Weight { get; set; } + + public Trash(GarbageType type, int weight) + { + Type = type; + Weight = weight; + } + } +}