From 57c53b9bdb9fcfcbabf8204730e99eeda38134af Mon Sep 17 00:00:00 2001 From: s434678 Date: Wed, 10 Apr 2019 12:32:32 +0200 Subject: [PATCH] Stefan --- .../Models/GarbageCollector.cs | 2 +- .../CzokoŚmieciarka.DataModels.csproj | 1 + .../Exceptions/OutOfGridException.cs | 24 ++++++++++ .../GarbageCollector/AGarbageCollector.cs | 44 ++++++++++++++----- .../GarbageCollector/IGarbageCollector.cs | 8 ++-- .../Interfaces/IWPFObject.cs | 4 +- .../CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs | 37 +++++++++------- .../Models/GarbageCollector.cs | 23 ++++++---- .../CzokoŚmieciarka.WPFv2/Models/House.cs | 14 +++--- .../CzokoŚmieciarka.WPFv2/Models/Road.cs | 17 ++++--- 10 files changed, 116 insertions(+), 58 deletions(-) create mode 100644 Trunk/Components/CzokoŚmieciarka.DataModels/Exceptions/OutOfGridException.cs diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/GarbageCollector.cs b/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/GarbageCollector.cs index f13df43..5a224df 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/GarbageCollector.cs +++ b/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/GarbageCollector.cs @@ -7,7 +7,7 @@ namespace CzokoŚmieciarka.DataModels.GeneralModels.Models { public class GarbageCollector : AGarbageCollector { - public GarbageCollector(Coords startPosition, IEnumerable trashContainers) : base(startPosition, trashContainers) + public GarbageCollector(Coords startPosition, IEnumerable trashContainers, int columns, int rows) : base(startPosition, trashContainers, columns, rows) { } } diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj b/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj index 010f889..1104398 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/CzokoŚmieciarka.DataModels.csproj @@ -45,6 +45,7 @@ + diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/Exceptions/OutOfGridException.cs b/Trunk/Components/CzokoŚmieciarka.DataModels/Exceptions/OutOfGridException.cs new file mode 100644 index 0000000..a0c69cc --- /dev/null +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/Exceptions/OutOfGridException.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CzokoŚmieciarka.DataModels.Exceptions +{ + public class OutOfGridException : Exception + { + public OutOfGridException() + { + } + public OutOfGridException(string message) + : base(message) + { + } + + public OutOfGridException(string message, Exception inner) + : base(message, inner) + { + } + } +} diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs index 3998ca2..414d5d6 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using CzokoŚmieciarka.DataModels.Exceptions; using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; using CzokoŚmieciarka.DataModels.Models; @@ -10,31 +11,50 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector { public abstract class AGarbageCollector : IGarbageCollector { - public AGarbageCollector(Coords startPosition, IEnumerable trashContainers) - { + public AGarbageCollector(Coords startPosition, IEnumerable trashContainers, int columns, int rows) + { + this.columns = columns; + this.rows = rows; this.Coords = startPosition; this.TrashContainers = trashContainers; } - public Coords Coords { get; set; } - - public Coords MoveUp() + public Coords Coords { get; set; } + public int columns { get; set; } + public int rows { get; set; } + public void MoveUp() { - return new Coords(Coords.X,Coords.Y+1); + if(Coords.Y -1 < 0) + { + throw new OutOfGridException(); + } + Coords.Y -= 1; } - public Coords MoveDown() + public void MoveDown() { - return new Coords(Coords.X, Coords.Y - 1); + if (Coords.Y + 1 >= rows) + { + throw new OutOfGridException(); + } + Coords.Y +=1; } - public Coords MoveLeft() + public void MoveLeft() { - return new Coords(Coords.X-1, Coords.Y); + if (Coords.X - 1 < 0) + { + throw new OutOfGridException(); + } + Coords.X -= 1; } - public Coords MoveRight() + public void MoveRight() { - return new Coords(Coords.X+1, Coords.Y); + if (Coords.X + 1 >= columns) + { + throw new OutOfGridException(); + } + Coords.X += 1; } public object Clone() diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/IGarbageCollector.cs b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/IGarbageCollector.cs index 260a030..89bc30e 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/IGarbageCollector.cs +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/GarbageCollector/IGarbageCollector.cs @@ -11,10 +11,10 @@ namespace CzokoŚmieciarka.DataModels.Interfaces public interface IGarbageCollector : ICloneable { Coords Coords { get; } - Coords MoveUp(); - Coords MoveDown(); - Coords MoveLeft(); - Coords MoveRight(); + void MoveUp(); + void MoveDown(); + void MoveLeft(); + void MoveRight(); IEnumerable TrashContainers { get; } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPFv2/Interfaces/IWPFObject.cs b/Trunk/Interface/CzokoŚmieciarka.WPFv2/Interfaces/IWPFObject.cs index 29b240a..6db260b 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPFv2/Interfaces/IWPFObject.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPFv2/Interfaces/IWPFObject.cs @@ -11,9 +11,7 @@ namespace CzokoŚmieciarka.WPFv2.Interfaces { public interface IWPFObject { - string ImagePath { get; set; } - Image Image { get; set; } + Image Image { get; } Coords Coords { get; set; } - } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs b/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs index bf9c145..4523793 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs @@ -47,7 +47,8 @@ namespace CzokoŚmieciarka.WPFv2 if (e.Key == Key.Space) { - routePlanningEngine.PerformStep(); + garbageCollector.MoveLeft(); + //routePlanningEngine.PerformStep(); } CollectorBoard.Children.Clear(); @@ -55,12 +56,18 @@ namespace CzokoŚmieciarka.WPFv2 Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y); CollectorBoard.Children.Add(garbageCollector.Image); Board.Children.Clear(); - foreach (var item in Objects) + for (int x=0;x trashContainers) : base(startPosition, trashContainers) + public Image Image { - ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"; - Image = new Image + get { - Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + - @"..\..\Images\garbageCollector.png")) - }; + return new Image + { + Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png")) + }; + } + } + + public WPFGarbageCollector(Coords startPosition, IEnumerable trashContainers, int columns, int rows) : base(startPosition, trashContainers, columns, rows) + { } public event PropertyChangedEventHandler PropertyChanged; @@ -38,5 +40,8 @@ namespace CzokoŚmieciarka.WPFv2.Models { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + + } } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/House.cs b/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/House.cs index 03cec39..4ad0f6d 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/House.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/House.cs @@ -17,17 +17,17 @@ namespace CzokoŚmieciarka.WPFv2.Models { public Coords Coords { get; set; } public IEnumerable TrashCans { get; set; } - public string ImagePath { get; set; } - public Image Image { get; set; } + public Image Image { get { + return new Image + { + Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png")) + }; + } } public WPFHouse(Coords coords, IEnumerable trashCans) { - ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"; - Image = new Image - { - Source = new BitmapImage(new Uri(ImagePath)) - }; + TrashCans = trashCans; Coords = coords; } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/Road.cs b/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/Road.cs index 114149b..fd1542b 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/Road.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPFv2/Models/Road.cs @@ -13,17 +13,20 @@ namespace CzokoŚmieciarka.WPFv2.Models { class Road : IWPFObject { - public string ImagePath { get; set; } - public Image Image { get; set; } + public Image Image + { + get + { + return new Image + { + Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png")) + }; + } + } public Coords Coords { get; set; } public Road() { - ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png"; - Image = new Image - { - Source = new BitmapImage(new Uri(ImagePath)) - }; } } }