Usprawnienie poruszania
This commit is contained in:
parent
d20cdcd6f9
commit
9ff635db9f
@ -42,6 +42,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Enums\GarbageTypes.cs" />
|
||||||
<Compile Include="Exceptions.cs" />
|
<Compile Include="Exceptions.cs" />
|
||||||
<Compile Include="Enums\Directions.cs" />
|
<Compile Include="Enums\Directions.cs" />
|
||||||
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.DataModels.Enums
|
||||||
|
{
|
||||||
|
public enum GarbageType
|
||||||
|
{
|
||||||
|
Glass,
|
||||||
|
PlasticMetal,
|
||||||
|
Organic,
|
||||||
|
Paper
|
||||||
|
}
|
||||||
|
}
|
@ -78,6 +78,7 @@
|
|||||||
<Compile Include="Models\House.cs" />
|
<Compile Include="Models\House.cs" />
|
||||||
<Compile Include="Models\Road.cs" />
|
<Compile Include="Models\Road.cs" />
|
||||||
<Compile Include="Models\Tile.cs" />
|
<Compile Include="Models\Tile.cs" />
|
||||||
|
<Compile Include="Models\Trash.cs" />
|
||||||
<Compile Include="Properties\Annotations.cs" />
|
<Compile Include="Properties\Annotations.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
xmlns:local="clr-namespace:CzokoŚmieciarka.WPF"
|
xmlns:local="clr-namespace:CzokoŚmieciarka.WPF"
|
||||||
xmlns:models="clr-namespace:CzokoŚmieciarka.WPF.Models"
|
xmlns:models="clr-namespace:CzokoŚmieciarka.WPF.Models"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="800" Width="800"
|
Title="MainWindow" Height="800" Width="1000"
|
||||||
KeyDown="MainWindow_OnKeyDown">
|
KeyDown="MainWindow_OnKeyDown">
|
||||||
<ItemsControl ItemsSource="{Binding Tiles}">
|
<ItemsControl ItemsSource="{Binding Tiles}">
|
||||||
<ItemsControl.Resources>
|
<ItemsControl.Resources>
|
||||||
@ -22,4 +22,5 @@
|
|||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</ItemsControl.ItemsPanel>
|
</ItemsControl.ItemsPanel>
|
||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -14,6 +14,7 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using CzokoŚmieciarka.DataModels.Enums;
|
||||||
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
using CzokoŚmieciarka.DataModels.Interfaces;
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
@ -28,16 +29,15 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public GarbageCollector garbageCollector = new GarbageCollector(new Coords(1,1), new List<AGarbageCollectorContainer>());
|
|
||||||
//public Board board;
|
//public Board board;
|
||||||
private int rows = 9;
|
private static int rows = 9;
|
||||||
private int columns = 9;
|
private static int columns = 9;
|
||||||
|
private GarbageCollectorWPF garbageCollector = new GarbageCollectorWPF(columns, new Coords(0, 0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png");
|
||||||
private List<AObject> Objects = new List<AObject>();
|
private List<AObject> Objects = new List<AObject>();
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
List<AObject> Objects = new List<AObject>();
|
|
||||||
|
|
||||||
for (int y = 0; y < rows; y++)
|
for (int y = 0; y < rows; y++)
|
||||||
{
|
{
|
||||||
@ -70,47 +70,24 @@ namespace CzokoŚmieciarka.WPF
|
|||||||
|
|
||||||
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
|
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)
|
if (e.Key == Key.Up)
|
||||||
{
|
{
|
||||||
garbageCollector.Position.Y -= 1;
|
garbageCollector.Move(columns, Direction.Up);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.Key == Key.Down)
|
if (e.Key == Key.Down)
|
||||||
{
|
{
|
||||||
garbageCollector.Position.Y += 1;
|
garbageCollector.Move(columns, Direction.Down);
|
||||||
}
|
}
|
||||||
if (e.Key == Key.Left)
|
if (e.Key == Key.Left)
|
||||||
{
|
{
|
||||||
garbageCollector.Position.X -= 1;
|
garbageCollector.Move(columns, Direction.Left);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.Key == Key.Right)
|
if (e.Key == Key.Right)
|
||||||
{
|
{
|
||||||
garbageCollector.Position.X += 1;
|
garbageCollector.Move(columns,Direction.Right);
|
||||||
}
|
}
|
||||||
Board board = new Board(Objects, garbageCollector);
|
Board board = new Board(Objects, garbageCollector);
|
||||||
board.BoardRefresh(Objects, garbageCollector);
|
board.BoardRefresh(Objects, garbageCollector);
|
||||||
|
@ -18,9 +18,8 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
static int _rows = 9;
|
static int _rows = 9;
|
||||||
static int _columns = 9;
|
static int _columns = 9;
|
||||||
List<Tile> _tiles = new List<Tile>();
|
List<Tile> _tiles = new List<Tile>();
|
||||||
private GarbageCollectorWPF garbageCollectorWPF = new GarbageCollectorWPF(_columns, new Coords(0,0), AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\garbageCollector.png");
|
|
||||||
|
|
||||||
public Board(List<AObject> objects, GarbageCollector garbageCollector)
|
public Board(List<AObject> objects, GarbageCollectorWPF garbageCollector)
|
||||||
{
|
{
|
||||||
foreach(var item in objects)
|
foreach(var item in objects)
|
||||||
{
|
{
|
||||||
@ -31,12 +30,12 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
};
|
};
|
||||||
_tiles.Add(tile);
|
_tiles.Add(tile);
|
||||||
}
|
}
|
||||||
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps(
|
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
|
||||||
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
|
new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.ImagePath),
|
||||||
new Bitmap(garbageCollectorWPF.ImagePath));
|
new Bitmap(garbageCollector.ImagePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BoardRefresh(List<AObject> objects, GarbageCollector garbageCollector)
|
public void BoardRefresh(List<AObject> objects, GarbageCollectorWPF garbageCollector)
|
||||||
{
|
{
|
||||||
foreach (var item in objects)
|
foreach (var item in objects)
|
||||||
{
|
{
|
||||||
@ -45,10 +44,9 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
garbageCollectorWPF.Move(_columns, garbageCollector);
|
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
|
||||||
_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.Image = MergedBitmaps(
|
new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.ImagePath),
|
||||||
new Bitmap(_tiles[garbageCollectorWPF.Location.X + garbageCollectorWPF.Location.Y].Object.ImagePath),
|
new Bitmap(garbageCollector.ImagePath));
|
||||||
new Bitmap(garbageCollectorWPF.ImagePath));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Rows
|
public int Rows
|
||||||
|
@ -7,6 +7,7 @@ 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 System.Windows.Media.Imaging;
|
||||||
|
using CzokoŚmieciarka.DataModels.Enums;
|
||||||
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
using CzokoŚmieciarka.DataModels.Models;
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
using CzokoŚmieciarka.WPF.Annotations;
|
using CzokoŚmieciarka.WPF.Annotations;
|
||||||
@ -16,10 +17,23 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
{
|
{
|
||||||
public class GarbageCollectorWPF : AObject, INotifyPropertyChanged
|
public class GarbageCollectorWPF : AObject, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public void Move(int columns, GarbageCollector garbageCollector)
|
public void Move(int columns, Direction direction)
|
||||||
{
|
{
|
||||||
Location.X = garbageCollector.Position.X;
|
switch (direction)
|
||||||
Location.Y = garbageCollector.Position.Y * columns;
|
{
|
||||||
|
case (Direction.Up):
|
||||||
|
Location.Y = Location.Y + (-1 * columns);
|
||||||
|
break;
|
||||||
|
case (Direction.Down):
|
||||||
|
Location.Y = Location.Y + (1 * columns);
|
||||||
|
break;
|
||||||
|
case (Direction.Left):
|
||||||
|
Location.X = Location.X + (-1);
|
||||||
|
break;
|
||||||
|
case (Direction.Right):
|
||||||
|
Location.X = Location.X + (1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,12 +12,13 @@ namespace CzokoŚmieciarka.WPF.Models
|
|||||||
{
|
{
|
||||||
public class House : AObject
|
public class House : AObject
|
||||||
{
|
{
|
||||||
|
public List<Trash> Trashes = new List<Trash>(4);
|
||||||
public House(int columns, Coords location)
|
public House(int columns, Coords location)
|
||||||
{
|
{
|
||||||
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
|
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
|
||||||
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
|
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
|
||||||
Location = new Coords(location.X, location.Y*columns);
|
Location = new Coords(location.X, location.Y*columns);
|
||||||
Data = "House";
|
Data = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
Trunk/Interface/CzokoŚmieciarka.WPF/Models/Trash.cs
Normal file
21
Trunk/Interface/CzokoŚmieciarka.WPF/Models/Trash.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CzokoŚmieciarka.DataModels.Enums;
|
||||||
|
|
||||||
|
namespace CzokoŚmieciarka.WPF.Models
|
||||||
|
{
|
||||||
|
public class Trash
|
||||||
|
{
|
||||||
|
public GarbageType Type { get; set; }
|
||||||
|
public int Weight { get; set; }
|
||||||
|
|
||||||
|
public Trash(GarbageType type, int weight)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
Weight = weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user