Exemple #1
0
        // current room loader
        // Yet more
        static int[] loadRoom(int x, int y, int z)
        {
            debugCheck(x, y, z); // debugs room

            cavern current = new cavern(); // default config
            if (Map1[x, y, z] != null) // is it null?
                current = Map1[x, y, z]; // no then...

            Console.Clear(); // clears console

            Text.Art(current.pic, Console.WindowWidth); // draw pic
            Console.SetCursorPosition(0, Console.CursorTop + 1);

            // Console.SetCursorPosition(0, 10); // sets cursor position
            Text.WordWrap(current.discribe); // writes discription
            Text.WordWrap(" "); // blank line

            for(byte i = 0; i < current.exits.Length; i++) // i = 0 to 5
            Text.WordWrap(current.exits[i]); // writes exits

            input: // label for input statement
            Text.WordWrap(@"What direction do You go (N,S,E,W,U,D), or do you want to check your inventory and the cave's inventory (I)?");
            string choice = string.Format(Console.ReadLine()).ToUpper(); // to upper case
            try // find and return next room
            {
                int c = "NSEWUDI".IndexOf(choice[0]);
                if (c != 6)
                {
                    int[] @return = new int[3] { current.paths[c, 0], current.paths[c, 1], current.paths[c, 2] };
                    Text.Log("Room Index", "Going to: ",Debug);
                    for (int i = 0; i < @return.Length; i++)
                        Text.Log("Room []", @return[i].ToString(), Debug);
                    return @return; // returns next room
                }
                else // inventory
                {
                    Text.WordWrap("");
                    Text.WordWrap("Items found in the cavern.");
                    ShowInventory(current.inventory); // the cavern's inventory

                    Text.WordWrap("");
                    Text.WordWrap("Items found in your inventory.");
                    ShowInventory(Player.inventory); // your inventory

                    Text.WordWrap("");
                    Text.WordWrap("From your inventory...");
                    SelectItem(Player, Map1[x,y,z], current); // items from you to the cave

                    Text.WordWrap("");
                    Text.WordWrap("From the cave...");
                    SelectItem(Map1[x, y, z], Player, current); // items from cave to you
                    goto input; // back to room select
                }
            }
            catch // errror catch
            {
                Text.WordWrap("Error Input, please only use North, South, East, West, Up, and Down as directions or use Inventory. ");
                Text.Log("Input", "Error Invalid: " + choice,Debug);
                goto input;
            }
        }
Exemple #2
0
 static void SelectItem(cavern @in, cavern  @out, cavern current)
 {
     InputSI: // first input retry
     Text.WordWrap("Do you wish to select an item (Y/N)?");
     try
     {
         string Input = Console.ReadLine().ToUpper(); //line to caps
         if (Input[0] == 'Y') // yes
         {
         InputSIT: // second retry input
             int a = -1; // variable for invintory entry
             Text.WordWrap("Item name?");
             string InputT = Console.ReadLine().ToUpper(); // name querry; case sensitive
             try
             {
                 for(var i = 0; i <= @in.inventory.Length; i++) // go through the inventory
                 {
                     item A = @in.inventory[i]; // item to A for easy refference
                     if (A != null) // isn null?
                         if (A.name.ToUpper() == InputT)
                         {
                             a = i; // record index
                             break;
                         }
                 }
                 if ([email protected][a].movable) // movable?
                     Text.WordWrap("This item cannot be moved.");
                 else
                 {
                     InputSETT: // third input retry
                     Text.WordWrap("Transfer item (Y/N)?");
                     string input = Console.ReadLine().ToUpper(); // transfer from @in to @out
                     try
                     {
                         if (input[0] == 'Y') // yes...
                         {
                             for (int i = 0; i < @out.inventory.Length; i++) //find first null entry in inventory
                                 if (@out.inventory[i] == null)
                                 {
                                     @out.inventory[i] = @in.inventory[a]; // copy item
                                     @in.inventory[a] = null; // delete previous item
                                     Text.Log("Item","Moved "[email protected][i].name,Debug); // log moved item
                                     break;
                                 }
                             goto InputSI;
                         }
                         else if (input[0] == 'N') // no...
                         {
                             Text.WordWrap(""); // blank line?
                         }
                     }
                     catch
                     {
                         Text.WordWrap("Invalid input."); // third retry goto...
                         goto InputSETT;
                     }
                 }
             }
             catch
             {
                 Text.WordWrap("Invalid input."); // second retry goto...
                 goto InputSIT;
             }
         }
         else if (Input[0] == 'N')
         {
             Text.WordWrap("Closing this inventory"); // exit...
         }
         else
         {
             Text.WordWrap("Invalid input."); // first retry goto if random reply
             goto InputSI;
         }
     }
     catch
     {
         Text.WordWrap("Invalid input."); // first retry goto if breaks
         goto InputSI;
     }
 }
Exemple #3
0
        // 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
            }
        }