示例#1
0
        public Vector3 Hex2Board(CubeCoordinate hex)
        {
            Vector3 position;

            position.y = spacing.y * (hex.z + 0.5f * hex.x);
            position.x = spacing.x * hex.x;
            position.z = 0;
            return(position);
        }
示例#2
0
 public static IEnumerable <CubeCoordinate> Fan(CubeCoordinate center, int radius)
 {
     for ( ; radius >= 0; --radius)
     {
         foreach (var position in Arc(center, radius))
         {
             yield return(position);
         }
     }
 }
示例#3
0
 ICell IBoard.this[CubeCoordinate coord] {
     get {
         if (cells.TryGetValue(coord, out var cell))
         {
             return(cell);
         }
         else
         {
             return(null);
         }
     }
 }
示例#4
0
        public void Destroy(CubeCoordinate coord)
        {
            if (cells.TryGetValue(coord, out var cell) == false)
            {
                return;
            }

            if (cell.block == null)
            {
                return;
            }

            Destroy(cell.block.gameObject);
            cell.block = null;
        }
示例#5
0
        void IBoard.Spawn(CubeCoordinate coord, int count)
        {
            Debug.Assert(count > 0);

            var spawner = cells[coord].GetComponent <Spawner>();

            Debug.Assert(spawner != null, $"Tried to spawn a block from non-spawner cell, {coord}");

            var offset = FlatTopDirection.N * count;
            var p      = coord;

            for (var i = 0; i < count; ++i)
            {
                var cell = cells[p];
                cell.block = SpawnBlock(spawner.Draw(), p + offset);
                anim.Drop(cell);
                p -= FlatTopDirection.N;
            }
        }
示例#6
0
        public static IEnumerable <CubeCoordinate> Ring(CubeCoordinate center, int radius)
        {
            if (radius <= 0f)
            {
                yield return(center);

                yield break;
            }

            var position = center + (around[4] * radius);

            foreach (var dir in around)
            {
                for (var i = 0; i < radius; ++i)
                {
                    yield return(position);

                    position += dir;
                }
            }
        }
示例#7
0
 void IBoard.Drop(CubeCoordinate from, CubeCoordinate to)
 {
     Swap(cells[from], cells[to]);
     Debug.Assert(cells[to].block != null, $"{from} -> {to}");
     anim.Drop(cells[to]);
 }
示例#8
0
 void IBoard.Swap(CubeCoordinate from, CubeCoordinate to)
 {
     Swap(cells[from], cells[to]);
 }
示例#9
0
 bool IBoard.HasCell(CubeCoordinate coord)
 {
     return(cells.ContainsKey(coord));
 }
示例#10
0
 public int Distance(CubeCoordinate subject)
 {
     return(Distance(this, subject));
 }
示例#11
0
 public Line(CubeCoordinate selected, CubeCoordinate direction)
 {
     this.selected  = selected;
     this.direction = direction;
 }
示例#12
0
        public Vector3 Hex2World(CubeCoordinate hex)
        {
            var local = Hex2Board(hex);

            return(transform.TransformPoint(local));
        }
示例#13
0
 private static bool Less(CubeCoordinate a, CubeCoordinate b)
 {
     return(a.r < b.r);
 }
示例#14
0
 public Burst(CubeCoordinate selected)
 {
     target = selected;
 }