naprawione
This commit is contained in:
parent
0b534d67b3
commit
97cd3630fc
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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++)
|
||||
|
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MonoGameView.DataModels.Models;
|
||||
|
||||
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
|
||||
{
|
||||
@ -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<Texture2D>("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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<Texture2D>("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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
|
||||
{
|
||||
@ -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<Texture2D>("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
Trunk/MonoGameView/DataModels/Models/ImageContainer.cs
Normal file
37
Trunk/MonoGameView/DataModels/Models/ImageContainer.cs
Normal file
@ -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<string, Texture2D> Images;
|
||||
public static void InitContainer(ContentManager content)
|
||||
{
|
||||
_container = new ImageContainer();
|
||||
_container.Images = new Dictionary<string, Texture2D>();
|
||||
_container.Images.Add("house", content.Load<Texture2D>("house"));
|
||||
_container.Images.Add("road1", content.Load<Texture2D>("road1"));
|
||||
_container.Images.Add("road2", content.Load<Texture2D>("road2"));
|
||||
_container.Images.Add("grass", content.Load<Texture2D>("grass"));
|
||||
_container.Images.Add("collector", content.Load<Texture2D>("collector"));
|
||||
}
|
||||
|
||||
public static Texture2D GetImage(string s)
|
||||
{
|
||||
return _container.Images[s];
|
||||
}
|
||||
|
||||
|
||||
public ImageContainer()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Texture2D>("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<IStep> steps;
|
||||
GarbageCollector collector;
|
||||
object[,] grid;
|
||||
IDrawables[,] grid;
|
||||
public Game1()
|
||||
{
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
@ -51,6 +52,8 @@ namespace CzokoŚmieciarka.MonoGameView
|
||||
/// </summary>
|
||||
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
|
||||
|
@ -70,6 +70,7 @@
|
||||
<Compile Include="DataModels\Models\GarbageLocalization.cs" />
|
||||
<Compile Include="DataModels\Models\Grass.cs" />
|
||||
<Compile Include="DataModels\Models\House.cs" />
|
||||
<Compile Include="DataModels\Models\ImageContainer.cs" />
|
||||
<Compile Include="DataModels\Models\Map.cs" />
|
||||
<Compile Include="DataModels\Models\Road1.cs" />
|
||||
<Compile Include="DataModels\Models\Road2.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user