public Pray(int iD, Vertex vA, Vertex vO, Graph g) { this.iD = iD; this.velocity = 5; this.index = 0; this.health = 100; this.position = vA.getPoint(); this.vO = vO; this.vA = vA; this.edge = null; this.existPath = true; this.vertexRoute = new List <Vertex>(); this.pLRoute = new List <Point>(); this.edgeRoute = new List <Edge>(); this.predator = null; this.g = g; this.random = new Random(); pen = new Pen(Brushes.Gold, 3); font = new Font(FontFamily.GenericSansSerif, 20); format = new StringFormat(StringFormatFlags.NoClip); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; vertexRoute = g.Dijkstra(vA, vO); if (vertexRoute.Count > 0) { getPointList(); } else { existPath = false; } }
public bool move() { predator = null; if (!isHunted()) { if ((vA != vO) && existPath) { if (pLRoute.Count < velocity) { pLRoute.Clear(); } else { pLRoute.RemoveRange(0, velocity); } if (index == 0) { vA.isOccupied(true); vA.updateTimer(); if (edgeRoute.Count != 0) { edge = edgeRoute.First(); edgeRoute.RemoveAt(0); } } vA.isOccupied(false); vA.updateTimer(); if ((index + velocity) < edge.getPoints().Count) { index = index + velocity; position = edge.getPointAt(index); } else { vA = edge.getDestination(); position = vA.getPoint(); index = 0; } } } else { if ((vA != vO) && existPath) { if (pLRoute.Count < velocity) { pLRoute.Clear(); } else { pLRoute.RemoveRange(0, velocity); } if (index == 0) { vA.isOccupied(true); vA.updateTimer(); Point pred = predator.getPoint(); if (pred != position) { if (edgeRoute.Count != 0) { edge = edgeRoute.First(); edgeRoute.RemoveAt(0); } } else { pLRoute.Clear(); edgeRoute.Clear(); Edge edg = predator.getEdge(); foreach (Edge ed in vA.getEdges()) { if (ed != edg) { edge = ed; pLRoute.AddRange(ed.getPoints()); } } } } vA.isOccupied(false); vA.updateTimer(); if (edge != null) { if ((index + velocity) < edge.getPoints().Count) { index = index + velocity; position = edge.getPointAt(index); } else { vA = edge.getDestination(); position = vA.getPoint(); index = 0; } } } } if (vA == vO) { gainsHealth(); return(true); } return(false); }
public void setPredator(Predator p) => predator = p;
// DEPREDADOR // public void addPredator(Predator p) => predators.Add(p);