public SquareGridUnit(UnitID id, SquareGridSquare square = null) { this.id = id; this.square = square; this.move_range = 1; this.jump_range = 1; }
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); }
public bool MoveUnit(SquareGridUnit unit, SquareGridSquare s) { if (s == null) { return(false); } s.AddUnit(unit); unit.Moved(s); return(true); }
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)); }
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); }
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; }
protected bool CanMoveAdjacent(SquareGridSquare curr, SquareGridSquare adj) { return(this.jump_range >= System.Math.Abs(adj.Height - curr.Height)); }
public virtual void Moved(SquareGridSquare target) { this.square = target; }
public IEnumerable <SquareGridSquare> GetPath(SquareGridSquare dst) { return(from v in this.RootVertex.GetPathTo(this.Vertices, dst.TmpVertex) select v.Parent); }
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; }
public bool CanMoveTo(SquareGridUnit unit, SquareGridSquare square) { return(true); }
public virtual bool MoveUnit(SquareGridUnit piece, SquareGridSquare s) { return(this.grid.MoveUnit(piece, s)); }