Usprawnienie poruszania
This commit is contained in:
parent
d20cdcd6f9
commit
9ff635db9f
@ -42,6 +42,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Enums\GarbageTypes.cs" />
|
||||
<Compile Include="Exceptions.cs" />
|
||||
<Compile Include="Enums\Directions.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\Road.cs" />
|
||||
<Compile Include="Models\Tile.cs" />
|
||||
<Compile Include="Models\Trash.cs" />
|
||||
<Compile Include="Properties\Annotations.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
|
@ -6,7 +6,7 @@
|
||||
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="1000"
|
||||
KeyDown="MainWindow_OnKeyDown">
|
||||
<ItemsControl ItemsSource="{Binding Tiles}">
|
||||
<ItemsControl.Resources>
|
||||
@ -22,4 +22,5 @@
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
|
||||
</Window>
|
||||
|
@ -14,6 +14,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;
|
||||
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||
@ -28,16 +29,15 @@ namespace CzokoŚmieciarka.WPF
|
||||
/// </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 static int rows = 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>();
|
||||
public MainWindow()
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
List<AObject> Objects = new List<AObject>();
|
||||
|
||||
for (int y = 0; y < rows; y++)
|
||||
{
|
||||
@ -70,47 +70,24 @@ namespace CzokoŚmieciarka.WPF
|
||||
|
||||
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;
|
||||
garbageCollector.Move(columns, Direction.Up);
|
||||
}
|
||||
|
||||
if (e.Key == Key.Down)
|
||||
{
|
||||
garbageCollector.Position.Y += 1;
|
||||
garbageCollector.Move(columns, Direction.Down);
|
||||
}
|
||||
if (e.Key == Key.Left)
|
||||
{
|
||||
garbageCollector.Position.X -= 1;
|
||||
garbageCollector.Move(columns, Direction.Left);
|
||||
}
|
||||
|
||||
if (e.Key == Key.Right)
|
||||
{
|
||||
garbageCollector.Position.X += 1;
|
||||
garbageCollector.Move(columns,Direction.Right);
|
||||
}
|
||||
Board board = new Board(Objects, garbageCollector);
|
||||
board.BoardRefresh(Objects, garbageCollector);
|
||||
|
@ -18,9 +18,8 @@ namespace CzokoŚmieciarka.WPF.Models
|
||||
static int _rows = 9;
|
||||
static int _columns = 9;
|
||||
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)
|
||||
{
|
||||
@ -31,12 +30,12 @@ namespace CzokoŚmieciarka.WPF.Models
|
||||
};
|
||||
_tiles.Add(tile);
|
||||
}
|
||||
_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));
|
||||
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
|
||||
new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.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)
|
||||
{
|
||||
@ -45,10 +44,9 @@ namespace CzokoŚmieciarka.WPF.Models
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.Image = MergedBitmaps(
|
||||
new Bitmap(_tiles[garbageCollector.Location.X + garbageCollector.Location.Y].Object.ImagePath),
|
||||
new Bitmap(garbageCollector.ImagePath));
|
||||
}
|
||||
|
||||
public int Rows
|
||||
|
@ -7,6 +7,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using CzokoŚmieciarka.DataModels.Enums;
|
||||
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||
using CzokoŚmieciarka.DataModels.Models;
|
||||
using CzokoŚmieciarka.WPF.Annotations;
|
||||
@ -16,10 +17,23 @@ namespace CzokoŚmieciarka.WPF.Models
|
||||
{
|
||||
public class GarbageCollectorWPF : AObject, INotifyPropertyChanged
|
||||
{
|
||||
public void Move(int columns, GarbageCollector garbageCollector)
|
||||
public void Move(int columns, Direction direction)
|
||||
{
|
||||
Location.X = garbageCollector.Position.X;
|
||||
Location.Y = garbageCollector.Position.Y * columns;
|
||||
switch (direction)
|
||||
{
|
||||
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 List<Trash> Trashes = new List<Trash>(4);
|
||||
public House(int columns, Coords location)
|
||||
{
|
||||
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
|
||||
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
|
||||
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