Czoko_Smieciarka/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs

96 lines
3.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPFv2.Interfaces;
using CzokoŚmieciarka.WPFv2.Models;
namespace CzokoŚmieciarka.WPFv2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static int Columns = 9;
public static int Rows = 9;
IWPFObject[,] Objects = new IWPFObject[Columns,Rows];
private IEnumerable<AGarbageCollectorContainer> GarbageCollectorContainers;
private WPFGarbageCollector garbageCollector;
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") });
}
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
{
garbageCollector.Position = garbageCollector.MoveRight();
}
CollectorBoard.Children.Clear();
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X);
CollectorBoard.Children.Add(garbageCollector.Image);
}
}
}