Ejemplo n.º 1
0
        //Compute min and max dim of the plant list
        public void ComputeDimInfos(PlantList plants)
        {
            var maxDim   = 0;
            var minDim   = 0;
            var dimCount = 0;

            foreach (var plant in plants)
            {
                var keys          = plant.Model.Select(x => x.Key);
                var dimCountLocal = plant.Model.Count;
                if (dimCountLocal > dimCount)
                {
                    dimCount = dimCountLocal;
                }
                var minDimLocal = keys.Min();
                if (minDimLocal < minDim)
                {
                    minDim = minDimLocal;
                }

                var maxDimLocal = keys.Max();
                if (maxDimLocal > maxDim)
                {
                    maxDim = maxDimLocal;
                }
            }
            DimCount = (uint)dimCount;
            MinDim   = minDim;
            MaxDim   = (uint)maxDim;
        }
Ejemplo n.º 2
0
 private void ChangeKeyLogic()
 {
     if (!string.IsNullOrEmpty(SelectedPlant.PlantID))
     {//check to see if key is part of the current companylist...
         Plant query = PlantList.Where(company => company.PlantID == SelectedPlant.PlantID &&
                                       company.AutoID != SelectedPlant.AutoID).FirstOrDefault();
         if (query != null)
         {//revert it back
             SelectedPlant.PlantID = SelectedPlantMirror.PlantID;
             //change to the newly selected company...
             SelectedPlant = query;
             return;
         }
         //it is not part of the existing list try to fetch it from the db...
         PlantList = GetPlantByID(SelectedPlant.PlantID, XERP.Client.ClientSessionSingleton.Instance.CompanyID);
         if (PlantList.Count == 0)//it was not found do new record required logic...
         {
             NotifyNewRecordNeeded("Record " + SelectedPlant.PlantID + " Does Not Exist.  Create A New Record?");
         }
         else
         {
             SelectedPlant = PlantList.FirstOrDefault();
         }
     }
     else
     {
         string errorMessage = "ID Is Required.";
         NotifyMessage(errorMessage);
         //revert back to the value it was before it was changed...
         if (SelectedPlant.PlantID != SelectedPlantMirror.PlantID)
         {
             SelectedPlant.PlantID = SelectedPlantMirror.PlantID;
         }
     }
 }
Ejemplo n.º 3
0
        protected override int GetAnswer(string input)
        {
            var initialRegex    = new Regex(@"initial state: ([\.#]+)");
            var generationRegex = new Regex(@"([\.#]{5}) => ([\.#])");
            var inputs          = input.Split(Environment.NewLine);

            var plantList = new PlantList
            {
                Plants = initialRegex.Match(inputs[0]).Groups[1].ToString()
            };

            var rules = inputs
                        .Skip(2)
                        .Select(i => generationRegex.Match(i))
                        .Select(m => new GenerationRule
            {
                Pattern = m.Groups[1].ToString(),
                Result  = m.Groups[2].ToString()
            })
                        .ToArray();

            for (long i = 0; i < 20; i++)
            {
                NextGeneration(plantList, rules);
            }

            return(ScorePlants(plantList));
        }
Ejemplo n.º 4
0
        //Plant Object Scope Validation check the entire object for validity...
        private byte PlantIsValid(Plant item, out string errorMessage)
        {   //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(item.PlantID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            EntityStates entityState = GetPlantState(item);

            if (entityState == EntityStates.Added && PlantExists(item.PlantID))
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = PlantList.Count(q => q.PlantID == item.PlantID);

            if (count > 1)
            {
                errorMessage = "Item All Ready Exists...";
                return(1);
            }
            //validate Description
            if (string.IsNullOrEmpty(item.Name))
            {
                errorMessage = "Name Is Required.";
                return(1);
            }
            //a value of 2 is pending changes...
            //On Commit we will give it a value of 0...
            return(2);
        }
Ejemplo n.º 5
0
        private void CreatePlantList()
        {
            ObservableCollection <PlantVariety> list = new ObservableCollection <PlantVariety>();
            List <PlantVariety> list1 = new List <PlantVariety>();

            list1 = context.PlantVariety.Local.ToList();
            if (checkBoxAll.IsChecked != true)
            {
                if (checkGenus.IsChecked == true)
                {
                    list1 = list1.Where(x => x.Genus == SelectedGenus).Select(x => x).ToList();
                }
                if (checkLifeForm.IsChecked == true)
                {
                    list1 = list1.Where(x => x.LifeForm == SelectedLifeForm).Select(x => x).ToList();
                }
            }

            if (textBoxSearch.Text != "")
            {
                list1 = list1.Where(x => x.FullName.ToLower().Contains(textBoxSearch.Text.ToLower()) == true).Select(x => x).ToList();
            }
            PlantList.Clear();
            foreach (var item in list1)
            {
                PlantList.Add(item);
            }
        }
