zmiana pozycji obiektu smieciarki z interfejsu dla logiki

This commit is contained in:
Michał Dulski 2019-03-27 02:00:58 +01:00
parent 56d2a4ff75
commit 70b821ce36
5 changed files with 29 additions and 16 deletions

View File

@ -15,7 +15,7 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector
this.Position = startPosition;
this.TrashContainers = trashContainers;
}
public Coords Position { get; }
public Coords Position { get; set; }
public Coords MoveUp()
{

View File

@ -10,7 +10,6 @@ namespace CzokoŚmieciarka.WPF.Models
{
public interface IObject
{
Coords Location { get; set; }
string ImagePath { get; set; }
string Data { get; set; }
ImageBrush Image { get; set; }

View File

@ -32,7 +32,7 @@ namespace CzokoŚmieciarka.WPF
//public Board board;
private static int rows = 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>();
public MainWindow()
{
@ -41,7 +41,7 @@ namespace CzokoŚmieciarka.WPF
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");
Objects.Add(road);
@ -58,11 +58,11 @@ namespace CzokoŚmieciarka.WPF
trashes.Add(plasticMetal);
trashes.Add(organic);
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;
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;
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;
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), glass);
Objects[dump.Location.X + dump.Location.Y] = dump;
@ -80,7 +80,7 @@ namespace CzokoŚmieciarka.WPF
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Up)
{
garbageCollector.Move(columns, Direction.Up);
@ -97,11 +97,11 @@ namespace CzokoŚmieciarka.WPF
if (e.Key == Key.Right)
{
garbageCollector.Move(columns,Direction.Right);
garbageCollector.Move(columns, Direction.Right);
}
Board board = new Board(Objects, garbageCollector);
board.BoardRefresh(Objects, garbageCollector);
this.DataContext = board;
}
}
}
}

View File

@ -21,7 +21,7 @@ namespace CzokoŚmieciarka.WPF.Models
public Board(List<AObject> objects, GarbageCollectorWPF garbageCollector)
{
foreach(var item in objects)
foreach (var item in objects)
{
Tile tile = new Tile()
{
@ -41,7 +41,7 @@ namespace CzokoŚmieciarka.WPF.Models
{
_tiles[item.Location.X + item.Location.Y].Object = item;
_tiles[item.Location.X + item.Location.Y].Object.RefreshImage();
}
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
@ -71,7 +71,7 @@ namespace CzokoŚmieciarka.WPF.Models
{
using (Graphics g = Graphics.FromImage(bmp1))
{
g.DrawImage(bmp2, new Point(0,0));
g.DrawImage(bmp2, new Point(0, 0));
}
MemoryStream ms = new MemoryStream();
((System.Drawing.Bitmap)bmp1).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
@ -84,4 +84,4 @@ namespace CzokoŚmieciarka.WPF.Models
return result;
}
}
}
}

View File

@ -9,35 +9,46 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Enums;
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.WPF.Annotations;
using CzokoŚmieciarka.WPF.Interfaces;
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)
{
switch (direction)
{
case (Direction.Up):
Location.Y = Location.Y + (-1 * columns);
Position = this.MoveUp();
break;
case (Direction.Down):
Location.Y = Location.Y + (1 * columns);
Position = this.MoveDown();
break;
case (Direction.Left):
Location.X = Location.X + (-1);
Position = this.MoveLeft();
break;
case (Direction.Right):
Location.X = Location.X + (1);
Position = this.MoveRight();
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);
ImagePath = imagePath;
@ -51,5 +62,8 @@ namespace CzokoŚmieciarka.WPF.Models
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}