diff --git a/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs b/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs index b212af0..8d02b5f 100644 --- a/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs +++ b/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs @@ -5,6 +5,6 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces { public interface IDrawables { - void Draw(ContentManager content, SpriteBatch spriteBatch, int size); + void Draw(SpriteBatch spriteBatch, int size); } } diff --git a/Trunk/MonoGameView/DataModels/MapLoader.cs b/Trunk/MonoGameView/DataModels/MapLoader.cs index 77c61eb..f3fe9b0 100644 --- a/Trunk/MonoGameView/DataModels/MapLoader.cs +++ b/Trunk/MonoGameView/DataModels/MapLoader.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Xml; using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models; +using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; using CzokoŚmieciarka.MonoGameView.DataModels.Models; using MonoGameView.DataModels.Models; @@ -12,14 +13,14 @@ namespace MonoGameView.DataModels { public class MapLoader { - public void Load(out int size, out object[,] grid, string filename) + public void Load(out int size, out IDrawables[,] grid, string filename) { XmlDocument xml = new XmlDocument(); xml.Load(filename); XmlNode node = xml.GetElementsByTagName("Map").Item(0); XmlNode sizeNode = node.SelectSingleNode("/Map/Size"); size = Convert.ToInt32(sizeNode.InnerText); - grid = new object[size,size]; + grid = new IDrawables[size,size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) diff --git a/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs b/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs index 206cf26..b22d054 100644 --- a/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs +++ b/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs @@ -9,7 +9,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; - +using MonoGameView.DataModels.Models; + namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { public class GarbageCollector : AGarbageCollector, IDrawables @@ -18,9 +19,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { } - public void Draw(ContentManager content, SpriteBatch batch,int size) + public void Draw(SpriteBatch batch,int size) { - batch.Draw(content.Load("collector"), new Rectangle(Coords.X*500/size, Coords.Y*500/size, 500/size, 500/size), Color.White); + batch.Draw(ImageContainer.GetImage("collector"), new Rectangle(Coords.X*500/size, Coords.Y*500/size, 500/size, 500/size), Color.White); } diff --git a/Trunk/MonoGameView/DataModels/Models/Grass.cs b/Trunk/MonoGameView/DataModels/Models/Grass.cs index d450ab9..180fbcc 100644 --- a/Trunk/MonoGameView/DataModels/Models/Grass.cs +++ b/Trunk/MonoGameView/DataModels/Models/Grass.cs @@ -20,9 +20,9 @@ namespace MonoGameView.DataModels.Models Coords = coords; } - public void Draw(ContentManager content, SpriteBatch batch, int size) + public void Draw(SpriteBatch batch, int size) { - batch.Draw(content.Load("grass"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); + batch.Draw(ImageContainer.GetImage("grass"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); } } } diff --git a/Trunk/MonoGameView/DataModels/Models/House.cs b/Trunk/MonoGameView/DataModels/Models/House.cs index 66fe936..c8be10d 100644 --- a/Trunk/MonoGameView/DataModels/Models/House.cs +++ b/Trunk/MonoGameView/DataModels/Models/House.cs @@ -7,7 +7,8 @@ using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; - +using MonoGameView.DataModels.Models; + namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { public class House : IDrawables @@ -18,9 +19,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { Coords = coords; } - public void Draw(ContentManager content, SpriteBatch batch, int size) + public void Draw(SpriteBatch batch, int size) { - batch.Draw(content.Load("house"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); + batch.Draw(ImageContainer.GetImage("house"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); } } } diff --git a/Trunk/MonoGameView/DataModels/Models/ImageContainer.cs b/Trunk/MonoGameView/DataModels/Models/ImageContainer.cs new file mode 100644 index 0000000..be08600 --- /dev/null +++ b/Trunk/MonoGameView/DataModels/Models/ImageContainer.cs @@ -0,0 +1,37 @@ +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MonoGameView.DataModels.Models +{ + public sealed class ImageContainer + { + static ImageContainer _container = null; + private Dictionary Images; + public static void InitContainer(ContentManager content) + { + _container = new ImageContainer(); + _container.Images = new Dictionary(); + _container.Images.Add("house", content.Load("house")); + _container.Images.Add("road1", content.Load("road1")); + _container.Images.Add("road2", content.Load("road2")); + _container.Images.Add("grass", content.Load("grass")); + _container.Images.Add("collector", content.Load("collector")); + } + + public static Texture2D GetImage(string s) + { + return _container.Images[s]; + } + + + public ImageContainer() + { + + } + } +} diff --git a/Trunk/MonoGameView/DataModels/Models/Road1.cs b/Trunk/MonoGameView/DataModels/Models/Road1.cs index 399dbec..b3d2c1f 100644 --- a/Trunk/MonoGameView/DataModels/Models/Road1.cs +++ b/Trunk/MonoGameView/DataModels/Models/Road1.cs @@ -7,10 +7,11 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; - +using MonoGameView.DataModels.Models; + namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { - public class Road1 :IRoad1 + public class Road1 :IRoad1, IDrawables { private Coords Coords; @@ -19,9 +20,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models Coords = coords; } - public void Draw(ContentManager content, SpriteBatch batch, int size) + public void Draw(SpriteBatch batch, int size) { - batch.Draw(content.Load("grass"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); + batch.Draw(ImageContainer.GetImage("road1"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); } } } diff --git a/Trunk/MonoGameView/DataModels/Models/Road2.cs b/Trunk/MonoGameView/DataModels/Models/Road2.cs index 1838d6b..01adf2b 100644 --- a/Trunk/MonoGameView/DataModels/Models/Road2.cs +++ b/Trunk/MonoGameView/DataModels/Models/Road2.cs @@ -1,4 +1,7 @@ using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonoGameView.DataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -7,7 +10,18 @@ using System.Threading.Tasks; namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { - public class Road2 : IRoad2 + public class Road2 : IRoad2, IDrawables { + private Coords Coords; + + public Road2(Coords coords) + { + Coords = coords; + } + + public void Draw(SpriteBatch batch, int size) + { + batch.Draw(ImageContainer.GetImage("road2"), new Rectangle(Coords.X * 500 / size, Coords.Y * 500 / size, 500 / size, 500 / size), Color.White); + } } } diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs index 6f377fa..4d5478b 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/MoveStep.cs @@ -23,7 +23,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps public void Invoke(IGarbageCollector _garbageCollector, object[,] grid) { if(grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] is Road1) - grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] = new Road2(); + grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] = new Road2(new Coords(_garbageCollector.Coords.X, _garbageCollector.Coords.Y)); switch (_direction) { case Direction.Up: _garbageCollector.MoveUp(); break; diff --git a/Trunk/MonoGameView/Game1.cs b/Trunk/MonoGameView/Game1.cs index 1426aba..5fc0aa8 100644 --- a/Trunk/MonoGameView/Game1.cs +++ b/Trunk/MonoGameView/Game1.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using CzokoŚmieciarka.MonoGameView.Algorithms; using MonoGameView.DataModels; +using MonoGameView.DataModels.Models; namespace CzokoŚmieciarka.MonoGameView { @@ -32,7 +33,7 @@ namespace CzokoŚmieciarka.MonoGameView int stepN; List steps; GarbageCollector collector; - object[,] grid; + IDrawables[,] grid; public Game1() { graphics = new GraphicsDeviceManager(this); @@ -51,6 +52,8 @@ namespace CzokoŚmieciarka.MonoGameView /// protected override void Initialize() { + + ImageContainer.InitContainer(Content); // TODO: Add your initialization logic here roadPos = new Vector2(0, 0); timer = 0.2f; @@ -129,13 +132,14 @@ namespace CzokoŚmieciarka.MonoGameView { for (int y = 0; y < size; y++) { - if (grid[x, y] is Road1) spriteBatch.Draw(road1, new Rectangle(x*500 / size, y*500 / size, 500/size, 500/size),Color.White); - else if (grid[x,y] is Road2) spriteBatch.Draw(road2, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); - else if (grid[x, y] is House) spriteBatch.Draw(house, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); - else spriteBatch.Draw(grass, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); + //if (grid[x, y] is Road1) spriteBatch.Draw(road1, new Rectangle(x*500 / size, y*500 / size, 500/size, 500/size),Color.White); + //else if (grid[x,y] is Road2) spriteBatch.Draw(road2, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); + //else if (grid[x, y] is House) spriteBatch.Draw(house, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); + //else spriteBatch.Draw(grass, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); + grid[x, y].Draw(spriteBatch, size); } } - collector.Draw(Content, spriteBatch, size); + collector.Draw(spriteBatch, size); spriteBatch.End(); // TODO: Add your drawing code here diff --git a/Trunk/MonoGameView/MonoGameView.csproj b/Trunk/MonoGameView/MonoGameView.csproj index 3c34106..4085629 100644 --- a/Trunk/MonoGameView/MonoGameView.csproj +++ b/Trunk/MonoGameView/MonoGameView.csproj @@ -70,6 +70,7 @@ +