Ejemplo n.º 6
0
        public void DeletePlantCommand()
        {
            try
            {
                int i  = 0;
                int ii = 0;
                for (int j = SelectedPlantList.Count - 1; j >= 0; j--)
                {
                    Plant item = (Plant)SelectedPlantList[j];
                    //get Max Index...
                    i = PlantList.IndexOf(item);
                    if (i > ii)
                    {
                        ii = i;
                    }
                    Delete(item);
                    PlantList.Remove(item);
                }

                if (PlantList != null && PlantList.Count > 0)
                {
                    //back off one index from the max index...
                    ii = ii - 1;

                    //if they delete the first row...
                    if (ii < 0)
                    {
                        ii = 0;
                    }

                    //make sure it does not exceed the list count...
                    if (ii >= PlantList.Count())
                    {
                        ii = PlantList.Count - 1;
                    }

                    SelectedPlant = PlantList[ii];
                    //we will only enable committ for dirty validated records...
                    if (Dirty == true)
                    {
                        AllowCommit = CommitIsAllowed();
                    }
                    else
                    {
                        AllowCommit = false;
                    }
                }
                else//only one record, deleting will result in no records...
                {
                    SetAsEmptySelection();
                }
            }//we try catch company delete as it may be used in another table as a key...
            //As well we will force a refresh to sqare up the UI after the botched delete...
            catch
            {
                NotifyMessage("Plant/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                Refresh();
            }
        }
Ejemplo n.º 7
0
 public Packing(PlantList plantList, Garden garden)
 {
     //First placement
     Garden        = garden;
     PlantList     = plantList;
     BasePlacement = new Placement(plantList, garden);
     PossiblePlacements.Insert(0, BasePlacement);
     FinalPlacement = ComputePacking(BasePlacement);
 }
Ejemplo n.º 8
0
        //Create base placement
        public Placement(PlantList plants, Garden garden)
        {
            //Plants
            Plants = plants;
            ComputeDimInfos(plants);

            garden.SetGardenMaps(MinDim, MaxDim);
            Garden = garden;
        }
Ejemplo n.º 9
0
 private void OnSearchResult(object sender, NotificationEventArgs <BindingList <Plant> > e)
 {
     if (e.Data != null && e.Data.Count > 0)
     {
         PlantList     = e.Data;
         SelectedPlant = PlantList.FirstOrDefault();
         Dirty         = false;
         AllowCommit   = false;
     }
     UnregisterToReceiveMessages <BindingList <Plant> >(MessageTokens.PlantSearchToken.ToString(), OnSearchResult);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Verander hoeveel zaadjes de gebruiker heeft over een bepaalde vrucht.
 /// </summary>
 /// <param name="plant">De plant.</param>
 /// <param name="amount">Hoeveelheid.</param>
 /// <seealso cref="PlantList"/>
 public void SetSeedInventoryAmount(PlantList plant, int amount)
 {
     if (plantSeedInventory.ContainsKey(plant))
     {
         plantSeedInventory[plant] = amount;
     }
     else
     {
         plantSeedInventory.Add(plant, amount);
     }
 }
Ejemplo n.º 11
0
 public Plant(PlantList type) : base()
 {
     initStatic();
     this.type = type;
     growthCur = 0;
     growthMax = 30;
     waterCons = 5;
     quality   = Plant.maxQuality;
     initGrowthSettings();
     determineGrowthStep();
     updateSprite();
 }
Ejemplo n.º 12
0
        private int ScorePlants(PlantList plantList)
        {
            var total = 0;

            for (var i = 0; i < plantList.Plants.Length; i++)
            {
                if (plantList.Plants[i] == '#')
                {
                    total += i - plantList.ZeroOffset;
                }
            }
            return(total);
        }
Ejemplo n.º 13
0
        public static void Test1()
        {
            //SoilMap
            var soilMap = new Mat(new Size(500, 500), DepthType.Cv8U, 1);

            soilMap.SetTo(new MCvScalar(0));
            for (int i = 1; i < 25; i++)
            {
                for (int j = 1; j < 25; j++)
                {
                    soilMap.SetValue(i, j, (byte)255);
                }
            }

            //Garden
            var garden = new Garden(soilMap);

            //Plants
            //p1
            var model1    = new List <KeyValuePair <int, Mat> >();
            var k         = 1;
            var plantMap1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(2 * k + 1, 2 * k + 1), new Point(k, k));

            model1.Add(new KeyValuePair <int, Mat>(0, plantMap1));
            model1.Add(new KeyValuePair <int, Mat>(-1, plantMap1));
            model1.Add(new KeyValuePair <int, Mat>(1, plantMap1));
            model1 = model1.OrderBy(o => o.Key).ToList();
            var plant1 = new Plant(1, model1);

            //p2
            var model2 = new List <KeyValuePair <int, Mat> >();

            k = 2;
            var plantMap2 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(2 * k + 1, 2 * k + 1), new Point(k, k));

            model2.Add(new KeyValuePair <int, Mat>(0, plantMap2));
            model2.Add(new KeyValuePair <int, Mat>(-1, plantMap2));
            model2.Add(new KeyValuePair <int, Mat>(1, plantMap2));
            model2 = model2.OrderBy(o => o.Key).ToList();

            var plant2 = new Plant(2, model2);

            var plantList = new PlantList()
            {
                plant1, plant2
            };

            //Packing
            var packing = new Packing(plantList, garden);
        }
