Tworzenie Mapy

This commit is contained in:
Michał Dulski 2019-04-08 15:47:01 +02:00
parent 163afa21d9
commit cc9ccd26ba
2 changed files with 72 additions and 42 deletions

View File

@ -13,6 +13,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CzokoŚmieciarka.DataModels.Enums;
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.DataModels.Models;
@ -34,47 +35,9 @@ namespace CzokoŚmieciarka.WPFv2
public MainWindow()
{
ColumnDefinition column;
RowDefinition row;
InitializeComponent();
for(int i = 0; i < Rows; i++)
{
column = new ColumnDefinition();
row = new RowDefinition();
Board.ColumnDefinitions.Add(column);
Board.RowDefinitions.Add(row);
column = new ColumnDefinition();
row = new RowDefinition();
CollectorBoard.ColumnDefinitions.Add(column);
CollectorBoard.RowDefinitions.Add(row);
for (int j = 0; j < Columns; j++)
{
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);
}
IEnumerable<TrashCan> trashCans = new List<TrashCan>();
WPFHouse house = new WPFHouse(new Coords(i, i), trashCans);
Objects[i, i] = house;
Grid.SetRow(Objects[i, i].Image, i);
Grid.SetColumn(Objects[i, i].Image, i);
Board.Children.Add(Objects[i, i].Image);
}
GarbageCollectorContainers = new List<AGarbageCollectorContainer>();
garbageCollector = new WPFGarbageCollector(new Coords(2, 1), GarbageCollectorContainers);
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X);
CollectorBoard.Children.Add(garbageCollector.Image);
CollectorBoard.ShowGridLines = true;
CollectorInfo.ItemsSource = garbageCollector.TrashContainers;
//CollectorInfo.Items.Add(garbageCollector);
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")});
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") });
BoardInitialize();
}
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
@ -91,5 +54,73 @@ namespace CzokoŚmieciarka.WPFv2
CollectorBoard.Children.Add(garbageCollector.Image);
}
private void BoardInitialize()
{
ColumnDefinition column;
RowDefinition row;
for (int i = 0; i < Rows; i++)
{
column = new ColumnDefinition();
row = new RowDefinition();
Board.ColumnDefinitions.Add(column);
Board.RowDefinitions.Add(row);
column = new ColumnDefinition();
row = new RowDefinition();
CollectorBoard.ColumnDefinitions.Add(column);
CollectorBoard.RowDefinitions.Add(row);
for (int j = 0; j < Columns; j++)
{
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);
}
IEnumerable<TrashCan> trashCans = new List<TrashCan>();
WPFHouse house = new WPFHouse(new Coords(i, i), trashCans);
Objects[i, i] = house;
Grid.SetRow(Objects[i, i].Image, i);
Grid.SetColumn(Objects[i, i].Image, i);
Board.Children.Add(Objects[i, i].Image);
}
Objects[2,7] = new WPFDump(new TypeOfGarbage(GarbageType.Glass,1,1), 10000,new Coords(2,7));
Grid.SetColumn(Objects[2, 7].Image, 2);
Grid.SetRow(Objects[2, 7].Image, 7);
Board.Children.Add(Objects[2, 7].Image);
Objects[3,7] = new WPFDump(new TypeOfGarbage(GarbageType.Organic,1,1),10000, new Coords(3,7));
Grid.SetColumn(Objects[3, 7].Image, 3);
Grid.SetRow(Objects[3, 7].Image, 7);
Board.Children.Add(Objects[3, 7].Image);
Objects[2,8] = new WPFDump(new TypeOfGarbage(GarbageType.Paper,1,1), 10000, new Coords(2,8));
Grid.SetColumn(Objects[2, 8].Image, 2);
Grid.SetRow(Objects[2, 8].Image, 8);
Board.Children.Add(Objects[2, 8].Image);
Objects[3,8] = new WPFDump(new TypeOfGarbage(GarbageType.PlasticMetal, 1,1), 10000, new Coords(3,8));
Grid.SetColumn(Objects[3, 8].Image, 3);
Grid.SetRow(Objects[3, 8].Image, 8);
Board.Children.Add(Objects[3, 8].Image);
GarbageCollectorContainers = new List<AGarbageCollectorContainer>()
{
new GarbageCollectorContainer(new TypeOfGarbage(GarbageType.Glass,1,1), 500),
new GarbageCollectorContainer(new TypeOfGarbage(GarbageType.Organic,1,1), 500),
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);
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X);
CollectorBoard.Children.Add(garbageCollector.Image);
CollectorBoard.ShowGridLines = true;
//CollectorInfo.ItemsSource = garbageCollector.TrashContainers;
//CollectorInfo.Items.Add(garbageCollector);
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")});
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") });
}
}
}

View File

@ -20,9 +20,8 @@ namespace CzokoŚmieciarka.WPFv2.Models
public string ImagePath { get; set; }
public Image Image { get; set; }
public WPFDump(ITypeOfGarbage typeofGarbage, int maxVolume, Coords localization, string imagePath) : base ( typeofGarbage, maxVolume, localization)
public WPFDump(ITypeOfGarbage typeofGarbage, int maxVolume, Coords localization) : base ( typeofGarbage, maxVolume, localization)
{
ImagePath = imagePath;
Image = new Image();
switch (typeofGarbage.GarbageType)
{