Dodano poruszanie się śmieciarki przy pomocy strzałek

This commit is contained in:
Michał Dulski 2019-03-20 16:51:35 +01:00
parent 22814fc944
commit b14fd9f43f
7 changed files with 1121 additions and 9 deletions

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Czoko_015Amieciarka_002EWPF_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -76,6 +76,7 @@
<Compile Include="Models\House.cs" />
<Compile Include="Models\Road.cs" />
<Compile Include="Models\Tile.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>

View File

@ -6,7 +6,8 @@
xmlns:local="clr-namespace:CzokoŚmieciarka.WPF"
xmlns:models="clr-namespace:CzokoŚmieciarka.WPF.Models"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="800">
Title="MainWindow" Height="800" Width="800"
KeyDown="MainWindow_OnKeyDown">
<ItemsControl ItemsSource="{Binding Tiles}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type models:Tile}">

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@ -28,7 +29,7 @@ namespace CzokoŚmieciarka.WPF
{
public List<IObject> Objects = new List<IObject>();
public GarbageCollector garbageCollector = new GarbageCollector(new Coords(0,0), new List<AGarbageCollectorContainer>());
public Board board;
public MainWindow()
{
@ -55,10 +56,30 @@ namespace CzokoŚmieciarka.WPF
Location = new Coords(7, 5),
Data = "House"
});
garbageCollector.Position.X += 1;
this.DataContext = new Board(9, 9, Objects, garbageCollector);
}
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
{
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;
}
this.DataContext = new Board(9, 9, Objects, garbageCollector);
}
}
}

View File

@ -38,17 +38,29 @@ namespace CzokoŚmieciarka.WPF.Models
foreach(var item in objects)
{
_tiles[item.Location.X + item.Location.Y * columns].Object = item;
_tiles[item.Location.X + item.Location.Y * columns].Object.Image = item.Image;
_tiles[item.Location.X + item.Location.Y * columns].Object.Data = item.Data;
_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(
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
new Bitmap(garbageCollectorWPF.ImagePath));
}
public Board BoardRefresh(List<IObject> objects, GarbageCollector garbageCollector)
{
foreach (var item in objects)
{
_tiles[item.Location.X + item.Location.Y * _columns].Object = item;
}
garbageCollectorWPF.Move(_columns, garbageCollector);
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps(
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
new Bitmap(garbageCollectorWPF.ImagePath));
return this;
}
public int Rows
{
get { return _rows; }

View File

@ -1,16 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPF.Annotations;
namespace CzokoŚmieciarka.WPF.Models
{
public class GarbageCollectorWPF : IObject
public class GarbageCollectorWPF : IObject, INotifyPropertyChanged
{
public Coords Location { get; set; }
@ -31,5 +34,12 @@ namespace CzokoŚmieciarka.WPF.Models
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

File diff suppressed because it is too large Load Diff