using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System;

[Serializable]
public class Map {

	[Serializable]
	public class Tile {
		public int X;
		public int Y;
		public bool IsObstacle;
	}

	public struct Vector2Int
	{
		public Vector2Int(Vector2 xy)
		{
			X = (int) xy.x;
			Y = (int) xy.y;
		}

		public Vector2Int(int x, int y)
		{
			X = x;
			Y = y;
		}

		public int X { get; private set; }
		public int Y { get; private set; } 
	}

	public MapTile[,] Tiles;

	public int borderSize;
	public int startPointX;
	public int startPointY;
	public int endPointX;
	public int endPointY;
	public int wifiSpawnPointX;
	public int wifiSpawnPointY;
	public int wifiPlacePointX;
	public int wifiPlacePointY;

	public Tile[] mapGrid;

	public MapTile[,] MapGrid { 
		set 
		{
			mapGrid = new Tile[value.Length];

			int index = 0;
			for (int i = 0; i < value.GetLength (0); i++) {
				for (int j = 0; j < value.GetLength (1); j++) {
					mapGrid [index] = new Tile ();
					mapGrid [index].X = value [i, j].Coordinates.X;
					mapGrid [index].Y = value [i, j].Coordinates.Y;
					mapGrid [index].IsObstacle = value [i, j].IsObstacle;
					index++;
				}
			}
		} 
	}

	public Vector2Int StartPoint {
		get { return new Vector2Int (startPointX, startPointY); } 
		set { startPointX = value.X; startPointY = value.Y; }
	}
	public Vector2Int EndPoint {
		get { return new Vector2Int (endPointX, endPointY); } 
		set { endPointX = value.X; endPointY = value.Y; }
	}

	public Vector2Int WifiSpawnPoint {
		get { return new Vector2Int (wifiSpawnPointX, wifiSpawnPointY); }
		set { wifiSpawnPointX = value.X; wifiSpawnPointY = value.Y; }
	}

	public Vector2Int WifiPlacePoint {
		get { return new Vector2Int (wifiPlacePointX, wifiPlacePointY); }
		set { wifiPlacePointX = value.X; wifiPlacePointY = value.Y; }
	}
}
