//node index is the nodes place in the map, beginning with the top left and ending with the bottom right private void AddNodeData(GamePiece nodePiece, int nodeIndex) { Console.WriteLine("AddNodeData used"); // TEST CODE int starCounter = 0; int lineCounter = -1; string CurrentLine; string[] CurrentLineStrings; List<string[]> NodeDataList = new List<string[]>(); try{ StreamReader sr = new StreamReader(@CurrentNodeDataPath); CurrentLine = sr.ReadLine(); while (CurrentLine != null) { lineCounter += 1; //Console.WriteLine(CurrentLine); // TEST CODE if (CurrentLine.Contains("*")) starCounter += 1; if (starCounter == nodeIndex) { //read next line to determine node type. CurrentLine = sr.ReadLine(); CurrentLineStrings = CurrentLine.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); if (CurrentLineStrings[0] != nodePiece.Type) //check to see if mapfile and nodeData file agree on the nodeType. { Console.WriteLine("Error: Mapfile and Data file do not match. Mapfile data gives " + nodePiece.Type + " while NodeFile gives " + CurrentLineStrings[0]); } nodePiece.SecurityRating = Convert.ToInt32(CurrentLineStrings[1]); // set secRating to the second term in the string array, convert to int. CurrentLine = sr.ReadLine(); nodePiece.Header = CurrentLine; // read nextline and set header to whats read Console.WriteLine("{0} {1} {2}", nodePiece.Type, nodePiece.SecurityRating, nodePiece.Header); // prints to console to make sure everything is working fine. TEST CODE CurrentLine = sr.ReadLine(); // Following Code reads below title and header. while (!CurrentLine.Contains("*")) { //Console.WriteLine("no star: "); // TEST CODE //Console.WriteLine(CurrentLine); // TEST CODE CurrentLineStrings = CurrentLine.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); NodeDataList.Add(CurrentLineStrings); //populate a list for the current node. List contains all files, folders, and other data. Does not include Header, Sec Rating, Or Node Type. CurrentLine = sr.ReadLine(); } // go through the list and assign files and folders to their correct places, so long as the list has at least one entry. if (NodeDataList.Count > 0) { AssignFilesAndFolders(NodeDataList, nodePiece); Console.WriteLine("Number of Folders: "); Console.WriteLine(nodePiece.Folders.Count); } break; } CurrentLine = sr.ReadLine(); } } catch (Exception e) { Console.WriteLine("Exception: FAILED TO LOAD NODE DATA " + e.Message); } }
private void AssignFilesAndFolders(List<string[]> NodeDataList, GamePiece inputNode) { string FolderName; List<string> FolderFilesList = new List<string>(); string[] CurrentLineStrings; Console.WriteLine("AssignFilesAndFolders Accessed"); foreach (string[] line in NodeDataList) { if (line.Contains("Folder")) { Console.WriteLine("Line contains Folder"); FolderName = line[1]; for (int i = (NodeDataList.IndexOf(line)+1); i < NodeDataList.Count; i++) { Console.WriteLine("Folder File Loop Accsessed"); if (NodeDataList[i].Contains("File")) { CurrentLineStrings = NodeDataList[i]; FolderFilesList.Add(CurrentLineStrings[1]); Console.WriteLine(CurrentLineStrings[1]); } else { break; } } Folder newFolder = new Folder(FolderName, FolderFilesList); inputNode.Folders.Add(newFolder); } if (line.Contains("File")) { inputNode.Files.Add(line[1]); } } }
public void UpdateAdjacentStates(GamePiece[,] inputMap) { GamePiece.NodePiece OccupiedNode; //find the occupid node. Break once it's found; theres only one. for (int x = 0; x < NetworkMap.NetworkMapWidth; x++) { for (int y = 0; y < NetworkMap.NetworkMapHeight; y++) { if (inputMap[x, y].State == "Occupied") { OccupiedNode = (GamePiece.NodePiece)inputMap[x, y]; //FindAdjacentNodes(inputMap, OccupiedNode, x, y); // get other ends of occupied node and give adjacent nodes the "adjacent" state. } } } }