Exemplo n.º 1
0
        public bool Switch(string choice, List <Snake> snakeList, List <LandTerrarium> lanTerList, List <WaterTerrarium> waTerList, string snakeFilename, string terFilename, string waterFilename) //MISSING waTer
        {
            SnakeMenu       snakeMenu       = new SnakeMenu();
            WaTerrariumMenu waTerrariumMenu = new WaTerrariumMenu();
            LaTerrariumMenu laTerrariumMenu = new LaTerrariumMenu();

            try
            {
                if (choice == "snake" || choice == "3")
                {
                    snakeMenu.DisplaySnakeMenu();
                    string ui = Console.ReadLine();
                    theXml.WriteToXmlFile(snakeMenu.SnakeSwitch(ui, snakeList, waTerList, lanTerList, snakeFilename), snakeFilename);
                    return(true);
                }
                else if (choice == "land" || choice == "2") //LAND
                {
                    laTerrariumMenu.LaTerrariumMenuDisplay();
                    string ui = Console.ReadLine();
                    theXml.LandTerWriteToXmlFile(laTerrariumMenu.LaTerrariumSwitch(ui, snakeList, snakeFilename, lanTerList, terFilename), terFilename);
                    return(true);
                }
                else if (choice == "water" || choice == "1") //WATER
                {
                    waTerrariumMenu.WaTerrariumMenuDisplay();
                    string ui = Console.ReadLine();
                    theXml.WaterTerWriteToXmlFile(waTerrariumMenu.WaTerrariumSwitch(ui, snakeList, snakeFilename, waTerList, waterFilename), waterFilename);
                    return(true);
                }

                else if (choice == "exit" || choice == "4")
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(true);
        }
Exemplo n.º 2
0
        public List <LandTerrarium> LaTerrariumSwitch(string choice, List <Snake> snakeList, string snakeFilename, List <LandTerrarium> lanTerList, string lanTerfilename)
        {
            SnakeMenu snakeMenu = new SnakeMenu();
            XML       theXml    = new XML();

            //maybe a WHILE here?
            while (true)
            {
                try
                {
                    if (choice == "create" || choice == "1")
                    {
                        AddTerToList(CreateLaTerrarium(lanTerList), lanTerList);
                        theXml.LandTerWriteToXmlFile(lanTerList, lanTerfilename);
                        Console.WriteLine("Land terrarium successfully created.");
                        break;
                    }
                    else if (choice == "destroy" || choice == "2")
                    {
                        while (true)
                        {
                            Console.WriteLine("ID: ");
                            string id  = Console.ReadLine();
                            string msg = $"Terrarium with: {id} has been deleted.";
                            if (DestroyTerrarium(lanTerList, id) == msg)
                            {
                                Console.WriteLine(msg);
                                break;
                            }
                            Console.WriteLine("Invalid id!");
                        }
                        theXml.LandTerWriteToXmlFile(lanTerList, lanTerfilename);
                        break;
                    }

                    else if (choice == "display" || choice == "3")
                    {
                        DisplayTerrarium(lanTerList);
                        break;
                    }
                    else if (choice == "add" || choice == "4")
                    {
                        AddSnakeToTer(snakeList, lanTerList, snakeMenu);
                        Console.WriteLine("Done");
                        theXml.LandTerWriteToXmlFile(lanTerList, lanTerfilename);
                        theXml.WriteToXmlFile(snakeList, snakeFilename);
                        break;
                    }

                    else if (choice == "back" || choice == "5")
                    {
                        break;
                    }
                    else if (choice == "exit" || choice == "6")
                    {
                        System.Environment.Exit(1);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(lanTerList);
        }
Exemplo n.º 3
0
        public void AddSnakeToTer(List <Snake> snakeList, List <LandTerrarium> laTerList, SnakeMenu snakeMenu)
        {
            Console.WriteLine("Please choose the terrarium you would like to add the snake to:");
            string sName;

            DisplayTerrarium(laTerList);
            Console.WriteLine("ID: ");
            string terId = Console.ReadLine();

            Console.WriteLine("Please choose the snake you would like to add:");
            snakeMenu.DisplayAllSnakes(snakeList);
            while (true)
            {
                Console.WriteLine("Name: ");
                string snakeName = Console.ReadLine();
                if (TypeChecker(snakeName, snakeList) == true)
                {
                    sName = snakeName;
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid Input!");
                }
            }


            foreach (var ter in laTerList)
            {
                if (ter.ID == terId)
                {
                    foreach (var snake in snakeList)
                    {
                        if (snake.Name == sName)
                        {
                            ter.AddSnake(snake);
                            snakeList.Remove(snake);
                            Console.WriteLine($"Snake: {snake.Name} has been removed from the SnakeList.");
                            Console.WriteLine($"Snake: {snake.Name} has been added to the terrarium with ID: {ter.ID}.");
                            break;
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 4
0
        public void AddSnakeToTer(List <Snake> snakeList, List <WaterTerrarium> waTerList, SnakeMenu snakeMenu)
        {
            Console.WriteLine("Please choose the terrarium you would like to add the snake to:");
            DisplayTerrarium(waTerList);
            Console.WriteLine("ID: ");
            string terId = Console.ReadLine();

            Console.WriteLine("Please choose the snake you would like to add:");
            snakeMenu.DisplayAllSnakes(snakeList);
            while (true)
            {
                Console.WriteLine("Name: ");
                string snakeName = Console.ReadLine();
                foreach (var ter in waTerList)
                {
                    if (ter.ID == terId)
                    {
                        foreach (var snake in snakeList)
                        {
                            if (snake.Name == snakeName)
                            {
                                try
                                {
                                    ter.AddSnake(snake);
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }

                                snakeList.Remove(snake);
                                Console.WriteLine($"Snake: {snake.Name} has been removed from the SnakeList.");
                                Console.WriteLine($"Snake: {snake.Name} has been added to the terrarium with ID: {ter.ID}.");
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            XML       theXml    = new XML();
            Utility   util      = new Utility();
            SnakeMenu snakeMenu = new SnakeMenu();

            List <Snake>          snakeList  = new List <Snake>();
            List <WaterTerrarium> waTerList  = new List <WaterTerrarium>();
            List <LandTerrarium>  lanTerList = new List <LandTerrarium>();
            LandTerrarium         laTer;
            WaterTerrarium        waTer;

            string terFilename   = "LandTerrarium.xml";
            string waterFilename = "WaterTerrarium.xml";
            string snakeFilename = "JustSnakes.xml";


            if (!File.Exists("LandTerrarium.xml") || theXml.IsEmpty(terFilename))
            {
                laTer = new LandTerrarium(util.IdGenerator(), snakeList);
                lanTerList.Add(laTer);
                theXml.LandTerWriteToXmlFile(lanTerList, terFilename);
            }

            if (!File.Exists("JustSnakes.xml") || theXml.IsEmpty(snakeFilename))
            {
                Console.WriteLine("Please create a Snake first!"); //snake already exists

                snakeMenu.CreateSnake(snakeList);
            }

            if (!File.Exists("WaterTerrarium.xml") || theXml.IsEmpty(waterFilename))
            {
                waTer = new WaterTerrarium(util.IdGenerator(), snakeList);
                waTerList.Add(waTer);
                theXml.WaterTerWriteToXmlFile(waTerList, waterFilename);
            }

            snakeList  = theXml.LoadObjectFromXmlFile(snakeFilename);
            waTerList  = theXml.WaterTerLoadObjectFromXmlFile(waterFilename);
            lanTerList = theXml.LandTerLoadObjectFromXmlFile(terFilename);


            theXml.WriteToXmlFile(snakeList, snakeFilename);

            Menu mainMenu = new Menu();

            do
            {
                mainMenu.DisplayMainMenu();
                string choice = mainMenu.InputHandler("Type option with lowercase: ");
                if (mainMenu.Switch(choice, snakeList, lanTerList, waTerList, snakeFilename, terFilename, waterFilename))
                {
                    theXml.WaterTerWriteToXmlFile(waTerList, waterFilename);
                    theXml.LandTerWriteToXmlFile(lanTerList, terFilename);
                    theXml.WriteToXmlFile(snakeList, snakeFilename);
                }
                else
                {
                    break;
                }
            } while (true);
        }