using CzokoŚmieciarka.AI_Naive;
using CzokoŚmieciarka.DataModels.Interfaces;
using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector;
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.DataModels.Models;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGameView;
using System;
using System.Collections.Generic;
using System.Linq;
namespace CzokoŚmieciarka.MonoGameView
{
///
/// This is the main type for your game.
///
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D road1;
Texture2D road2;
Texture2D grass;
Vector2 roadPos;
float timer;
const float TIMER = 0.2f;
int stepN;
List steps;
GarbageCollector collector;
object[,] grid = new object[10, 10];
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
}
///
/// 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.
///
protected override void Initialize()
{
// TODO: Add your initialization logic here
roadPos = new Vector2(0, 0);
timer = 0.2f;
for (int x=0;x<10;x++)
{
for (int y=0;y<10;y++)
{
if (x % 2 == 0 || y % 2 == 0) grid[x, y] = new Road1();
else grid[x, y] = null;
}
}
collector = new GarbageCollector(Content,new Coords(0, 0), new List(), 10, 10);
stepN = 0;
var dfs = new DFS();
steps = dfs.BestPath(collector, grid);
base.Initialize();
}
///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
road1 = Content.Load("road1");
road2 = Content.Load("road2");
grass = Content.Load("grass");
// TODO: use this.Content to load your game content here
}
///
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
///
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///
/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
timer -= elapsed;
if (timer<0)
{
timer = TIMER;
if (steps.Any())
{
steps.First().Invoke(collector, grid);
steps.RemoveAt(0);
}
}
// TODO: Add your update logic here
base.Update(gameTime);
}
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
if (grid[x, y] is Road1) spriteBatch.Draw(road1, new Vector2(x*50,y*50), Color.White);
else if (grid[x,y] is Road2) spriteBatch.Draw(road2, new Vector2(x * 50, y * 50), Color.White);
else spriteBatch.Draw(grass, new Vector2(x * 50, y * 50), Color.White);
}
}
collector.Draw(spriteBatch);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}