Exemple #1
0
        protected Ant(int health, int hunger, int id, int colonyID, int age, String location, AntType type)
        {
            HealthProperty       = health;
            HungerProperty       = hunger;
            IDProperty           = id;
            ColonyIDProperty     = colonyID;
            AgeProperty          = age;
            LocationProperty     = location;
            CarryingProperty     = Carrying.Nothing;
            StateProperty        = State.Standby;
            PheromoneProperty    = PheromoneEnum.ToNest;
            InNestProperty       = true;
            TypeProperty         = type;
            BeingCarriedProperty = false;
            MyAnthillProperty    = AntFarmForm.antHills[this.ColonyIDProperty];


            if (TypeProperty == AntType.Egg || TypeProperty == AntType.Queen)
            {
                MyAnthillProperty.AntsTotalProperty += 1;
            }
        }
Exemple #2
0
        //passed the enviroment root
        private void LoadScenario(string saveFilePath)
        {
            //take root folder as selected by user
            //init ant hill
            //store anthill stats.
            //store pointer in dictionary
            //init ant
            //store stats
            //store pointer in dictionary
            if (new FileInfo(saveFilePath).Length != 0)
            {

                using (StreamReader sr = new StreamReader(saveFilePath))
                {
                    string line = "";
                    int counter = 0;

                    //A temp value for parsing ints
                    int temp;
                    bool tempBool;

                    //temp objects
                    AntHill tempAnthill;
                    Chamber tempChamber = new Chamber();
                    Pheromone tempPhe = new Pheromone(0, "", PheromoneEnum.Danger, true);

                    Worker tempWorker = new Worker(0, 0, "", true);
                    Queen tempQueen = new Queen(0, 0, "", true);
                    Egg tempEgg = new Egg(0, 0, "", true);
                    Larvae tempLarvae = new Larvae(0, 0, "", true);
                    Pupae tempPupae = new Pupae(0, 0, "", true);
                    Ant antPointer = tempWorker;

                    while ((line = sr.ReadLine()) != "[Enviroment Stats End]")
                    {
                        counter++;

                        if (counter == 1)
                        {
                            this.enviromentFullPath = line;
                        }
                    }

                    tempAnthill = new AntHill(0, "", false);
                    counter = 0;
                    while ((line = sr.ReadLine()) != "[Anthill Stats End]")
                    {

                        counter++;

                        /*
                         1   sw.WriteLine(antHills[0].LocationProperty);
                         2   sw.WriteLine(antHills[0].IDProperty);
                         3   sw.WriteLine(antHills[0].AntsDiggingProperty);
                         4   sw.WriteLine(antHills[0].AntsMoveingEggsProperty);
                         5   sw.WriteLine(antHills[0].AntsScoutingProperty);
                         6   sw.WriteLine(antHills[0].AntsTendingToBroodProperty);
                         7   sw.WriteLine(antHills[0].AntsTendingToQueenProperty);
                         8   sw.WriteLine(antHills[0].AntsTotalProperty);
                         */

                        if (counter == 1)
                        {
                            tempAnthill.LocationProperty = line;

                        }
                        else if (counter == 2)
                        {

                            int.TryParse(line, out temp);
                            tempAnthill.IDProperty = temp;

                        }
                        else if (counter == 3)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsDiggingProperty = temp;

                        }
                        else if (counter == 4)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsMoveingEggsProperty = temp;

                        }
                        else if (counter == 5)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsScoutingProperty = temp;

                        }
                        else if (counter == 6)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsTendingToBroodProperty = temp;

                        }
                        else if (counter == 7)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsTendingToQueenProperty = temp;
                            antHills[0] = tempAnthill;
                            txtOutput.Text += Environment.NewLine + "Anthill" + tempAnthill.IDProperty + " Loaded";

                        }

                    }

                    counter = 0;
                    txtOutput.Text += Environment.NewLine + "Chambers Start: ";
                    //For the rest of the categories, I will have to set up a couple of loops.
                    //One for the category as a whole, and one for each record in that category.
                    while ((line = sr.ReadLine()) != "[Anthill Chamber Stats End]")
                    {
                        if (line == "[Anthill Chamber End]")
                        {
                            tempChamber = new Chamber();
                            counter = 0;
                        }
                        else
                        {
                            counter++;
                        }

                        /*
                        1 sw.WriteLine(antHills[0].chambers[i].IDProperty);
                        2 sw.WriteLine(antHills[0].chambers[i].TypeProperty);
                        3 sw.WriteLine(antHills[0].chambers[i].LocationProperty);
                        4 sw.WriteLine(antHills[0].chambers[i].AmountOfFoodProperty);
                        5 sw.WriteLine(antHills[0].chambers[i].AmountOfOffspringProperty);
                        6 sw.WriteLine(antHills[0].chambers[i].CapacityReachedProperty);
                        */

                        if (counter == 1)
                        {
                            int.TryParse(line, out temp);
                            tempChamber.IDProperty = temp;

                        }
                        else if (counter == 2)
                        {
                            tempChamber.TypeProperty = (ChamberType)Enum.Parse(typeof(ChamberType), line);

                        }
                        else if (counter == 3)
                        {
                            tempChamber.LocationProperty = line;

                        }
                        else if (counter == 4)
                        {
                            int.TryParse(line, out temp);
                            tempChamber.AmountOfFoodProperty = temp;

                        }
                        else if (counter == 5)
                        {
                            int.TryParse(line, out temp);
                            tempChamber.AmountOfOffspringProperty = temp;

                        }
                        else if (counter == 6)
                        {
                            bool.TryParse(line, out tempBool);
                            tempChamber.CapacityReachedProperty = tempBool;
                            txtOutput.Text += Environment.NewLine + "Anthill Chamber" + tempChamber.IDProperty + " Loaded";

                        }

                        //Add to list

                    }

                    while ((line = sr.ReadLine()) != "[Pheremone Stats End]")
                    {
                        if (line == "[Anthill Chamber End]")
                        {
                            tempPhe = new Pheromone(0, "", PheromoneEnum.Danger, true);
                            counter = 0;
                        }
                        else
                        {
                            counter++;
                        }

                        /*
                        1 sw.WriteLine(antHills[0].pheromonesPlaced[i].ColonyIDProperty);
                        2 sw.WriteLine(antHills[0].pheromonesPlaced[i].FullPathProperty);
                        3 sw.WriteLine(antHills[0].pheromonesPlaced[i].LocationProperty);
                        4 sw.WriteLine(antHills[0].pheromonesPlaced[i].StrengthProperty);
                        5 sw.WriteLine(antHills[0].pheromonesPlaced[i].TypeProperty);
                         */

                        if (counter == 1)
                        {
                            int.TryParse(line, out temp);
                            tempPhe.ColonyIDProperty = temp;
                        }
                        else if (counter == 2)
                        {
                            tempPhe.FullPathProperty = line;
                        }
                        else if (counter == 3)
                        {
                            tempPhe.LocationProperty = line;
                        }
                        else if (counter == 4)
                        {
                            int.TryParse(line, out temp);
                            tempPhe.StrengthProperty = temp;
                        }
                        else if (counter == 5)
                        {
                            tempPhe.TypeProperty = (PheromoneEnum)Enum.Parse(typeof(PheromoneEnum), line);
                            txtOutput.Text += Environment.NewLine + "Pheremone" + tempPhe.TypeProperty.ToString() + " Loaded";
                        }

                    }

                    while ((line = sr.ReadLine()) != "[Ant Stats End]")
                    {

                        if (line == "[Ant End]")
                        {
                            counter = 0;
                        }
                        else
                        {
                            counter++;
                        }

                        /*
                        1 sw.WriteLine(antHills[0].ants[i].TypeProperty);
                        2 sw.WriteLine(antHills[0].ants[i].IDProperty);
                        3 sw.WriteLine(antHills[0].ants[i].FullPathProperty);
                        4 sw.WriteLine(antHills[0].ants[i].LocationProperty);
                        5 sw.WriteLine(antHills[0].ants[i].HungerProperty);
                        6 sw.WriteLine(antHills[0].ants[i].HealthProperty);
                        7 sw.WriteLine(antHills[0].ants[i].AgeProperty);
                        8 sw.WriteLine(antHills[0].ants[i].BeingCarriedProperty);
                        9 sw.WriteLine(antHills[0].ants[i].CarriedAntProperty.IDProperty);
                        10 sw.WriteLine(antHills[0].ants[i].CarriedObjectFullPathProperty);
                        11 sw.WriteLine(antHills[0].ants[i].CarriedObjectLocationProperty);
                        12 sw.WriteLine(antHills[0].ants[i].CarryAmountProperty);
                        13 sw.WriteLine(antHills[0].ants[i].CarryingProperty);
                        14 sw.WriteLine(antHills[0].ants[i].ColonyIDProperty);
                        15 sw.WriteLine(antHills[0].ants[i].DestinationProperty);
                        16 sw.WriteLine(antHills[0].ants[i].InNestProperty);
                        17 sw.WriteLine(antHills[0].ants[i].NewThroneRoomProperty);
                        18 sw.WriteLine(antHills[0].ants[i].PheromoneProperty);
                        19 sw.WriteLine(antHills[0].ants[i].PreviousLocationProperty);
                        20 sw.WriteLine(antHills[0].ants[i].StateProperty);
                        21 sw.WriteLine(antHills[0].ants[i].StepCountProperty);

                        */

                        if (counter == 1)
                        {
                            if (line == "Queen")
                            {
                                tempQueen = new Queen(0, 0, "", true);
                                antPointer = tempQueen;
                            }
                            else if (line == "Egg")
                            {
                                tempEgg = new Egg(0, 0, "", true);
                                antPointer = tempEgg;
                            }
                            else if (line == "Larvae")
                            {
                                tempLarvae = new Larvae(0, 0, "", true);
                                antPointer = tempLarvae;
                            }
                            else if (line == "Pupae")
                            {
                                tempPupae = new Pupae(0, 0, "", true);
                                antPointer = tempPupae;
                            }
                            else if (line == "Worker")
                            {
                                tempWorker = new Worker(0, 0, "", true);
                                antPointer = tempWorker;
                            }

                        }
                        else if (counter == 2)
                        {
                            int.TryParse(line, out temp);
                            antPointer.IDProperty = temp;
                        }
                        else if (counter == 3)
                        {
                            antPointer.FullPathProperty = line;
                        }
                        else if (counter == 4)
                        {
                            antPointer.LocationProperty = line;
                        }
                        else if (counter == 5)
                        {
                            int.TryParse(line, out temp);
                            antPointer.HungerProperty = temp;
                        }
                        else if (counter == 6)
                        {
                            int.TryParse(line, out temp);
                            antPointer.HealthProperty = temp;
                        }
                        else if (counter == 7)
                        {
                            int.TryParse(line, out temp);
                            antPointer.AgeProperty = temp;
                        }
                        else if (counter == 8)
                        {
                            bool.TryParse(line, out tempBool);
                            antPointer.BeingCarriedProperty = tempBool;
                        }
                        else if (counter == 9)
                        {
                            //This is an object, so i will have to perhaps store the id of the ant instead, then get that ant.
                            //Or ignore this all together, but thats not good.
                            //I might have to change this property to store the ID anyway, then have the ant look for the
                            //cooresponding ant by ID.
                            //antPointer.CarriedAntProperty

                            //what i can do is use the ant dictionary and just point to the ID regardless of if it's a null value.
                            //that ant will get placed in the dictionary anyway at the end of the load.
                            if (line == "nullValue")
                            {
                                antPointer.CarriedAntProperty = null;
                            }
                            else
                            {
                                int.TryParse(line, out temp);
                                antPointer.CarriedAntProperty = antHills[0].ants[temp];
                            }

                        }
                        else if (counter == 10)
                        {
                            //10 sw.WriteLine(antHills[0].ants[i].CarriedObjectFullPathProperty);
                            if (line != "nullValue")
                            {
                                antPointer.CarriedObjectFullPathProperty = line;
                            }
                        }
                        else if (counter == 11)
                        {
                            //11 sw.WriteLine(antHills[0].ants[i].CarriedObjectLocationProperty);
                            if (line != "nullValue")
                            {
                                antPointer.CarriedObjectLocationProperty = line;
                            }
                        }
                        else if (counter == 12)
                        {
                            //12 sw.WriteLine(antHills[0].ants[i].CarryAmountProperty);
                            int.TryParse(line, out temp);
                            antPointer.CarryAmountProperty = temp;

                        }
                        else if (counter == 13)
                        {
                            //13 sw.WriteLine(antHills[0].ants[i].CarryingProperty);

                            antPointer.CarryingProperty = (Carrying)Enum.Parse(typeof(Carrying), line);

                        }
                        else if (counter == 14)
                        {
                            //14 sw.WriteLine(antHills[0].ants[i].ColonyIDProperty);
                            int.TryParse(line, out temp);
                            antPointer.ColonyIDProperty = temp;

                        }
                        else if (counter == 15)
                        {
                            //15 sw.WriteLine(antHills[0].ants[i].DestinationProperty);
                            antPointer.DestinationProperty = line;

                        }
                        else if (counter == 16)
                        {
                            //16 sw.WriteLine(antHills[0].ants[i].InNestProperty);
                            bool.TryParse(line, out tempBool);
                            antPointer.InNestProperty = tempBool;

                        }
                        else if (counter == 17)
                        {
                            // 17 sw.WriteLine(antHills[0].ants[i].NewThroneRoomProperty);
                            bool.TryParse(line, out tempBool);
                            antPointer.NewThroneRoomProperty = tempBool;

                        }
                        else if (counter == 18)
                        {
                            //18 sw.WriteLine(antHills[0].ants[i].PheromoneProperty);

                            antPointer.PheromoneProperty = (PheromoneEnum)Enum.Parse(typeof(PheromoneEnum), line);

                        }
                        else if (counter == 19)
                        {
                            //19 sw.WriteLine(antHills[0].ants[i].PreviousLocationProperty);
                            antPointer.PreviousLocationProperty = line;

                        }
                        else if (counter == 20)
                        {
                            //20 sw.WriteLine(antHills[0].ants[i].StateProperty);
                            antPointer.StateProperty = (State)Enum.Parse(typeof(State), line);

                        }
                        else if (counter == 21)
                        {
                            //21 sw.WriteLine(antHills[0].ants[i].StepCountProperty);
                            int.TryParse(line, out temp);
                            antPointer.StepCountProperty = temp;

                            antPointer.MyAnthillProperty = antHills[0];
                            antHills[0].ants[antPointer.IDProperty] = antPointer;

                            txtOutput.Text += Environment.NewLine + "Ant" + antPointer.ColonyIDProperty.ToString("D2") + "_" + antPointer.IDProperty.ToString("D4") + " Loaded";
                        }

                        //add ant to dictionary.
                        //set anthill pointer to anthill[0]
                        //

                    }

                    txtOutput.Text += Environment.NewLine + "LOAD COMPLETE";
                    sr.Close();
                }

            }
        }
