Czoko_Smieciarka/Trunk/Interface/CzokoŚmieciarka.WPF/MainWindow.xaml.cs
Michał Dulski 653e7cc3b7 coś tam
2019-03-26 23:20:41 +01:00

121 lines
4.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
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;
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPF.Interfaces;
using CzokoŚmieciarka.WPF.Models;
namespace CzokoŚmieciarka.WPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public GarbageCollector garbageCollector = new GarbageCollector(new Coords(1,1), new List<AGarbageCollectorContainer>());
//public Board board;
private int rows = 9;
private int columns = 9;
private List<AObject> Objects = new List<AObject>();
public MainWindow()
{
InitializeComponent();
List<AObject> Objects = new List<AObject>();
for (int y = 0; y < rows; y++)
{
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);
}
}
House house = new House(columns, new Coords(0, 0));
Objects[house.Location.X + house.Location.Y] = house;
house = new House(columns, new Coords(1, 0));
Objects[house.Location.X + house.Location.Y] = house;
house = new House(columns, new Coords(2, 0));
Objects[house.Location.X + house.Location.Y] = house;
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), new TypeOfGarbage("glass", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(2, 5), new TypeOfGarbage("plasticmetal", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(3, 4), new TypeOfGarbage("organic", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(3, 5), new TypeOfGarbage("paper", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
Board board = new Board(Objects, garbageCollector);
this.DataContext = board;
}
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
{
List<AObject> Objects = new List<AObject>();
for (int y = 0; y < rows; y++)
{
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);
}
}
House house = new House(columns, new Coords(0, 0));
Objects[house.Location.X + house.Location.Y] = house;
house = new House(columns, new Coords(1, 0));
Objects[house.Location.X + house.Location.Y] = house;
house = new House(columns, new Coords(2, 0));
Objects[house.Location.X + house.Location.Y] = house;
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), new TypeOfGarbage("glass", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(2, 5), new TypeOfGarbage("plasticmetal", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(3, 4), new TypeOfGarbage("organic", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(3, 5), new TypeOfGarbage("paper", 0, 0));
Objects[dump.Location.X + dump.Location.Y] = dump;
if (e.Key == Key.Up)
{
garbageCollector.Position.Y -= 1;
}
if (e.Key == Key.Down)
{
garbageCollector.Position.Y += 1;
}
if (e.Key == Key.Left)
{
garbageCollector.Position.X -= 1;
}
if (e.Key == Key.Right)
{
garbageCollector.Position.X += 1;
}
Board board = new Board(Objects, garbageCollector);
board.BoardRefresh(Objects, garbageCollector);
this.DataContext = board;
}
}
}