Stefan
This commit is contained in:
parent
aece006b15
commit
57c53b9bdb
@ -7,7 +7,7 @@ namespace CzokoŚmieciarka.DataModels.GeneralModels.Models
|
|||||||
{
|
{
|
||||||
public class GarbageCollector : AGarbageCollector
|
public class GarbageCollector : AGarbageCollector
|
||||||
{
|
{
|
||||||
public GarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers) : base(startPosition, trashContainers)
|
public GarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers, int columns, int rows) : base(startPosition, trashContainers, columns, rows)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
<Compile Include="Enums\GarbageTypes.cs" />
|
<Compile Include="Enums\GarbageTypes.cs" />
|
||||||
<Compile Include="Exceptions.cs" />
|
<Compile Include="Exceptions.cs" />
|
||||||
<Compile Include="Enums\Directions.cs" />
|
<Compile Include="Enums\Directions.cs" />
|
||||||
|
<Compile Include="Exceptions\OutOfGridException.cs" />
|
||||||
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
||||||
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" />
|
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" />
|
||||||
<Compile Include="Interfaces\Garbage\AGarbage.cs" />
|
<Compile Include="Interfaces\Garbage\AGarbage.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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using CzokoŚmieciarka.DataModels.Exceptions;
|
||||||
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
using CzokoŚmieciarka.DataModels.Models;
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
|
|
||||||
@ -10,31 +11,50 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
|
|||||||
{
|
{
|
||||||
public abstract class AGarbageCollector : IGarbageCollector
|
public abstract class AGarbageCollector : IGarbageCollector
|
||||||
{
|
{
|
||||||
public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers)
|
public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers, int columns, int rows)
|
||||||
{
|
{
|
||||||
|
this.columns = columns;
|
||||||
|
this.rows = rows;
|
||||||
this.Coords = startPosition;
|
this.Coords = startPosition;
|
||||||
this.TrashContainers = trashContainers;
|
this.TrashContainers = trashContainers;
|
||||||
}
|
}
|
||||||
public Coords Coords { get; set; }
|
public Coords Coords { get; set; }
|
||||||
|
public int columns { get; set; }
|
||||||
public Coords MoveUp()
|
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()
|
public object Clone()
|
||||||
|
@ -11,10 +11,10 @@ namespace CzokoŚmieciarka.DataModels.Interfaces
|
|||||||
public interface IGarbageCollector : ICloneable
|
public interface IGarbageCollector : ICloneable
|
||||||
{
|
{
|
||||||
Coords Coords { get; }
|
Coords Coords { get; }
|
||||||
Coords MoveUp();
|
void MoveUp();
|
||||||
Coords MoveDown();
|
void MoveDown();
|
||||||
Coords MoveLeft();
|
void MoveLeft();
|
||||||
Coords MoveRight();
|
void MoveRight();
|
||||||
|
|
||||||
IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,7 @@ namespace CzokoŚmieciarka.WPFv2.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IWPFObject
|
public interface IWPFObject
|
||||||
{
|
{
|
||||||
string ImagePath { get; set; }
|
Image Image { get; }
|
||||||
Image Image { get; set; }
|
|
||||||
Coords Coords { get; set; }
|
Coords Coords { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,8 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
|
|
||||||
if (e.Key == Key.Space)
|
if (e.Key == Key.Space)
|
||||||
{
|
{
|
||||||
routePlanningEngine.PerformStep();
|
garbageCollector.MoveLeft();
|
||||||
|
//routePlanningEngine.PerformStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorBoard.Children.Clear();
|
CollectorBoard.Children.Clear();
|
||||||
@ -55,13 +56,19 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y);
|
Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y);
|
||||||
CollectorBoard.Children.Add(garbageCollector.Image);
|
CollectorBoard.Children.Add(garbageCollector.Image);
|
||||||
Board.Children.Clear();
|
Board.Children.Clear();
|
||||||
foreach (var item in Objects)
|
for (int x=0;x<Columns;x++)
|
||||||
{
|
{
|
||||||
Grid.SetColumn(item.Image, item.Coords.X);
|
for (int y = 0; y < Rows; y++)
|
||||||
Grid.SetRow(item.Image, item.Coords.Y);
|
{
|
||||||
Board.Children.Add(item.Image);
|
var item = Objects[x, y];
|
||||||
|
Grid.SetColumn(item.Image, x);
|
||||||
|
Grid.SetRow(item.Image, y);
|
||||||
|
Board.Children.Add(item.Image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,7 +76,7 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
{
|
{
|
||||||
ColumnDefinition column;
|
ColumnDefinition column;
|
||||||
RowDefinition row;
|
RowDefinition row;
|
||||||
for (int i = 0; i < Rows; i++)
|
for (int y = 0; y < Rows; y++)
|
||||||
{
|
{
|
||||||
column = new ColumnDefinition();
|
column = new ColumnDefinition();
|
||||||
row = new RowDefinition();
|
row = new RowDefinition();
|
||||||
@ -79,13 +86,13 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
row = new RowDefinition();
|
row = new RowDefinition();
|
||||||
CollectorBoard.ColumnDefinitions.Add(column);
|
CollectorBoard.ColumnDefinitions.Add(column);
|
||||||
CollectorBoard.RowDefinitions.Add(row);
|
CollectorBoard.RowDefinitions.Add(row);
|
||||||
for (int j = 0; j < Columns; j++)
|
for (int x = 0; x < Columns; x++)
|
||||||
{
|
{
|
||||||
Road road = new Road();
|
Road road = new Road();
|
||||||
Objects[i, j] = road;
|
Objects[x, y] = road;
|
||||||
Grid.SetRow(Objects[i, j].Image, i);
|
Grid.SetRow(Objects[x, y].Image, y);
|
||||||
Grid.SetColumn(Objects[i, j].Image, j);
|
Grid.SetColumn(Objects[x, y].Image, x);
|
||||||
Board.Children.Add(Objects[i, j].Image);
|
Board.Children.Add(Objects[x, y].Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -114,12 +121,12 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
new GarbageCollectorContainer(new TypeOfGarbage(GarbageType.PlasticMetal, 1,1),500),
|
new GarbageCollectorContainer(new TypeOfGarbage(GarbageType.PlasticMetal, 1,1),500),
|
||||||
new GarbageCollectorContainer(new TypeOfGarbage(GarbageType.Paper, 1,1), 500)
|
new GarbageCollectorContainer(new TypeOfGarbage(GarbageType.Paper, 1,1), 500)
|
||||||
};
|
};
|
||||||
garbageCollector = new WPFGarbageCollector(new Coords(2, 1), GarbageCollectorContainers);
|
garbageCollector = new WPFGarbageCollector(new Coords(2, 1), GarbageCollectorContainers, Columns, Rows);
|
||||||
Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y);
|
Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y);
|
||||||
Grid.SetColumn(garbageCollector.Image, garbageCollector.Coords.X);
|
Grid.SetColumn(garbageCollector.Image, garbageCollector.Coords.X);
|
||||||
CollectorBoard.Children.Add(garbageCollector.Image);
|
CollectorBoard.Children.Add(garbageCollector.Image);
|
||||||
CollectorBoard.ShowGridLines = true;
|
CollectorBoard.ShowGridLines = true;
|
||||||
//CollectorInfo.ItemsSource = garbageCollector.TrashContainers;
|
//CollectorInfo.ItemsSource = garbageCollector;
|
||||||
//CollectorInfo.Items.Add(garbageCollector);
|
//CollectorInfo.Items.Add(garbageCollector);
|
||||||
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Coords.X")});
|
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Coords.X")});
|
||||||
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Coords.Y") });
|
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Coords.Y") });
|
||||||
@ -133,8 +140,8 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
|
|
||||||
WPFHouse house = new WPFHouse(new Coords(1, 3), trashCans);
|
WPFHouse house = new WPFHouse(new Coords(1, 3), trashCans);
|
||||||
Objects[1, 3] = house;
|
Objects[1, 3] = house;
|
||||||
Grid.SetRow(Objects[1, 3].Image, 1);
|
Grid.SetRow(Objects[1, 3].Image, 3);
|
||||||
Grid.SetColumn(Objects[1, 3].Image, 3);
|
Grid.SetColumn(Objects[1, 3].Image, 1);
|
||||||
Board.Children.Add(Objects[1, 3].Image);
|
Board.Children.Add(Objects[1, 3].Image);
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,17 +18,19 @@ namespace CzokoŚmieciarka.WPFv2.Models
|
|||||||
{
|
{
|
||||||
class WPFGarbageCollector : AGarbageCollector, IWPFObject, INotifyPropertyChanged
|
class WPFGarbageCollector : AGarbageCollector, IWPFObject, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public string ImagePath { get; set; }
|
public Image Image
|
||||||
public Image Image { get; set; }
|
|
||||||
|
|
||||||
public WPFGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers) : base(startPosition, trashContainers)
|
|
||||||
{
|
{
|
||||||
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png";
|
get
|
||||||
Image = new Image
|
|
||||||
{
|
{
|
||||||
Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory +
|
return new Image
|
||||||
@"..\..\Images\garbageCollector.png"))
|
{
|
||||||
};
|
Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WPFGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers, int columns, int rows) : base(startPosition, trashContainers, columns, rows)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
@ -38,5 +40,8 @@ namespace CzokoŚmieciarka.WPFv2.Models
|
|||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,17 @@ namespace CzokoŚmieciarka.WPFv2.Models
|
|||||||
{
|
{
|
||||||
public Coords Coords { get; set; }
|
public Coords Coords { get; set; }
|
||||||
public IEnumerable<ATrashCan> TrashCans { get; set; }
|
public IEnumerable<ATrashCan> TrashCans { get; set; }
|
||||||
public string ImagePath { get; set; }
|
public Image Image { get {
|
||||||
public Image Image { get; set; }
|
return new Image
|
||||||
|
{
|
||||||
|
Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))
|
||||||
|
};
|
||||||
|
} }
|
||||||
|
|
||||||
|
|
||||||
public WPFHouse(Coords coords, IEnumerable<ATrashCan> trashCans)
|
public WPFHouse(Coords coords, IEnumerable<ATrashCan> trashCans)
|
||||||
{
|
{
|
||||||
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
|
|
||||||
Image = new Image
|
|
||||||
{
|
|
||||||
Source = new BitmapImage(new Uri(ImagePath))
|
|
||||||
};
|
|
||||||
TrashCans = trashCans;
|
TrashCans = trashCans;
|
||||||
Coords = coords;
|
Coords = coords;
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,20 @@ namespace CzokoŚmieciarka.WPFv2.Models
|
|||||||
{
|
{
|
||||||
class Road : IWPFObject
|
class Road : IWPFObject
|
||||||
{
|
{
|
||||||
public string ImagePath { get; set; }
|
public Image Image
|
||||||
public Image Image { get; set; }
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new Image
|
||||||
|
{
|
||||||
|
Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png"))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
public Coords Coords { get; set; }
|
public Coords Coords { get; set; }
|
||||||
|
|
||||||
public Road()
|
public Road()
|
||||||
{
|
{
|
||||||
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png";
|
|
||||||
Image = new Image
|
|
||||||
{
|
|
||||||
Source = new BitmapImage(new Uri(ImagePath))
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user