zmiana pozycji obiektu smieciarki z interfejsu dla logiki
This commit is contained in:
parent
56d2a4ff75
commit
70b821ce36
@ -15,7 +15,7 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
|
|||||||
this.Position = startPosition;
|
this.Position = startPosition;
|
||||||
this.TrashContainers = trashContainers;
|
this.TrashContainers = trashContainers;
|
||||||
}
|
}
|
||||||
public Coords Position { get; }
|
public Coords Position { get; set; }
|
||||||
|
|
||||||
public Coords MoveUp()
|
public Coords MoveUp()
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,6 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
{
|
{
|
||||||
public interface IObject
|
public interface IObject
|
||||||
{
|
{
|
||||||
Coords Location { get; set; }
|
|
||||||
string ImagePath { get; set; }
|
string ImagePath { get; set; }
|
||||||
string Data { get; set; }
|
string Data { get; set; }
|
||||||
ImageBrush Image { get; set; }
|
ImageBrush Image { get; set; }
|
||||||
|
@ -32,7 +32,7 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
//public Board board;
|
//public Board board;
|
||||||
private static int rows = 9;
|
private static int rows = 9;
|
||||||
private static int columns = 9;
|
private static int columns = 9;
|
||||||
private GarbageCollectorWPF garbageCollector = new GarbageCollectorWPF(columns, new Coords(0, 0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png");
|
private GarbageCollectorWPF garbageCollector = new GarbageCollectorWPF(columns, new Coords(0, 0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png", new List<AGarbageCollectorContainer>());
|
||||||
private List<AObject> Objects = new List<AObject>();
|
private List<AObject> Objects = new List<AObject>();
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
|
|
||||||
for (int y = 0; y < rows; y++)
|
for (int y = 0; y < rows; y++)
|
||||||
{
|
{
|
||||||
for(int x = 0; x < columns; x++)
|
for (int x = 0; x < columns; x++)
|
||||||
{
|
{
|
||||||
Road road = new Road(columns, new Coords(x, y), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png");
|
Road road = new Road(columns, new Coords(x, y), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png");
|
||||||
Objects.Add(road);
|
Objects.Add(road);
|
||||||
@ -58,11 +58,11 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
trashes.Add(plasticMetal);
|
trashes.Add(plasticMetal);
|
||||||
trashes.Add(organic);
|
trashes.Add(organic);
|
||||||
trashes.Add(paper);
|
trashes.Add(paper);
|
||||||
House house = new House(columns, new Coords(0, 0),trashes);
|
House house = new House(columns, new Coords(0, 0), trashes);
|
||||||
Objects[house.Location.X + house.Location.Y] = house;
|
Objects[house.Location.X + house.Location.Y] = house;
|
||||||
house = new House(columns, new Coords(1, 0),trashes);
|
house = new House(columns, new Coords(1, 0), trashes);
|
||||||
Objects[house.Location.X + house.Location.Y] = house;
|
Objects[house.Location.X + house.Location.Y] = house;
|
||||||
house = new House(columns, new Coords(2, 0),trashes);
|
house = new House(columns, new Coords(2, 0), trashes);
|
||||||
Objects[house.Location.X + house.Location.Y] = house;
|
Objects[house.Location.X + house.Location.Y] = house;
|
||||||
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), glass);
|
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), glass);
|
||||||
Objects[dump.Location.X + dump.Location.Y] = dump;
|
Objects[dump.Location.X + dump.Location.Y] = dump;
|
||||||
@ -97,7 +97,7 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
|
|
||||||
if (e.Key == Key.Right)
|
if (e.Key == Key.Right)
|
||||||
{
|
{
|
||||||
garbageCollector.Move(columns,Direction.Right);
|
garbageCollector.Move(columns, Direction.Right);
|
||||||
}
|
}
|
||||||
Board board = new Board(Objects, garbageCollector);
|
Board board = new Board(Objects, garbageCollector);
|
||||||
board.BoardRefresh(Objects, garbageCollector);
|
board.BoardRefresh(Objects, garbageCollector);
|
||||||
|
@ -21,7 +21,7 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
|
|
||||||
public Board(List<AObject> objects, GarbageCollectorWPF garbageCollector)
|
public Board(List<AObject> objects, GarbageCollectorWPF garbageCollector)
|
||||||
{
|
{
|
||||||
foreach(var item in objects)
|
foreach (var item in objects)
|
||||||
{
|
{
|
||||||
Tile tile = new Tile()
|
Tile tile = new Tile()
|
||||||
{
|
{
|
||||||
@ -71,7 +71,7 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
{
|
{
|
||||||
using (Graphics g = Graphics.FromImage(bmp1))
|
using (Graphics g = Graphics.FromImage(bmp1))
|
||||||
{
|
{
|
||||||
g.DrawImage(bmp2, new Point(0,0));
|
g.DrawImage(bmp2, new Point(0, 0));
|
||||||
}
|
}
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
((System.Drawing.Bitmap)bmp1).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
((System.Drawing.Bitmap)bmp1).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
||||||
|
@ -9,35 +9,46 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using CzokoŚmieciarka.DataModels.Enums;
|
using CzokoŚmieciarka.DataModels.Enums;
|
||||||
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
using CzokoŚmieciarka.DataModels.Models;
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
using CzokoŚmieciarka.WPF.Annotations;
|
using CzokoŚmieciarka.WPF.Annotations;
|
||||||
using CzokoŚmieciarka.WPF.Interfaces;
|
using CzokoŚmieciarka.WPF.Interfaces;
|
||||||
|
|
||||||
namespace CzokoŚmieciarka.WPF.Models
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
{
|
{
|
||||||
public class GarbageCollectorWPF : AObject, INotifyPropertyChanged
|
public class GarbageCollectorWPF : AGarbageCollector, IObject, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
public Coords Location { get; set; }
|
||||||
|
public string ImagePath { get; set; }
|
||||||
|
public string Data { get; set; }
|
||||||
|
public ImageBrush Image { get; set; }
|
||||||
public void Move(int columns, Direction direction)
|
public void Move(int columns, Direction direction)
|
||||||
{
|
{
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case (Direction.Up):
|
case (Direction.Up):
|
||||||
Location.Y = Location.Y + (-1 * columns);
|
Location.Y = Location.Y + (-1 * columns);
|
||||||
|
Position = this.MoveUp();
|
||||||
break;
|
break;
|
||||||
case (Direction.Down):
|
case (Direction.Down):
|
||||||
Location.Y = Location.Y + (1 * columns);
|
Location.Y = Location.Y + (1 * columns);
|
||||||
|
Position = this.MoveDown();
|
||||||
break;
|
break;
|
||||||
case (Direction.Left):
|
case (Direction.Left):
|
||||||
Location.X = Location.X + (-1);
|
Location.X = Location.X + (-1);
|
||||||
|
Position = this.MoveLeft();
|
||||||
break;
|
break;
|
||||||
case (Direction.Right):
|
case (Direction.Right):
|
||||||
Location.X = Location.X + (1);
|
Location.X = Location.X + (1);
|
||||||
|
Position = this.MoveRight();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public GarbageCollectorWPF(int columns,Coords location, string imagePath)
|
public GarbageCollectorWPF(int columns, Coords location, string imagePath, IEnumerable<AGarbageCollectorContainer> trashContainers) : base(location, trashContainers)
|
||||||
{
|
{
|
||||||
Location = new Coords(location.X, location.Y * columns);
|
Location = new Coords(location.X, location.Y * columns);
|
||||||
ImagePath = imagePath;
|
ImagePath = imagePath;
|
||||||
@ -51,5 +62,8 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user