Ejemplo n.º 14
0
    /**
     * Ajoute une plante a la case designed par tilePos sa localisation dans le repere de la scene
     *
     */
    public static bool ajoutPlante(PlantList type, Vector3 tilePos)
    {
        MapTile tile = Map.getTileAt(tilePos);

        if (tile != null)
        {
            if (tile.m_object == null)
            {
                Plant ajout = new Plant(type);
                tile.addObject(ajout);
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 15
0
        //Solo recibe objetos de la clase TerrainVehicle
        public void SavePlantPokemon(PlantPokemon plantPokemon)
        {
            var searchResult = PlantList.Where(p => p.Name == plantPokemon.Name).ToList();

            //if it didnt find any coincidence, then searchresult is null
            if (searchResult.Count() > 0)
            {
                throw new Exception("pokemon already stored");
            }
            else
            {
                //otherwise it stores the pokemon successfully
                PlantList.Add(plantPokemon);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Krijg de Plant object.
        /// </summary>
        /// <param name="plant">De plant waar het over gaat.</param>
        /// <returns><see cref="Plant"/></returns>
        public static Plant GetPlant(PlantList plant)
        {
            switch (plant)
            {
            case PlantList.Ananas:
                return(new Ananas(textures[PlantList.Ananas]));

            case PlantList.Mango:
                return(new Mango(textures[PlantList.Mango]));

            case PlantList.Markoesa:
                return(new Markoesa(textures[PlantList.Markoesa]));

            case PlantList.Papaya:
                return(new Papaya(textures[PlantList.Papaya]));

            case PlantList.Passievrucht:
                return(new Passievrucht(textures[PlantList.Passievrucht]));

            case PlantList.Avocado:
                return(new Avocado(textures[PlantList.Avocado]));

            case PlantList.Dragonfruit:
                return(new Dragonfruit(textures[PlantList.Dragonfruit]));

            case PlantList.Guave:
                return(new Guave(textures[PlantList.Guave]));

            case PlantList.Lychees:
                return(new Lychees(textures[PlantList.Lychees]));

            case PlantList.Granaatappel:
                return(new Granaatappel(textures[PlantList.Granaatappel]));

            default:
                return(null);
            }
        }
Ejemplo n.º 17
0
        //Object.Property Scope Validation...
        private bool PlantIsValid(Plant item, _plantValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _plantValidationProperties.PlantID:
                //validate key
                if (string.IsNullOrEmpty(item.PlantID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                EntityStates entityState = GetPlantState(item);
                if (entityState == EntityStates.Added && PlantExists(item.PlantID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = PlantList.Count(q => q.PlantID == item.PlantID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

            case _plantValidationProperties.Name:
                //validate Description
                if (string.IsNullOrEmpty(item.Name))
                {
                    errorMessage = "Description Is Required.";
                    return(false);
                }
                break;
            }
            return(true);
        }
Ejemplo n.º 18
0
        private void NextGeneration(PlantList plantList, GenerationRule[] rules)
        {
            plantList.PadLeftIfNecessary();
            plantList.PadRightIfNecessary();

            var nextGeneration = "..";

            for (var i = 2; i < plantList.Plants.Length - 2; i++)
            {
                var substring = plantList.Plants.Substring(i - 2, 5);

                foreach (var rule in rules)
                {
                    if (substring == rule.Pattern)
                    {
                        nextGeneration += rule.Result;
                        break;
                    }
                }
            }

            nextGeneration  += "..";
            plantList.Plants = nextGeneration;
        }
Ejemplo n.º 19
0
        private bool NewPlant(string itemID)
        {
            Plant newItem = new Plant();

            //all new records will be give a negative int autoid...
            //when they are updated then sql will generate one for them overiding this set value...
            //it will allow us to give uniqueness to the tempory new records...
            //Before they are updated to the entity and given an autoid...
            //we use a negative number and keep subtracting by 1 for each new item added...
            //This will allow it to alwasy be unique and never interfere with SQL's positive autoid...
            _newPlantAutoId         = _newPlantAutoId - 1;
            newItem.AutoID          = _newPlantAutoId;
            newItem.PlantID         = itemID;
            newItem.CompanyID       = ClientSessionSingleton.Instance.CompanyID;
            newItem.IsValid         = 1;
            newItem.NotValidMessage = "New Record Key Field/s Are Required.";
            PlantList.Add(newItem);
            _serviceAgent.AddToPlantRepository(newItem);
            SelectedPlant = PlantList.LastOrDefault();

            AllowEdit = true;
            Dirty     = false;
            return(true);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Constructor voor de Plant.
 /// </summary>
 /// <param name="plantList">De plant waar het over gaat.</param>
 /// <param name="name">De naam van de plant.</param>
 /// <param name="growTime">Hoe lang het duurt voordat de plant is volgroeid in secondes.</param>
 /// <seealso cref="PlantList"/>
 protected Plant(PlantList plantList, string name, int growTime)
 {
     this.PlantList = plantList;
     this.Name      = name;
     this.GrowTime  = growTime * 1000;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Hoeveel zaadjes heeft de gebruiker over een bepaalde plant.
 /// </summary>
 /// <param name="plant">De plant.</param>
 /// <seealso cref="PlantList"/>
 /// <returns>Een nummer hoeveel zaadjes de gebruiker heeft.</returns>
 public int GetSeedInventoryAmount(PlantList plant)
 {
     return(plantSeedInventory.ContainsKey(plant) ? plantSeedInventory[plant] : 0);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Het verwerken van muis events.
        /// </summary>
        /// <param name="main">Verwijzing naar Main class</param>
        /// <param name="gameTime">GameTime instance van MonoGame</param>
        /// <param name="mouseState">MouseState instance van MonoGame</param>
        /// <param name="prevMouseState">MouseState instance van vorige MouseState update</param>
        /// <seealso cref="Main"/>
        /// <seealso cref="GameTime"/>
        /// <seealso cref="MouseState"/>
        public void Update(Main main, GameTime gameTime, MouseState mouseState, MouseState prevMouseState)
        {
            if (!IsActive)
            {
                return;
            }

            // Sluit de winkel als er buiten de winkel wordt gedrukt.
            if (mouseState.LeftButton == ButtonState.Pressed &&
                prevMouseState.LeftButton == ButtonState.Released &&
                (!Collide(mouseState) || Collide(mouseState, 50 + graphicsDevice.Viewport.Width - 140, 50 + graphicsDevice.Viewport.Width - 100, 50, 50 + 40)) &&
                IsActive)
            {
                IsActive = false;
            }

            if (mouseState.LeftButton != ButtonState.Pressed || prevMouseState.LeftButton != ButtonState.Released || !IsActive)
            {
                return;
            }

            int menuWidth  = graphicsDevice.Viewport.Width - 100;
            int menuHeight = graphicsDevice.Viewport.Height - 100;
            int index      = 0;
            int maxIndex   = PlantFactory.Plants.Count;
            int cellWidth  = menuWidth / 4;
            int cellHeigth = menuHeight / 3;

            for (int row = 0; row < 3; row++)
            {
                for (int column = 0; column < 4; column++)
                {
                    // Sla de eerst en laatste vak over van de eerste rij.
                    if (row == 0 && (column < 1 || column > 2))
                    {
                        continue;
                    }

                    PlantList plant = PlantFactory.Plants[index];
                    String    text  = "Placeholder";

                    // Creëer een rechthoek voor de koop en verkoop knop.
                    Rectangle buyRectangle = new Rectangle(50 + 5 + cellWidth * column, 50 + (int)cellHeigth - 30 + cellHeigth * row, (int)cellWidth / 2 - 18,
                                                           (int)(spriteFont.MeasureString(text).Y) + 4);
                    Rectangle sellRectangle = new Rectangle(45 + (int)cellWidth / 2 + cellWidth * column, 50 + (int)cellHeigth - 30 + cellHeigth * row, (int)cellWidth / 2 + 3,
                                                            (int)(spriteFont.MeasureString(text).Y) + 4);

                    // De muis drukt op de koop knop.
                    if (buyRectangle.Intersects(new Rectangle(mouseState.X, mouseState.Y, 1, 1)))
                    {
                        // De gebruiker heeft genoeg geld en de plant wordt gekocht.
                        if (Money >= PlantFactory.GetCostPrice(plant))
                        {
                            SetSeedInventoryAmount(plant, GetSeedInventoryAmount(plant) + 1);
                            Money -= PlantFactory.GetCostPrice(plant);
                        }
                        else // De gebruiker heeft niet genoeg geld en zal een alert worden getoont.
                        {
                            main.ShowAlert(Constants.DangerColor, Strings.ErrorNotEnoughMoney, Strings.ErrorNotEnoughMoneyBody.Replace("%%PLANT", plant.ToString()));
                        }
                    }
                    else if (sellRectangle.Intersects(new Rectangle(mouseState.X, mouseState.Y, 1, 1))) // De muis drukt op de verkoop knop.
                    {
                        // De gebruiker heeft genoeg vruchten van de plant.
                        if (GetInventoryAmount(plant) >= 1)
                        {
                            SetInventoryAmount(plant, GetInventoryAmount(plant) - 1);
                            Money += PlantFactory.GetSellPrice(plant);
                        }
                        else // De gebruiker heeft niet genoeg vruchten en zal een alert worden getoont.
                        {
                            main.ShowAlert(Constants.DangerColor, Strings.ErrorNotEnoughInventory, Strings.ErrorNotEnoughInventoryBody.Replace("%%PLANT", plant.ToString()));
                        }
                    }

                    index++;
                    if (index >= maxIndex)
                    {
                        break;
                    }
                }

                if (index >= maxIndex)
                {
                    break;
                }
            }
        }
Ejemplo n.º 23
0
 public Erosion(PlantList plantList, Placement placement)
 {
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructor voor MenuItem. Deze constructor wordt alleen gebruikt wanneer de dirt veld leeg is.
 /// </summary>
 /// <param name="plant">De plant over waar deze optie gaat.</param>
 /// <param name="dirt">De dirt object waar het is aangekoppeld.</param>
 protected MenuItem(PlantList plant, Dirt dirt)
 {
     this.plant  = plant;
     this.dirt   = dirt;
     this.action = false;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Hoeveel kost het om een zaadje te kopen.
 /// </summary>
 /// <param name="plant">De plant</param>
 /// <seealso cref="PlantList"/>
 /// <returns>Prijs</returns>
 public static int GetCostPrice(PlantList plant)
 {
     return(costPrice.ContainsKey(plant) ? costPrice[plant] : -1);
 }
Ejemplo n.º 26
0
        private void plantList_Click(object sender, EventArgs e)
        {
            PlantList plantList = new PlantList();

            plantList.Show();
        }
Ejemplo n.º 27
0
 public void ClearLogic()
 {
     PlantList.Clear();
     SetAsEmptySelection();
 }
Ejemplo n.º 28
0
    private void Start()
    {
        GameObject GameManager = GameObject.Find("GameManager");

        plantlist = GameManager.GetComponent <PlantList>();
    }
Ejemplo n.º 29
0
 /// <summary>
 /// Hoeveel kan er worden verdiend als een vrucht wordt verkocht.
 /// </summary>
 /// <param name="plant">De plant</param>
 /// <seealso cref="PlantList"/>
 /// <returns>Prijs</returns>
 public static int GetSellPrice(PlantList plant)
 {
     return(sellPrice.ContainsKey(plant) ? sellPrice[plant] : -1);
 }