Exemple #3
0
        private void AntFarmForm_Load(object sender, EventArgs e)
        {
            AntHill dummy = new AntHill(0, "", false);
            antHills.Add(0, dummy);
            txtOutput.Text += "Welcome to AntFarm!";
            cbxSpeed.SelectedIndex = 4;
            runTimer.Stop();

            //initial state
            setState(FormState.Initial);
        }
Exemple #4
0
        private string createAntHill(string path)
        {
            string dest;
            string returnString;
            AntHill newAntHill;
            bool antHillCreated = false;
            string errorString = "";
            returnString = "Failed";

            //split the path to ensure that the anthill is being placed in the enviroment
            //For now, i dont want to allow placment in any folder.
            string[] pathSplit = path.Split(Path.DirectorySeparatorChar);
            string[] enviroSplit = enviromentFullPath.Split(Path.DirectorySeparatorChar);

            if (pathSplit.Contains(enviroSplit.Last()))
            {
                if (pathSplit.Last() == enviroSplit.Last())
                {
                    path += @"\Entrance";
                }
            }
            else
            {
                return returnString + ": Not in Enviroment";
            }

            if (antHills.Count < MAX_ANTHILLS)
            {
                for (int i = 0; i < MAX_ANTHILLS; i++)
                {
                    try
                    {

                        dest = path + @"\Anthill_" + i.ToString("D2");
                        newAntHill = new AntHill(i, dest, true);

                        //Reenable if i ever want more then one anthill
                        /*if (antHills.ContainsKey(i) && antHills[i] == null)
                        {
                            antHills[i] = newAntHill;
                        }
                        else
                        {
                            antHills.Add(i, newAntHill);
                        }*/

                        //single hill code
                        antHills[0] = newAntHill;

                        Directory.CreateDirectory(dest);
                        newAntHill.StartHill(true);
                        returnString = "AntHill_" + i.ToString("D2") + " was created at " + dest;
                        cbxAntHill.Items.Add(i.ToString("D2"));
                        btnBrowseAnthill.Enabled = false;
                        antFarmCreated = true;

                        /*
                         * Update the folder selector
                         *
                         */

                        //entitySelector.Items[0].BackColor

                        if (i == 0)
                        {
                            cbxAntHill.SelectedIndex = 0;
                        }
                        antHillCreated = true;
                        i = MAX_ANTHILLS;

                        if (!runTimerRunning)
                        {
                            runTimer = new System.Windows.Forms.Timer();
                            runTimer.Interval = timerInterval;
                            runTimer.Tick -= new EventHandler(runTimerTick);
                            runTimer.Tick += new EventHandler(runTimerTick);
                            runTimer.Start();
                            runTimerRunning = true;
                            statusLabel.Text = "Running";
                            statusLabel.BackColor = Color.Green;

                            setState(FormState.Running);
                        }

                    }
                    catch (ArgumentException e)
                    {
                        newAntHill = null;
                        returnString = "Looking for free slot";
                        antHillCreated = false;
                        errorString = e.Message;

                    }
                }

                if (!antHillCreated)
                {
                    returnString = "Anthill creation failed: " + errorString;
                }

            }
            else
            {
                returnString = "Max AntHills reached. Delete an AntHill or wait for one to die.";
            }

            return returnString;
        }