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 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="Exceptions.cs" />
|
||||
<Compile Include="Enums\Directions.cs" />
|
||||
<Compile Include="Exceptions\OutOfGridException.cs" />
|
||||
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
||||
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.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.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<AGarbageCollectorContainer> trashContainers)
|
||||
{
|
||||
public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> 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()
|
||||
|
@ -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<AGarbageCollectorContainer> TrashContainers { get; }
|
||||
}
|
||||
|
@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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<Columns;x++)
|
||||
{
|
||||
Grid.SetColumn(item.Image, item.Coords.X);
|
||||
Grid.SetRow(item.Image, item.Coords.Y);
|
||||
Board.Children.Add(item.Image);
|
||||
for (int y = 0; y < Rows; y++)
|
||||
{
|
||||
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;
|
||||
RowDefinition row;
|
||||
for (int i = 0; i < Rows; i++)
|
||||
for (int y = 0; y < Rows; y++)
|
||||
{
|
||||
column = new ColumnDefinition();
|
||||
row = new RowDefinition();
|
||||
@ -79,13 +86,13 @@ namespace CzokoŚmieciarka.WPFv2
|
||||
row = new RowDefinition();
|
||||
CollectorBoard.ColumnDefinitions.Add(column);
|
||||
CollectorBoard.RowDefinitions.Add(row);
|
||||
for (int j = 0; j < Columns; j++)
|
||||
for (int x = 0; x < Columns; x++)
|
||||
{
|
||||
Road road = new Road();
|
||||
Objects[i, j] = road;
|
||||
Grid.SetRow(Objects[i, j].Image, i);
|
||||
Grid.SetColumn(Objects[i, j].Image, j);
|
||||
Board.Children.Add(Objects[i, j].Image);
|
||||
Objects[x, y] = road;
|
||||
Grid.SetRow(Objects[x, y].Image, y);
|
||||
Grid.SetColumn(Objects[x, y].Image, x);
|
||||
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.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.SetColumn(garbageCollector.Image, garbageCollector.Coords.X);
|
||||
CollectorBoard.Children.Add(garbageCollector.Image);
|
||||
CollectorBoard.ShowGridLines = true;
|
||||
//CollectorInfo.ItemsSource = garbageCollector.TrashContainers;
|
||||
//CollectorInfo.ItemsSource = garbageCollector;
|
||||
//CollectorInfo.Items.Add(garbageCollector);
|
||||
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Coords.X")});
|
||||
//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);
|
||||
Objects[1, 3] = house;
|
||||
Grid.SetRow(Objects[1, 3].Image, 1);
|
||||
Grid.SetColumn(Objects[1, 3].Image, 3);
|
||||
Grid.SetRow(Objects[1, 3].Image, 3);
|
||||
Grid.SetColumn(Objects[1, 3].Image, 1);
|
||||
Board.Children.Add(Objects[1, 3].Image);
|
||||
|
||||
|
||||
|
@ -18,17 +18,19 @@ namespace CzokoŚmieciarka.WPFv2.Models
|
||||
{
|
||||
class WPFGarbageCollector : AGarbageCollector, IWPFObject, INotifyPropertyChanged
|
||||
{
|
||||
public string ImagePath { get; set; }
|
||||
public Image Image { get; set; }
|
||||
|
||||
public WPFGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> 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<AGarbageCollectorContainer> 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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,17 @@ namespace CzokoŚmieciarka.WPFv2.Models
|
||||
{
|
||||
public Coords Coords { get; set; }
|
||||
public IEnumerable<ATrashCan> 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<ATrashCan> trashCans)
|
||||
{
|
||||
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
|
||||
Image = new Image
|
||||
{
|
||||
Source = new BitmapImage(new Uri(ImagePath))
|
||||
};
|
||||
|
||||
TrashCans = trashCans;
|
||||
Coords = coords;
|
||||
}
|
||||
|
@ -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))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user