Dodany obiekt Road2 i odświeżanie Boardu z obiektami

This commit is contained in:
Michał Dulski 2019-04-08 17:07:08 +02:00
parent e105382084
commit 6071eb60b9
14 changed files with 69 additions and 29 deletions

View File

@ -43,7 +43,7 @@ namespace Czoko_Smieciarka.AI_Naive
switch (CurrentState) switch (CurrentState)
{ {
case State.TravelToDump: case State.TravelToDump:
if (Destination == Collector.Position) if (Destination == Collector.Coords)
{ {
var dump = (DestinationObject as ADump); var dump = (DestinationObject as ADump);
var step = new SpillStep(Collector, dump, dump.TypeOfGarbage); var step = new SpillStep(Collector, dump, dump.TypeOfGarbage);
@ -52,7 +52,7 @@ namespace Czoko_Smieciarka.AI_Naive
} }
else else
{ {
var dif = Destination - Collector.Position; var dif = Destination - Collector.Coords;
Direction nextDirection = (dif.X == 0) ? Direction nextDirection = (dif.X == 0) ?
((dif.Y > 0) ? Direction.Up : Direction.Down) : ((dif.Y > 0) ? Direction.Up : Direction.Down) :
((dif.X > 0) ? Direction.Right : Direction.Left); ((dif.X > 0) ? Direction.Right : Direction.Left);
@ -62,7 +62,7 @@ namespace Czoko_Smieciarka.AI_Naive
} }
break; break;
case State.TravelToCan: case State.TravelToCan:
if (Destination == Collector.Position) if (Destination == Collector.Coords)
{ {
var garbage = (DestinationObject as IGarbageLocalization); var garbage = (DestinationObject as IGarbageLocalization);
foreach (var item in garbage.TrashCans) foreach (var item in garbage.TrashCans)
@ -75,7 +75,7 @@ namespace Czoko_Smieciarka.AI_Naive
} }
else else
{ {
var dif = Destination - Collector.Position; var dif = Destination - Collector.Coords;
Direction nextDirection = (dif.X == 0) ? Direction nextDirection = (dif.X == 0) ?
((dif.Y > 0) ? Direction.Up : Direction.Down) : ((dif.Y > 0) ? Direction.Up : Direction.Down) :
((dif.X > 0) ? Direction.Right : Direction.Left); ((dif.X > 0) ? Direction.Right : Direction.Left);
@ -89,7 +89,7 @@ namespace Czoko_Smieciarka.AI_Naive
if (notEmpty.Any()) if (notEmpty.Any())
{ {
var destDump = Dumps.First(i => i.TypeOfGarbage == notEmpty.First().TypeOfGarbage); var destDump = Dumps.First(i => i.TypeOfGarbage == notEmpty.First().TypeOfGarbage);
this.Destination = destDump.Localization; this.Destination = destDump.Coords;
this.CurrentState = State.TravelToDump; this.CurrentState = State.TravelToDump;
} }
else else

View File

@ -12,29 +12,29 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
{ {
public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers) public AGarbageCollector(Coords startPosition, IEnumerable<AGarbageCollectorContainer> trashContainers)
{ {
this.Position = startPosition; this.Coords = startPosition;
this.TrashContainers = trashContainers; this.TrashContainers = trashContainers;
} }
public Coords Position { get; set; } public Coords Coords { get; set; }
public Coords MoveUp() public Coords MoveUp()
{ {
return new Coords(Position.X,Position.Y+1); return new Coords(Coords.X,Coords.Y+1);
} }
public Coords MoveDown() public Coords MoveDown()
{ {
return new Coords(Position.X, Position.Y - 1); return new Coords(Coords.X, Coords.Y - 1);
} }
public Coords MoveLeft() public Coords MoveLeft()
{ {
return new Coords(Position.X-1, Position.Y); return new Coords(Coords.X-1, Coords.Y);
} }
public Coords MoveRight() public Coords MoveRight()
{ {
return new Coords(Position.X+1, Position.Y); return new Coords(Coords.X+1, Coords.Y);
} }
public object Clone() public object Clone()

View File

@ -10,7 +10,7 @@ namespace CzokoŚmieciarka.DataModels.Interfaces
{ {
public interface IGarbageCollector : ICloneable public interface IGarbageCollector : ICloneable
{ {
Coords Position { get; } Coords Coords { get; }
Coords MoveUp(); Coords MoveUp();
Coords MoveDown(); Coords MoveDown();
Coords MoveLeft(); Coords MoveLeft();

View File

@ -6,9 +6,9 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
{ {
protected ADump(ITypeOfGarbage typeOfGarbage, int maxVolume, Coords localization) : base(typeOfGarbage, maxVolume) protected ADump(ITypeOfGarbage typeOfGarbage, int maxVolume, Coords localization) : base(typeOfGarbage, maxVolume)
{ {
this.Localization = localization; this.Coords = localization;
} }
public Coords Localization { get; set; } public Coords Coords { get; set; }
} }
} }

View File

@ -27,13 +27,13 @@ namespace CzokoŚmieciarka.DataModels.Models
return !(a == b); return !(a == b);
} }
public static Coords operator + (Coords a, Coords b) public static Coords operator + (Coords a, Coords b)
{ {
return new Coords(a.X + b.X, a.Y + b.Y); return new Coords(a.X + b.X, a.Y + b.Y);
} }
public static Coords operator -(Coords a, Coords b) public static Coords operator -(Coords a, Coords b)
{ {
return new Coords(a.X - b.X, a.Y - b.Y); return new Coords(a.X - b.X, a.Y - b.Y);
} }
} }
} }

View File

@ -23,7 +23,7 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
public void Invoke() public void Invoke()
{ {
if(_garbageCollector.Position != _garbageLocalization.Coords) if(_garbageCollector.Coords != _garbageLocalization.Coords)
throw new WrongPositionException("Śmieciarka nie jest w miejscu oderbania śmieci"); throw new WrongPositionException("Śmieciarka nie jest w miejscu oderbania śmieci");
var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage == _typeOfGarbage); var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage == _typeOfGarbage);

View File

@ -23,7 +23,7 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
public void Invoke() public void Invoke()
{ {
if(_garbageCollector.Position != _dump.Localization) if(_garbageCollector.Coords != _dump.Coords)
throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska"); throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska");
if(_dump.TypeOfGarbage != _typeOfGarbage) if(_dump.TypeOfGarbage != _typeOfGarbage)

View File

@ -74,6 +74,7 @@
<Compile Include="Models\GarbageCollector.cs" /> <Compile Include="Models\GarbageCollector.cs" />
<Compile Include="Models\House.cs" /> <Compile Include="Models\House.cs" />
<Compile Include="Models\Road.cs" /> <Compile Include="Models\Road.cs" />
<Compile Include="Models\Road2.cs" />
<Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using CzokoŚmieciarka.DataModels.Models;
namespace CzokoŚmieciarka.WPFv2.Interfaces namespace CzokoŚmieciarka.WPFv2.Interfaces
{ {
@ -12,5 +13,7 @@ namespace CzokoŚmieciarka.WPFv2.Interfaces
{ {
string ImagePath { get; set; } string ImagePath { get; set; }
Image Image { get; set; } Image Image { get; set; }
Coords Coords { get; set; }
} }
} }

View File

@ -51,9 +51,16 @@ namespace CzokoŚmieciarka.WPFv2
} }
CollectorBoard.Children.Clear(); CollectorBoard.Children.Clear();
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y); Grid.SetColumn(garbageCollector.Image, garbageCollector.Coords.X);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X); Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y);
CollectorBoard.Children.Add(garbageCollector.Image); CollectorBoard.Children.Add(garbageCollector.Image);
Board.Children.Clear();
foreach (var item in Objects)
{
Grid.SetColumn(item.Image, item.Coords.X);
Grid.SetRow(item.Image, item.Coords.Y);
Board.Children.Add(item.Image);
}
} }
@ -108,14 +115,14 @@ namespace CzokoŚmieciarka.WPFv2
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);
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y); Grid.SetRow(garbageCollector.Image, garbageCollector.Coords.Y);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.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.TrashContainers;
//CollectorInfo.Items.Add(garbageCollector); //CollectorInfo.Items.Add(garbageCollector);
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")}); //CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Coords.X")});
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") }); //CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Coords.Y") });
IEnumerable<TrashCan> trashCans = new List<TrashCan>() IEnumerable<TrashCan> trashCans = new List<TrashCan>()
{ {
new TrashCan(new TypeOfGarbage(GarbageType.Glass,1,1), 500, new Garbage(new TypeOfGarbage(GarbageType.Glass,1,1), 100)), new TrashCan(new TypeOfGarbage(GarbageType.Glass,1,1), 500, new Garbage(new TypeOfGarbage(GarbageType.Glass,1,1), 100)),

View File

@ -15,7 +15,7 @@ namespace CzokoŚmieciarka.WPFv2.Models
{ {
class WPFHouse : IGarbageLocalization, IWPFObject class WPFHouse : IGarbageLocalization, IWPFObject
{ {
public Coords Coords { get; } public Coords Coords { get; set; }
public IEnumerable<ATrashCan> TrashCans { get; set; } public IEnumerable<ATrashCan> TrashCans { get; set; }
public string ImagePath { get; set; } public string ImagePath { get; set; }
public Image Image { get; set; } public Image Image { get; set; }

View File

@ -15,6 +15,7 @@ namespace CzokoŚmieciarka.WPFv2.Models
{ {
public string ImagePath { get; set; } public string ImagePath { get; set; }
public Image Image { get; set; } public Image Image { get; set; }
public Coords Coords { get; set; }
public Road() public Road()
{ {

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPFv2.Interfaces;
namespace CzokoŚmieciarka.WPFv2.Models
{
class Road2 : IWPFObject
{
public string ImagePath { get; set; }
public Image Image { get; set; }
public Coords Coords { get; set; }
public Road2()
{
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersectionRED.png";
Image = new Image
{
Source = new BitmapImage(new Uri(ImagePath))
};
}
}
}