1
0
forked from s425077/PotatoPlan
JoelForkTest/Game1/Sources/Pathing/A-Star/PathSaver/Nodes.cs

124 lines
2.2 KiB
C#
Raw Normal View History

2020-05-03 13:05:05 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
2020-05-09 15:54:53 +02:00
using C5;
2020-05-03 13:05:05 +02:00
2020-05-09 15:54:53 +02:00
class Nodes : IComparable<Nodes>, IEqualityComparer<Nodes>, IPriorityQueueHandle<Nodes>
2020-05-03 13:05:05 +02:00
{
2020-05-03 16:35:46 +02:00
private int F = 0;
private int G = 0;
private int H = 0;
private Vector2 Coordinates;
private Nodes Parent = null;
2020-05-03 23:40:40 +02:00
private int Direction = 0;
2020-05-03 13:05:05 +02:00
2020-05-03 16:35:46 +02:00
public Nodes(Vector2 coordinates)
2020-05-03 13:05:05 +02:00
{
2020-05-03 16:35:46 +02:00
Coordinates = coordinates;
2020-05-03 13:05:05 +02:00
}
2020-05-03 23:40:40 +02:00
public Nodes(Vector2 coordinates, int direction)
{
Coordinates = coordinates;
Direction = direction;
}
2020-05-09 15:54:53 +02:00
public Nodes(int f, Vector2 coordinates)
{
Coordinates = coordinates;
F = f;
}
public Nodes(Nodes node)
2020-05-03 13:05:05 +02:00
{
2020-05-03 16:35:46 +02:00
F = node.F;
G = node.G;
H = node.H;
Coordinates = node.Coordinates;
Parent = node.Parent;
2020-05-03 13:05:05 +02:00
}
2020-05-03 16:35:46 +02:00
public Nodes(int f, int g, int h, Vector2 coordinates, Nodes parent)
2020-05-03 13:05:05 +02:00
{
2020-05-03 16:35:46 +02:00
F = f;
G = g;
H = h;
Coordinates = coordinates;
Parent = parent;
}
public Vector2 getCords()
{
return Coordinates;
}
public int getF()
{
return F;
}
public int getG()
{
return G;
}
public int getH()
{
return H;
}
public void calculateF()
{
F = G + H;
}
public void setG(int g)
{
G = g;
}
public void setH(int h)
{
H = h;
}
public Nodes getParent()
{
return Parent;
}
public void setParent(Nodes parent)
{
Parent = parent;
2020-05-03 13:05:05 +02:00
}
2020-05-03 23:40:40 +02:00
public int getDirection()
{
return Direction;
}
2020-05-09 15:54:53 +02:00
public int CompareTo(Nodes other)
{
if (this.F < other.F)
return -1;
else if (this.F > other.F)
return 1;
else
return 0;
}
public bool Equals(Nodes source, Nodes other)
{
return (source.Coordinates.X == other.Coordinates.X && source.Coordinates.Y == other.Coordinates.Y);
}
public int GetHashCode(Nodes nodes)
{
return (nodes.Coordinates.GetHashCode());
}
}