Example #1
0
 public SquareGridUnit(UnitID id, SquareGridSquare square = null)
 {
     this.id         = id;
     this.square     = square;
     this.move_range = 1;
     this.jump_range = 1;
 }
Example #2
0
    public SquareGridSquare(int row, int col, float height = 0)
    {
        this.Row    = row;
        this.Col    = col;
        this.Height = SquareGridSquare.RoundHeight(height);
        this.units  = new List <SquareGridUnit>();

        this.Vertex    = new GraphableMixin <SquareGridSquare>(this);
        this.TmpVertex = new GraphableMixin <SquareGridSquare>(this);
    }
Example #3
0
    public bool MoveUnit(SquareGridUnit unit, SquareGridSquare s)
    {
        if (s == null)
        {
            return(false);
        }

        s.AddUnit(unit);
        unit.Moved(s);
        return(true);
    }
Example #4
0
    public bool MoveUnit(SquareGridUnit piece, int row, int col)
    {
        SquareGridSquare s = this.GetSquare(row, col);

        if (s == null)
        {
            return(false);
        }

        return(this.MoveUnit(piece, s));
    }
Example #5
0
    public SquareGridArea(HashSet <SquareGridSquare> squares,
                          SquareGridSquare root_square)
    {
        this.Squares    = squares;
        this.RootVertex = root_square.TmpVertex;

        /* need to append root because it might not be in squares */
        var all = new List <GraphableMixin <SquareGridSquare> >(
            from s in squares select s.TmpVertex);

        this.Vertices = all;
    }
    public override void Moved(SquareGridSquare s)
    {
        Vector3           new_pos;
        USquareGridSquare us = (USquareGridSquare)s;

        this.square = us;

        /* need to put the piece on the top of the background (TODO: gravity?) */
        new_pos   = us.WorldCenterCoords;
        new_pos.y = new_pos.y + this.half_height;
        this.g.transform.position = new_pos;

        /* not sure how expensive setactive is */
        this.g.SetActive(true);
    }
Example #7
0
    public IEnumerable <SquareGridSquare> GetAdjacentRadius(SquareGridSquare square, int radius)
    {
        int row;
        int col;

        this.mark_sequence_number += 1;

        if (radius == 0)
        {
            yield break;
        }

        /**
         * starting at x,y with radius 3
         * x - 3, y + [0, 0]
         * x - 2, y + [-1, 1]
         * x - 1, y + [-2, 2]
         * x, y + [-3, 3]
         * x + 1, [-2, 2]
         */
        for (row = square.Row - radius; row <= square.Row + radius; row++)
        {
            int dist = row - square.Row;
            if (dist < 0)
            {
                dist = radius + dist;
            }
            else
            {
                dist = radius - dist;
            }
            for (col = square.Col - dist; col <= square.Col + dist; col++)
            {
                SquareGridSquare adj;

                adj = this.GetSquare(row, col);
                if ((adj != null) && (adj != square))
                {
                    yield return(adj);
                }
            }
        }

        yield break;
    }
Example #8
0
 protected bool CanMoveAdjacent(SquareGridSquare curr, SquareGridSquare adj)
 {
     return(this.jump_range >= System.Math.Abs(adj.Height - curr.Height));
 }
Example #9
0
 public virtual void Moved(SquareGridSquare target)
 {
     this.square = target;
 }
Example #10
0
 public IEnumerable <SquareGridSquare> GetPath(SquareGridSquare dst)
 {
     return(from v in this.RootVertex.GetPathTo(this.Vertices, dst.TmpVertex)
            select v.Parent);
 }
Example #11
0
 public override bool MoveUnit(SquareGridUnit unit, SquareGridSquare s)
 {
     return(this.grid.MoveUnit(unit, s));
 }
 public SquareGridSelector(SquareGridGame game)
 {
     this.game        = game;
     this.curr_piece  = null;
     this.curr_square = null;
 }
Example #13
0
 public bool CanMoveTo(SquareGridUnit unit, SquareGridSquare square)
 {
     return(true);
 }
Example #14
0
 public virtual bool MoveUnit(SquareGridUnit piece, SquareGridSquare s)
 {
     return(this.grid.MoveUnit(piece, s));
 }