2019-04-22 09:24:16 +02:00
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Models;
|
2019-04-22 03:16:30 +02:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2019-04-21 02:43:36 +02:00
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
using System;
|
2019-05-11 16:03:29 +02:00
|
|
|
|
using System.CodeDom;
|
2019-04-22 03:16:30 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-04-22 09:24:16 +02:00
|
|
|
|
using CzokoŚmieciarka.MonoGameView.Algorithms;
|
2019-04-22 14:17:44 +02:00
|
|
|
|
using MonoGameView.DataModels;
|
2019-04-22 14:55:47 +02:00
|
|
|
|
using MonoGameView.DataModels.Models;
|
2019-04-23 06:32:35 +02:00
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models;
|
|
|
|
|
using CzokoŚmieciarka.MonoGameView.DataModels.Enums;
|
2019-04-23 11:24:07 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Threading;
|
2019-05-04 15:56:55 +02:00
|
|
|
|
using MonoGameView.Algorithms;
|
2019-04-21 02:43:36 +02:00
|
|
|
|
|
2019-04-22 03:16:30 +02:00
|
|
|
|
namespace CzokoŚmieciarka.MonoGameView
|
2019-04-21 02:43:36 +02:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is the main type for your game.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Game1 : Game
|
|
|
|
|
{
|
2019-04-22 14:17:44 +02:00
|
|
|
|
private static int size;
|
2019-04-21 02:43:36 +02:00
|
|
|
|
GraphicsDeviceManager graphics;
|
|
|
|
|
SpriteBatch spriteBatch;
|
2019-04-23 11:24:01 +02:00
|
|
|
|
private SpriteFont font;
|
|
|
|
|
private int score = 0;
|
2019-04-22 14:17:44 +02:00
|
|
|
|
MapLoader mapLoader = new MapLoader();
|
2019-04-21 02:43:36 +02:00
|
|
|
|
Vector2 roadPos;
|
2019-04-22 03:16:30 +02:00
|
|
|
|
float timer;
|
2019-05-14 23:05:37 +02:00
|
|
|
|
const float TIMER = 0.1f;
|
2019-04-22 03:16:30 +02:00
|
|
|
|
int stepN;
|
|
|
|
|
List<IStep> steps;
|
|
|
|
|
GarbageCollector collector;
|
2019-04-22 14:55:47 +02:00
|
|
|
|
IDrawables[,] grid;
|
2019-05-14 14:12:04 +02:00
|
|
|
|
Displayer displayer = new Displayer();
|
2019-05-11 16:03:29 +02:00
|
|
|
|
|
|
|
|
|
|
2019-04-21 02:43:36 +02:00
|
|
|
|
public Game1()
|
|
|
|
|
{
|
|
|
|
|
graphics = new GraphicsDeviceManager(this);
|
|
|
|
|
Content.RootDirectory = "Content";
|
2019-05-14 23:05:37 +02:00
|
|
|
|
graphics.PreferredBackBufferWidth =1400;
|
|
|
|
|
graphics.PreferredBackBufferHeight =1000;
|
2019-04-21 02:43:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 03:16:30 +02:00
|
|
|
|
|
|
|
|
|
|
2019-04-21 02:43:36 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Allows the game to perform any initialization it needs to before starting to run.
|
|
|
|
|
/// This is where it can query for any required services and load any non-graphic
|
|
|
|
|
/// related content. Calling base.Initialize will enumerate through any components
|
|
|
|
|
/// and initialize them as well.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void Initialize()
|
|
|
|
|
{
|
2019-04-22 14:55:47 +02:00
|
|
|
|
|
|
|
|
|
ImageContainer.InitContainer(Content);
|
2019-04-21 02:43:36 +02:00
|
|
|
|
// TODO: Add your initialization logic here
|
2019-05-14 23:05:37 +02:00
|
|
|
|
timer = 1f;
|
2019-04-22 03:16:30 +02:00
|
|
|
|
|
2019-05-14 23:05:37 +02:00
|
|
|
|
mapLoader.Load(out size,out grid,"mapa4.xml");
|
2019-04-23 06:32:35 +02:00
|
|
|
|
var containers = new List<GarbageCollectorContainer>()
|
|
|
|
|
{
|
|
|
|
|
new GarbageCollectorContainer(
|
2019-04-23 11:24:07 +02:00
|
|
|
|
new TypeOfGarbage(GarbageType.Glass,1),
|
2019-05-14 23:05:37 +02:00
|
|
|
|
1000,
|
2019-04-23 11:24:07 +02:00
|
|
|
|
new BasicGarbage(new TypeOfGarbage(GarbageType.Glass,1),0)
|
2019-04-23 06:32:35 +02:00
|
|
|
|
),
|
2019-04-23 09:30:16 +02:00
|
|
|
|
new GarbageCollectorContainer(
|
2019-04-23 11:24:07 +02:00
|
|
|
|
new TypeOfGarbage(GarbageType.Paper,1),
|
2019-05-14 23:05:37 +02:00
|
|
|
|
1000,
|
2019-05-14 14:12:04 +02:00
|
|
|
|
new BasicGarbage(new TypeOfGarbage(GarbageType.Paper,1),0)
|
2019-04-23 09:30:16 +02:00
|
|
|
|
),
|
|
|
|
|
new GarbageCollectorContainer(
|
2019-04-23 11:24:07 +02:00
|
|
|
|
new TypeOfGarbage(GarbageType.Organic,1),
|
2019-05-14 23:05:37 +02:00
|
|
|
|
1000,
|
2019-05-14 14:12:04 +02:00
|
|
|
|
new BasicGarbage(new TypeOfGarbage(GarbageType.Organic,1),0)
|
2019-04-23 09:30:16 +02:00
|
|
|
|
),
|
|
|
|
|
new GarbageCollectorContainer(
|
2019-04-23 11:24:07 +02:00
|
|
|
|
new TypeOfGarbage(GarbageType.PlasticMetal,1),
|
2019-05-14 23:05:37 +02:00
|
|
|
|
1000,
|
2019-05-14 14:12:04 +02:00
|
|
|
|
new BasicGarbage(new TypeOfGarbage(GarbageType.PlasticMetal,1),0)
|
2019-04-23 09:30:16 +02:00
|
|
|
|
),
|
|
|
|
|
|
2019-04-23 06:32:35 +02:00
|
|
|
|
};
|
2019-05-14 21:42:05 +02:00
|
|
|
|
collector = new GarbageCollector(new Coords(1,1), containers, size, size,0);
|
2019-04-22 03:16:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stepN = 0;
|
2019-05-14 21:42:05 +02:00
|
|
|
|
var dfs = new DFS(collector,grid);
|
2019-05-14 23:05:37 +02:00
|
|
|
|
var r = dfs.BestPath(Content, collector, grid);
|
|
|
|
|
steps = r.Key;
|
|
|
|
|
Console.WriteLine(r);
|
|
|
|
|
//displayer.Add("Count", r.Value.ToString());
|
|
|
|
|
//new Thread(delegate() {
|
|
|
|
|
// var x = dfs.BestPath(Content, collector, grid);
|
2019-05-04 15:53:04 +02:00
|
|
|
|
|
2019-05-14 23:05:37 +02:00
|
|
|
|
//}).Start();
|
2019-04-22 03:16:30 +02:00
|
|
|
|
|
2019-04-21 02:43:36 +02:00
|
|
|
|
base.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// LoadContent will be called once per game and is the place to load
|
|
|
|
|
/// all of your content.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void LoadContent()
|
|
|
|
|
{
|
|
|
|
|
// Create a new SpriteBatch, which can be used to draw textures.
|
|
|
|
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
2019-04-23 11:24:01 +02:00
|
|
|
|
font = Content.Load<SpriteFont>("arial");
|
2019-05-14 23:05:37 +02:00
|
|
|
|
|
2019-04-21 02:43:36 +02:00
|
|
|
|
// TODO: use this.Content to load your game content here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// UnloadContent will be called once per game and is the place to unload
|
|
|
|
|
/// game-specific content.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void UnloadContent()
|
|
|
|
|
{
|
2019-04-22 09:24:16 +02:00
|
|
|
|
Content.Unload();
|
2019-04-21 02:43:36 +02:00
|
|
|
|
// TODO: Unload any non ContentManager content here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Allows the game to run logic such as updating the world,
|
|
|
|
|
/// checking for collisions, gathering input, and playing audio.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
|
|
|
|
Exit();
|
2019-05-14 23:05:37 +02:00
|
|
|
|
|
2019-05-05 17:54:12 +02:00
|
|
|
|
var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
2019-04-22 03:16:30 +02:00
|
|
|
|
timer -= elapsed;
|
|
|
|
|
if (timer<0)
|
|
|
|
|
{
|
|
|
|
|
timer = TIMER;
|
|
|
|
|
if (steps.Any())
|
|
|
|
|
{
|
|
|
|
|
steps.First().Invoke(collector, grid);
|
|
|
|
|
steps.RemoveAt(0);
|
|
|
|
|
}
|
2019-05-05 17:54:12 +02:00
|
|
|
|
}
|
2019-05-14 23:05:37 +02:00
|
|
|
|
|
2019-04-21 02:43:36 +02:00
|
|
|
|
// TODO: Add your update logic here
|
2019-05-14 14:12:04 +02:00
|
|
|
|
var barsDictionary = new Dictionary<string, int>();
|
2019-05-13 19:22:46 +02:00
|
|
|
|
var collectorDictionary = new Dictionary<string, string>
|
|
|
|
|
{
|
2019-05-14 14:12:04 +02:00
|
|
|
|
{"Garbage Collector Info", ""}
|
2019-05-13 19:22:46 +02:00
|
|
|
|
};
|
2019-05-14 14:12:04 +02:00
|
|
|
|
foreach (GarbageCollectorContainer container in collector.TrashContainers)
|
|
|
|
|
{
|
|
|
|
|
collectorDictionary.Add(container.TypeOfGarbage.GarbageType.ToString(), container.Garbage.Weight.ToString());
|
|
|
|
|
barsDictionary.Add(container.TypeOfGarbage.GarbageType.ToString(), (int) Math.Round(container.FillPercent * 100));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displayer.info = collectorDictionary;
|
|
|
|
|
displayer.barsPercent = barsDictionary;
|
2019-04-21 02:43:36 +02:00
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is called when the game should draw itself.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
|
|
|
|
spriteBatch.Begin();
|
|
|
|
|
|
2019-04-22 10:39:00 +02:00
|
|
|
|
for (int x = 0; x < size; x++)
|
2019-04-22 03:16:30 +02:00
|
|
|
|
{
|
2019-04-22 10:39:00 +02:00
|
|
|
|
for (int y = 0; y < size; y++)
|
2019-04-22 03:16:30 +02:00
|
|
|
|
{
|
2019-05-14 23:05:37 +02:00
|
|
|
|
grid[x, y].Draw(spriteBatch, size, graphics.PreferredBackBufferHeight);
|
2019-04-22 03:16:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-14 23:05:37 +02:00
|
|
|
|
collector.Draw(spriteBatch, size, graphics.PreferredBackBufferHeight);
|
2019-05-14 14:12:04 +02:00
|
|
|
|
Display(displayer.info, displayer.barsPercent);
|
2019-04-22 03:16:30 +02:00
|
|
|
|
|
2019-04-21 02:43:36 +02:00
|
|
|
|
spriteBatch.End();
|
|
|
|
|
// TODO: Add your drawing code here
|
|
|
|
|
|
|
|
|
|
base.Draw(gameTime);
|
|
|
|
|
}
|
2019-04-23 11:24:01 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info"></param>
|
2019-05-14 14:12:04 +02:00
|
|
|
|
public void Display(Dictionary<string, string> info, Dictionary<string,int> barInfo)
|
2019-04-23 11:24:01 +02:00
|
|
|
|
{
|
2019-05-14 23:05:37 +02:00
|
|
|
|
int width = graphics.PreferredBackBufferHeight;
|
|
|
|
|
int x = width + width/50;
|
|
|
|
|
int y = width/50;
|
2019-04-23 11:24:01 +02:00
|
|
|
|
foreach (KeyValuePair<string, string> item in info)
|
|
|
|
|
{
|
2019-05-14 23:05:37 +02:00
|
|
|
|
if (barInfo.ContainsKey(item.Key))
|
2019-05-14 14:12:04 +02:00
|
|
|
|
{
|
|
|
|
|
var bar = barInfo[item.Key];
|
2019-05-14 23:05:37 +02:00
|
|
|
|
spriteBatch.Draw(ImageContainer.GetImage(item.Key + "Bar"), new Rectangle(x, y, bar * width / 500, width / 50), Color.White);
|
|
|
|
|
y += width / 50;
|
2019-05-14 14:12:04 +02:00
|
|
|
|
}
|
2019-05-14 23:05:37 +02:00
|
|
|
|
spriteBatch.DrawString(font, item.Key, new Vector2(x, y), Color.Black);
|
|
|
|
|
y += width*2/100;
|
|
|
|
|
spriteBatch.DrawString(font, item.Value, new Vector2(x, y), Color.White);
|
|
|
|
|
y += width*3/50;
|
|
|
|
|
|
2019-04-23 11:24:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-21 02:43:36 +02:00
|
|
|
|
}
|
|
|
|
|
}
|