Ejemplo n.º 1
0
 /// <summary>
 /// Runs the given hill's automation
 /// </summary>
 /// <param name="hill"> A hill </param>
 private static void runAutomation(Hill hill)
 {
     while (HillManager.isAutomationActivate())
     {
         hill.cycle();
         Thread.Sleep(HillManager.WAIT_TIME_IN_MILISECONDS);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a rabbit using the node's attributes and adds it to the hill
        /// </summary>
        /// <param name="hill"> A hill </param>
        /// <param name="node"> A node </param>
        private static void createRabbit(Hill hill, XmlNode node)
        {
            int    age   = XMLFileIO.readAge(node);
            string name  = XMLFileIO.readName(node);
            Sex    sex   = XMLFileIO.readSex(node);
            Color  color = XMLFileIO.readColor(node);

            addRabbit(hill, new Rabbit(age, sex, color, name));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates a hill from a file
        /// </summary>
        /// <param name="fileName"> Name of the XML file </param>
        /// <param name="hill"> An empty hill </param>
        private static void generateHill(string fileName, Hill hill)
        {
            XmlNodeList nodes = HillManager.fileNodes(fileName);

            foreach (XmlNode node in nodes)
            {
                if (HillManager.hasAttributes(node))
                {
                    HillManager.createRabbit(hill, node);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Automates the given hill
        /// </summary>
        /// <param name="hill"> A hill </param>
        private static void automateHill(Hill hill)
        {
            HillManager._toggle = true;

            Thread.Sleep(HillManager.WAIT_TIME_IN_MILISECONDS);

            while (true)
            {
                HillManager.runAutomation(hill);
                HillManager.checkToggle();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Runs the hill
        /// </summary>
        public static void runHill()
        {
            const string FILE_NAME      = "InitialState.xml";
            const int    NUM_OF_FEMALES = 3;
            const int    NUM_OF_MALES   = 2;

            Hill hill;

            if (XMLFileIO.doesFileExist(FILE_NAME))
            {
                hill = new Hill();
                generateHill(FILE_NAME, hill);
            }
            else
            {
                hill = new Hill(NUM_OF_MALES, NUM_OF_FEMALES);
            }

            automateHill(hill);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds a rabbit to the given hill
 /// </summary>
 /// <param name="hill"> A hill </param>
 /// <param name="rabbit"> A rabbit </param>
 private static void addRabbit(Hill hill, Rabbit rabbit)
 {
     hill.Rabbits.Add(rabbit);
 }