CLIFFS: How do I create a list of mixed variables in C#?
My programming experience after computer science class in school adds up to about a week. Last year I thought it might be fun to learn some programming. With the help of google, youtube and stackoverflow.com I was able to make a word jumble game over the easter weekend in C# using Visual Studio. There is a lot that I did that I didn’t really understand. It just worked.
This is all picture boxes and labels.
When I got the basic functionality done I lost interested. Fast forward to about 2 weeks ago I wanted to try again. I thought of a turn-based game inspired by Heroes of Might & Magic - Chess Royale:
Now the problem I have run into:
Once there is more than one hero and one monster I needed some kind of pathfinding. Luckily others have solved this for me. I found good explanations of A* and Dijkstra. I opted for the latter because there might be more than one destination/targets (=the hero characters).
To implement this I need to store four variables for each node: two points (the node’s and the parent node’s x/y coordinates) and two integers (the G and H cost). I could create an array with mixed variables or convert the points to integers and back every time I need them.
Then add those arrays to the lists.
Now Microsoft says
This is the example code:
// Create a list of parts.
List<Part> parts = new List<Part>();
// Add parts to the list.
parts.Add(new Part() {PartName="crank arm", PartId=1234});
parts.Add(new Part() { PartName = "chain ring", PartId = 1334 });
parts.Add(new Part() { PartName = "regular seat", PartId = 1434 });
How do I adapt this for my purposes?
Something like…?
// Create a list of nodes.
List<Node> nodes = new List<Node>();
// Add nodes to the list.
parts.Add(new Part() {nodeCoordinates=(0,0), parent=(1,1), g=0, h=0});
(Sorry for the long post)