Dodano wysypisko i drobne poprawki

This commit is contained in:
Michał Dulski 2019-03-20 18:27:11 +01:00
parent b14fd9f43f
commit 31a9e9109c
10 changed files with 98 additions and 47 deletions

View File

@ -72,6 +72,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Models\Board.cs" /> <Compile Include="Models\Board.cs" />
<Compile Include="Interfaces\IObject.cs" /> <Compile Include="Interfaces\IObject.cs" />
<Compile Include="Models\DumpWPF.cs" />
<Compile Include="Models\GarbageCollectorWPF.cs" /> <Compile Include="Models\GarbageCollectorWPF.cs" />
<Compile Include="Models\House.cs" /> <Compile Include="Models\House.cs" />
<Compile Include="Models\Road.cs" /> <Compile Include="Models\Road.cs" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -30,33 +30,23 @@ namespace CzokoŚmieciarka.WPF
public List<IObject> Objects = new List<IObject>(); public List<IObject> Objects = new List<IObject>();
public GarbageCollector garbageCollector = new GarbageCollector(new Coords(0,0), new List<AGarbageCollectorContainer>()); public GarbageCollector garbageCollector = new GarbageCollector(new Coords(0,0), new List<AGarbageCollectorContainer>());
public Board board; public Board board;
private int rows = 9;
private int columns = 9;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
Objects.Add(new House() Objects.Add(new House(columns, new Coords(3, 2)));
{ Objects.Add(new House(columns, new Coords(5, 8)));
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png", Objects.Add(new House(columns, new Coords(7, 5)));
Image = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))), Objects.Add(new DumpWPF(columns, new Coords(2, 4), new TypeOfGarbage("glass",0,0)));
Location = new Coords(3, 2), Objects.Add(new DumpWPF(columns, new Coords(2, 5), new TypeOfGarbage("plasticmetal", 0, 0)));
Data = "House" Objects.Add(new DumpWPF(columns, new Coords(3, 4), new TypeOfGarbage("organic", 0, 0)));
}); Objects.Add(new DumpWPF(columns, new Coords(3, 5), new TypeOfGarbage("paper", 0, 0)));
Objects.Add(new House()
{ board = new Board(Objects, garbageCollector);
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png", this.DataContext = board;
Image = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))),
Location = new Coords(5, 8),
Data = "House"
});
Objects.Add(new House()
{
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png",
Image = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png"))),
Location = new Coords(7, 5),
Data = "House"
});
this.DataContext = new Board(9, 9, Objects, garbageCollector);
} }
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e) private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
@ -79,7 +69,9 @@ namespace CzokoŚmieciarka.WPF
{ {
garbageCollector.Position.X += 1; garbageCollector.Position.X += 1;
} }
this.DataContext = new Board(9, 9, Objects, garbageCollector); //board = board.BoardRefresh(Objects, garbageCollector);
//this.DataContext = board;
this.DataContext = new Board(Objects, garbageCollector);
} }
} }
} }

View File

@ -14,18 +14,16 @@ namespace CzokoŚmieciarka.WPF.Models
{ {
public class Board public class Board
{ {
int _rows; static int _rows = 9;
int _columns; static int _columns = 9;
List<Tile> _tiles = new List<Tile>(); List<Tile> _tiles = new List<Tile>();
private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png"); private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(_columns, new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png");
public Board(int rows, int columns, List<IObject> objects, GarbageCollector garbageCollector) public Board(List<IObject> objects, GarbageCollector garbageCollector)
{ {
_rows = rows; for (int r = 0; r < _rows; r++)
_columns = columns;
for (int r = 0; r < rows; r++)
{ {
for (int c = 0; c < columns; c++) for (int c = 0; c < _columns; c++)
{ {
Road road = new Road(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png"); Road road = new Road(AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\intersection.png");
_tiles.Add(new Tile() _tiles.Add(new Tile()
@ -38,28 +36,27 @@ namespace CzokoŚmieciarka.WPF.Models
foreach(var item in objects) foreach(var item in objects)
{ {
_tiles[item.Location.X + item.Location.Y * _columns].Object = item; _tiles[item.Location.X + item.Location.Y].Object = item;
} }
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = new ImageBrush(new BitmapImage(new Uri(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath)));
garbageCollectorWPF.Move(_columns, garbageCollector); garbageCollectorWPF.Move(_columns, garbageCollector);
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps( _tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps(
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath), new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
new Bitmap(garbageCollectorWPF.ImagePath)); new Bitmap(garbageCollectorWPF.ImagePath));
} }
public Board BoardRefresh(List<IObject> objects, GarbageCollector garbageCollector) //public void BoardRefresh(List<IObject> objects, GarbageCollector garbageCollector)
{ //{
foreach (var item in objects) // foreach (var item in objects)
{ // {
_tiles[item.Location.X + item.Location.Y * _columns].Object = item; // _tiles[item.Location.X + item.Location.Y * _columns].Object = item;
} // }
garbageCollectorWPF.Move(_columns, garbageCollector); // garbageCollectorWPF.Move(_columns, garbageCollector);
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps( // _tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps(
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath), // new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
new Bitmap(garbageCollectorWPF.ImagePath)); // new Bitmap(garbageCollectorWPF.ImagePath));
return this; //}
}
public int Rows public int Rows
{ {

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Interfaces;
using CzokoŚmieciarka.DataModels.Models;
namespace CzokoŚmieciarka.WPF.Models
{
class DumpWPF : IObject, INotifyPropertyChanged
{
public Coords Location { get; set; }
public string ImagePath { get; set; }
public string Data { get; set; }
public ImageBrush Image { get; set; }
public ITypeOfGarbage TypeOfGarbage { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public DumpWPF(int columns, Coords location, ITypeOfGarbage typeOfGarbage)
{
Location = new Coords(location.X, location.Y * columns);
TypeOfGarbage = typeOfGarbage;
switch (TypeOfGarbage.GarbageType)
{
case "glass":
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\glass.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Szkło";
break;
case "plasticmetal":
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\plasticmetal.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Plastiki i metale";
break;
case "organic":
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\organic.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Organiczne";
break;
case "paper":
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\paper.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Papier";
break;
}
}
}
}

View File

@ -27,9 +27,9 @@ namespace CzokoŚmieciarka.WPF.Models
public string Data { get; set; } public string Data { get; set; }
public ImageBrush Image { get; set; } public ImageBrush Image { get; set; }
public GarbageCollectorWPF(Coords location, string imagePath) public GarbageCollectorWPF(int columns,Coords location, string imagePath)
{ {
Location = location; Location = new Coords(location.X, location.Y * columns);
ImagePath = imagePath; ImagePath = imagePath;
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath))); Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
} }

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.DataModels.Models;
namespace CzokoŚmieciarka.WPF.Models namespace CzokoŚmieciarka.WPF.Models
@ -14,5 +15,13 @@ namespace CzokoŚmieciarka.WPF.Models
public string ImagePath { get; set; } public string ImagePath { get; set; }
public string Data { get; set; } public string Data { get; set; }
public ImageBrush Image { get; set; } public ImageBrush Image { get; set; }
public House(int columns, Coords location)
{
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Location = new Coords(location.X, location.Y*columns);
Data = "House";
}
} }
} }