naprawione

This commit is contained in:
ryuga4 2019-04-22 14:55:47 +02:00
parent 0b534d67b3
commit 97cd3630fc
11 changed files with 83 additions and 23 deletions

View File

@ -5,6 +5,6 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces
{ {
public interface IDrawables public interface IDrawables
{ {
void Draw(ContentManager content, SpriteBatch spriteBatch, int size); void Draw(SpriteBatch spriteBatch, int size);
} }
} }

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models; using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
using CzokoŚmieciarka.MonoGameView.DataModels.Models; using CzokoŚmieciarka.MonoGameView.DataModels.Models;
using MonoGameView.DataModels.Models; using MonoGameView.DataModels.Models;
@ -12,14 +13,14 @@ namespace MonoGameView.DataModels
{ {
public class MapLoader 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(); XmlDocument xml = new XmlDocument();
xml.Load(filename); xml.Load(filename);
XmlNode node = xml.GetElementsByTagName("Map").Item(0); XmlNode node = xml.GetElementsByTagName("Map").Item(0);
XmlNode sizeNode = node.SelectSingleNode("/Map/Size"); XmlNode sizeNode = node.SelectSingleNode("/Map/Size");
size = Convert.ToInt32(sizeNode.InnerText); size = Convert.ToInt32(sizeNode.InnerText);
grid = new object[size,size]; grid = new IDrawables[size,size];
for (int x = 0; x < size; x++) for (int x = 0; x < size; x++)
{ {
for (int y = 0; y < size; y++) for (int y = 0; y < size; y++)

View File

@ -9,7 +9,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using MonoGameView.DataModels.Models;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{ {
public class GarbageCollector : AGarbageCollector, IDrawables 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<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);
} }

View File

@ -20,9 +20,9 @@ namespace MonoGameView.DataModels.Models
Coords = coords; 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);
} }
} }
} }

View File

@ -7,7 +7,8 @@ using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MonoGameView.DataModels.Models;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{ {
public class House : IDrawables public class House : IDrawables
@ -18,9 +19,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{ {
Coords = coords; 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);
} }
} }
} }

View 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()
{
}
}
}

View File

@ -7,10 +7,11 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MonoGameView.DataModels.Models;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
{ {
public class Road1 :IRoad1 public class Road1 :IRoad1, IDrawables
{ {
private Coords Coords; private Coords Coords;
@ -19,9 +20,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
Coords = coords; 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);
} }
} }
} }

View File

@ -1,4 +1,7 @@
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGameView.DataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,7 +10,18 @@ using System.Threading.Tasks;
namespace CzokoŚmieciarka.MonoGameView.DataModels.Models 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);
}
} }
} }

View File

@ -23,7 +23,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
public void Invoke(IGarbageCollector _garbageCollector, object[,] grid) public void Invoke(IGarbageCollector _garbageCollector, object[,] grid)
{ {
if(grid[_garbageCollector.Coords.X, _garbageCollector.Coords.Y] is Road1) 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) switch (_direction)
{ {
case Direction.Up: _garbageCollector.MoveUp(); break; case Direction.Up: _garbageCollector.MoveUp(); break;

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using CzokoŚmieciarka.MonoGameView.Algorithms; using CzokoŚmieciarka.MonoGameView.Algorithms;
using MonoGameView.DataModels; using MonoGameView.DataModels;
using MonoGameView.DataModels.Models;
namespace CzokoŚmieciarka.MonoGameView namespace CzokoŚmieciarka.MonoGameView
{ {
@ -32,7 +33,7 @@ namespace CzokoŚmieciarka.MonoGameView
int stepN; int stepN;
List<IStep> steps; List<IStep> steps;
GarbageCollector collector; GarbageCollector collector;
object[,] grid; IDrawables[,] grid;
public Game1() public Game1()
{ {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
@ -51,6 +52,8 @@ namespace CzokoŚmieciarka.MonoGameView
/// </summary> /// </summary>
protected override void Initialize() protected override void Initialize()
{ {
ImageContainer.InitContainer(Content);
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
roadPos = new Vector2(0, 0); roadPos = new Vector2(0, 0);
timer = 0.2f; timer = 0.2f;
@ -129,13 +132,14 @@ namespace CzokoŚmieciarka.MonoGameView
{ {
for (int y = 0; y < size; y++) 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); //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 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 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); //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(); spriteBatch.End();
// TODO: Add your drawing code here // TODO: Add your drawing code here

View File

@ -70,6 +70,7 @@
<Compile Include="DataModels\Models\GarbageLocalization.cs" /> <Compile Include="DataModels\Models\GarbageLocalization.cs" />
<Compile Include="DataModels\Models\Grass.cs" /> <Compile Include="DataModels\Models\Grass.cs" />
<Compile Include="DataModels\Models\House.cs" /> <Compile Include="DataModels\Models\House.cs" />
<Compile Include="DataModels\Models\ImageContainer.cs" />
<Compile Include="DataModels\Models\Map.cs" /> <Compile Include="DataModels\Models\Map.cs" />
<Compile Include="DataModels\Models\Road1.cs" /> <Compile Include="DataModels\Models\Road1.cs" />
<Compile Include="DataModels\Models\Road2.cs" /> <Compile Include="DataModels\Models\Road2.cs" />