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

public class MapGrid {
    public IEnumerable<Tile> Tiles { get { return tiles.Cast<Tile>(); } }

    private Tile[,] tiles;

    public MapGrid(Tile[,] tiles) {
        this.tiles = tiles;
    }

    public Tile GetTile(Vector2 position) {
        int x = Mathf.RoundToInt(position.x);
        int y = Mathf.RoundToInt(position.y);
        if (x >= tiles.GetLength(0) || x < 0 || y >= tiles.GetLength(1) || y < 0) {
            return null;
        }

        return tiles[x, y];
    }

    public void ForceDeactivated(ForceType force) {
        foreach (Tile tile in tiles) {
            tile.ForceDeactivated(force);
        }
    }

    public void ForceActivated(ForceType force) {
        foreach (Tile tile in tiles) {
            tile.ForceActivated(force);
        }
    }

    public Vector3 CameraPosition { get { return new Vector3((float)tiles.GetLength(0) / 2f, 0, (float)tiles.GetLength(1) / 2f); } }
    public float CameraDistance { get { return Mathf.Max(tiles.GetLength(0), tiles.GetLength(1)) * 1.5f; } }
}
