// show all non null entries in an item array static void ShowInventory(item[] inv) { foreach (item It in inv) { if (It != null) Text.WordWrap(string.Format("{0}",It)); // display } }
public cavern(item i) // single item construtor { inventory[99] = i; }
// loads map from file // Initalization of functions static void Load() { Text.Log("Path",@"\Save_template.txt",Debug); // print path foreach (string line in File.ReadLines(@"Save_template.txt")) // reads file at path { Text.Log("Line",line,Debug); if (line.Contains("//")) // finds comments and reads them in debug { // Debug.WriteLine(DateTime.Now + " | Comment | " + line); // debug comment reader } else if (line.Contains("Cavern:")) // finds all cavern defs from file { int pos = 0; // Pointers int exits = 0; // int route = 0; // int[] Pos = new int[3]; // Arrays string[] Exits = new string[6]; // int[,] Route = new int[6, 3]; // ... string Dis = ""; // String string @Pic = "404.txt"; string T = line.Substring(8); // looses the "Cavern:" part of the string int i = 0; for (int I = 1; I < T.Length; I++) // iterates through the line { if (T[I] == '<') // finds pos values apended with a < { string test = (T.Substring(i, (I - i))); Text.Log("Pos", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Pos[pos] = int.Parse(test); // pulls numerical value followed by a < i = I + 1; //Advances start pointer pos++; } else if (T[I] == ';') // finds Room discription values apended with a ; { string test = (T.Substring(i, (I - i))); if (test[0] == ' ') { test = test.Substring(1, test.Length - 1); } Text.Log("Discription", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Dis = test; // pulls string value followed by a ; i = I + 1; //Advances start pointer } else if (T[I] == ':') // finds Exit discription values apended with a : { string test = (T.Substring(i, (I - i))); if (test[0] == ' ') { test = test.Substring(1, test.Length - 1); } Text.Log("Exit", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Exits[exits] = test; // pulls string value followed by a : i = I + 1; //Advances start pointer exits++; } else if (T[I] == '>') // finds route sets apended with a > { int Start = 0; int pointer = 0; int[] Delta = new int[2]; string test = (T.Substring(i, (I - i))); Text.Log("Route", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug for (int End = 0; End < test.Length; End++) { if (test[End] == '|') // finds route values apended with a | { string testSub = (test.Substring(Start, ((End) - Start))); Text.Log("Route[]", testSub, Debug);//Debug Text.Log("Pointer", End + "," + Start, Debug); //Debug //Debug Route[route, pointer] = int.Parse(testSub); // pulls string value followed by a | Start = End + 1; //Advances start pointer pointer++; } } i = I + 1; //Advances start pointer route++; } else if (T[I] == '^') { string test = (T.Substring(i, (I - i))); if (test[0] == ' ') { test = test.Substring(1, test.Length - 1); } Text.Log("Exit", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug @Pic = test; // pulls string value followed by a : i = I + 1; //Advances start pointer } } Map1[Pos[0], Pos[1], Pos[2]] = new cavern(Pos, Dis, Exits, Route, @Pic); //make new room and store into an array } else if (line.Contains("Item:")) { int pos = 0; // pointer int[] Pos = new int[3]; string Dis = ""; // string string Name = ""; // int Amount = 1; // int bool Move = false; string T = line.Substring(5); // looses the "Item:" part of the string int i = 0; // start pointer for (int I = 1; I < T.Length; I++) // iterates through the line { if (T[I] == '<') // finds pos values apended with a < { string test = (T.Substring(i, (I - i))); Text.Log("Pos", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Pos[pos] = int.Parse(test); // pulls numerical value followed by a < i = I + 1; //Advances start pointer pos++; } else if (T[I] == ';') // finds Item name values apended with a ; { string test = (T.Substring(i, (I - i))); if (test[0] == ' ') { test = test.Substring(1, test.Length - 1); } Text.Log("Name", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Name = test; // pulls string value followed by a ; i = I + 1; //Advances start pointer } else if (T[I] == ':') // finds Item discription values apended with a : { string test = (T.Substring(i, (I - i))); if (test[0] == ' ') { test = test.Substring(1, test.Length - 1); } Text.Log("Discription", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Dis = test; // pulls string value followed by a : i = I + 1; //Advances start pointer } else if (T[I] == '~') // finds Item amount values apended with a ~ { string test = (T.Substring(i, (I - i))); Text.Log("Amount", test, Debug);//Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Amount = int.Parse(test); // pulls string value followed by a ~ i = I + 1; //Advances start pointer } if (T[I] == '|') // finds Movable values apended with a | { string test = (T.Substring(i, (I - i))); Text.Log("Movable",test,Debug); //Debug Text.Log("Pointer", I + "," + i, Debug); //Debug Move = bool.Parse(test); // pulls string value followed by a | i = I + 1; //Advances start pointer } } int max = Map1[Pos[0], Pos[1], Pos[2]].inventory.GetLength(0); // finds the max inventory size item[] inventory = Map1[Pos[0], Pos[1], Pos[2]].inventory; // sets inventory as a local variable for simplicity for (var I = 0; I < Amount; I++) // adds one itm to the frst null entry in the inventory { for (int index = 0; index < max; index++) // finds first null entry { if (inventory[index] == null) // null entry { inventory[index] = new item(Name, Dis, Move); break; } else if (inventory[index].equals()) // empty entry { inventory[index] = new item(Name, Dis, Move); break; } } } Map1[Pos[0], Pos[1], Pos[2]].inventory = inventory; // dump the resulting local inventory into the cavern inventory } // outside if-else for file read } }