Exemplo n.º 1
0
 private void RemoveDead()
 {
     Ants.RemoveAll(x => x.Hp <= 0);
     Pests.RemoveAll(x => x.Hp <= 0);
     Foods.RemoveAll(x => x.Hp <= 0);
     OpenFoods.RemoveAll(x => x.Hp <= 0);
 }
Exemplo n.º 2
0
        public void SolveFirstPuzzle()
        {
            var sut = new Foods(PuzzleData.PUZZLE_DATA);

            sut.CalculateIngredientsWithoutAllergens();
            Assert.Equal(2061, sut.ApparitionsOfIngredientsWithoutAllergensInFood);
        }
Exemplo n.º 3
0
        public void SolveSecondPuzzle()
        {
            var sut = new Foods(PuzzleData.PUZZLE_DATA);

            sut.CalculateIngredientsWithoutAllergens();
            Assert.Equal("cdqvp,dglm,zhqjs,rbpg,xvtrfz,tgmzqjz,mfqgx,rffqhl", sut.CanonicalDangerousIngredientList);
        }
Exemplo n.º 4
0
        private static Foods ParseFood(string[] foodTokens)
        {
            string foodType = foodTokens[0];
            int    quantity = int.Parse(foodTokens[1]);
            Foods  food     = null;

            switch (foodType)
            {
            case "Meat":
                food = new Meat(quantity);
                break;

            case "Vegetable":
                food = new Vegetable(quantity);
                break;

            case "Fruit":
                food = new Fruit(quantity);
                break;

            case "Seeds":
                food = new Seeds(quantity);
                break;

            default:
                throw new ArgumentException("Invalid type of food!");
            }

            return(food);
        }
Exemplo n.º 5
0
 public UserProfile UpdateFoods(List <long> foodIds)
 {
     if (!foodIds.IsNullOrZero())
     {
         if (Foods.IsNullOrZero())
         {
             Foods = new List <UserFood>();
         }
         Foods.RemoveAll(p => !foodIds.Contains(p.Id));
         var _foods = Foods;
         foodIds.ForEach(item =>
         {
             try
             {
                 var result = _foods.Where(p => p.Id == item).FirstOrDefault();
                 if (result.IsNull())
                 {
                     Foods.Add(new UserFood().Create(item, Id));
                 }
             }
             catch (Exception e)
             {
                 throw e;
             }
         });
     }
     else
     {
         Foods.Clear();
     }
     return(this);
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("FoodsId")] Foods foods)
        {
            if (id != foods.FoodsId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(foods);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FoodsExists(foods.FoodsId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(foods));
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            List <Animal> animals = new List <Animal>();
            string        input;

            while ((input = Console.ReadLine()) != "End")
            {
                Animal animal = ParseAnimal(input);
                animals.Add(animal);
                string[] foodTokens = Console.ReadLine().Split();
                Foods    food       = ParseFood(foodTokens);

                Console.WriteLine(animal.MakeSound());

                try
                {
                    animal.TryEatFood(food);
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            foreach (Animal animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 8
0
        public void Run()
        {
            string commad = Console.ReadLine();

            while (commad != "End")
            {
                string[] animalArgs = commad.Split();

                Animal animal = AnimalFactory.Create(animalArgs);

                string[] foodArgs = Console.ReadLine().Split();

                Foods food = FoodFactory.Create(foodArgs);

                Console.WriteLine(animal.SoundEat());

                try
                {
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animals.Add(animal);

                commad = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
Exemplo n.º 9
0
        public async Task PutAsync(HttpListenerContext context)
        {
            var data = await context.ReadPostDataAsync();

            if (data == null)
            {
                return;
            }

            var title       = data.GetOrDefault("title");
            var ingredients = data.GetOrDefault("ingredients");

            if (string.IsNullOrEmpty(title))
            {
                throw new HttpException(400, "Food is invalid");
            }

            if (!context.CheckCsrfToken(data.GetOrDefault("csrf-token")))
            {
                throw new HttpException(403, "Request is forged");
            }

            var food = await Foods.Add(title, ingredients);

            await context.WriteStringAsync(food.Id.ToString("N"));

            await callback(context.Request.Cookies.GetAuth() ?? "FoodBot", food).ConfigureAwait(false);
        }
Exemplo n.º 10
0
        public void AddFood()
        {
            var batata = new Foods("Batata", "tuberculo amarelo", 2934720, 23, 1, 10000000, 6, 123124, "", false, Guid.Parse("00000000-0000-0000-0000-000000000000"), Guid.Parse("fb56fd90-822b-4be9-09b6-08d822831157"));
            var res    = _bo.Create(batata);

            Assert.IsTrue(res.Success);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> PutFoods(long id, Foods foods)
        {
            if (id != foods.Id)
            {
                return(BadRequest());
            }

            _context.Entry(foods).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FoodsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 12
0
        private void chkNull(Foods p)
        {
            long    chk  = 0;
            Decimal chk1 = 0;

            p.date_modi   = p.date_modi == null ? "" : p.date_modi;
            p.date_cancel = p.date_cancel == null ? "" : p.date_cancel;
            p.user_create = p.user_create == null ? "" : p.user_create;
            p.user_modi   = p.user_modi == null ? "" : p.user_modi;
            p.user_cancel = p.user_cancel == null ? "" : p.user_cancel;

            p.foods_name       = p.foods_name == null ? "" : p.foods_name;
            p.foods_code       = p.foods_code == null ? "" : p.foods_code;
            p.res_code         = p.res_code == null ? "" : p.res_code;
            p.status_foods     = p.status_foods == null ? "0" : p.status_foods;
            p.printer_name     = p.printer_name == null ? "" : p.printer_name;
            p.status_to_go     = p.status_to_go == null ? "0" : p.status_to_go;
            p.status_dine_in   = p.status_dine_in == null ? "0" : p.status_dine_in;
            p.filename         = p.filename == null ? "" : p.filename;
            p.status_recommend = p.status_recommend == null ? "0" : p.status_recommend;
            p.status_create    = p.status_create == null ? "0" : p.status_create;
            p.foods_name_1     = p.foods_name_1 == null ? "" : p.foods_name_1;

            p.host_id       = long.TryParse(p.host_id, out chk) ? chk.ToString() : "0";
            p.branch_id     = long.TryParse(p.branch_id, out chk) ? chk.ToString() : "0";
            p.device_id     = long.TryParse(p.device_id, out chk) ? chk.ToString() : "0";
            p.foods_type_id = long.TryParse(p.foods_type_id, out chk) ? chk.ToString() : "0";
            p.res_id        = long.TryParse(p.res_id, out chk) ? chk.ToString() : "0";
            p.foods_cat_id  = long.TryParse(p.foods_cat_id, out chk) ? chk.ToString() : "0";

            p.foods_price     = Decimal.TryParse(p.foods_price, out chk1) ? chk1.ToString() : "0";
            p.price_plus_togo = Decimal.TryParse(p.price_plus_togo, out chk1) ? chk1.ToString() : "0";
        }
Exemplo n.º 13
0
        private void initConfig()
        {
            fEdit  = new Font(mposC.iniC.grdViewFontName, mposC.grdViewFontSize + 5, FontStyle.Regular);
            fEditB = new Font(mposC.iniC.grdViewFontName, mposC.grdViewFontSize, FontStyle.Bold);
            fEdit1 = new Font(mposC.iniC.grdViewFontName, mposC.grdViewFontSize + 5, FontStyle.Regular + 2);
            fgrd   = new Font(mposC.iniC.grdViewFontName, mposC.grdViewFontSize + 15, FontStyle.Regular);
            ford   = new Font(mposC.iniC.grdViewFontName, mposC.grdViewFontSize, FontStyle.Regular);

            picPlus.Click  += PicPlus_Click;
            picMinus.Click += PicMinus_Click;
            picDesc.Click  += PicDesc_Click;
            picDel.Click   += PicDel_Click;

            flagExplan = false;
            sizeNormal = this.Size;
            foo        = new Foods();
            foos       = new FoodsSpecial();

            hei1      = pnCri1.Height;
            hei2      = pnCri2.Height;
            hei3      = pnCri3.Height;
            hei4      = pnCri4.Height;
            heiselect = pnSelect.Height;

            setControl();
            PicDesc_Click(null, null);
        }
Exemplo n.º 14
0
        public ActionResult Create(Foods food)
        {
            _context.Foods.Add(food);
            _context.SaveChanges();

            return(CreatedAtRoute("GetFood", new { id = food.Food_id }, food));
        }
Exemplo n.º 15
0
        private void Tile_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            Tile tile = sender as Tile;

            if (tile != null)
            {
                Foods foo = new Foods();
                foo = (Foods)tile.Tag;
                setGrf(tile.Name, tile.Text, tile.Text1.Replace("ราคา", "").Trim(), "1", "", foo.printer_name);
                //FlickrPhoto photo = (FlickrPhoto)tile.Tag;
                //string uri = photo.ContentUri;
                //if (!string.IsNullOrEmpty(uri))
                //{
                //    pictureBox.Image = pictureBox.InitialImage;
                //    pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
                //    imgPanel.Visible = true;
                //    imgPanel.BringToFront();
                //    titleLabel.Text = photo.Title;
                //    authorLabel.Text = photo.AuthorName;
                //    waitLabel.Visible = true;
                //    pictureBox.LoadAsync(uri);
                //    tagBox.Enabled = false;
                //    setTagButton.Enabled = false;
                //    refreshButton.Enabled = false;
                //    loadNewButton.Enabled = false;
                //    flickrTiles.Enabled = false;
                //    backButton.Enabled = true;
                //    this.Focus();
                //}
            }
        }
Exemplo n.º 16
0
        public static void Task1()
        {
            Console.WriteLine("AOC2020_Day21_1");

            Foods foods = new Foods();

            foods.Read();
            var alergenes = foods.FindAlergenes();

            var found = new SortedSet <string>();

            foreach (var i in alergenes)
            {
                found.Add(i.Item2);
                Console.WriteLine("{0} - {1}", i.Item1, i.Item2);
            }
            ;

            int tot = 0; int t2 = 0;

            foreach (var food in foods.foods)
            {
                t2 += food.ingredients.Count;
                foreach (var ingr in  food.ingredients)
                {
                    if (!found.Contains(ingr))
                    {
                        tot++;
                    }
                }
            }

            Console.WriteLine("OK Ingrs = {0}", tot);
        }
Exemplo n.º 17
0
        public async Task DeleteFood(int id)
        {
            Foods foods = _context.Foods.Find(id);

            _context.Remove(foods);
            await _context.SaveChangesAsync();
        }
    private List <Food> decodeFood(string data)
    {
        data = $"{{\"FoodList\":{data}}}";
        Foods decodedData = JsonUtility.FromJson <Foods>(data);

        return(decodedData.FoodList.ToList());
    }
Exemplo n.º 19
0
 public override void Eat(Foods food)
 {
     this.BaseEat(food, new List <string>()
     {
         nameof(Meat)
     }, WeightIncrease);
 }
Exemplo n.º 20
0
Arquivo: FrmAdd.cs Projeto: fu-kim/-
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //校验信息完整性
            if (CheckInput())
            {
                Foods F = new Foods()
                {
                    FoodName  = txtFoodName.Text,
                    FoodPrice = Convert.ToDecimal(cboFoodPrice.Text),
                    FoodType  = (cboFoodType.SelectedIndex + 1).ToString(),
                    FoodTime  = TimeSpan.Parse("00:" + nudtxtFoodTime.Text + ":00"),
                };
                int    n = FoodManager.InsertFood(F);
                string pLocalFilePath = file;//要复制的文件路径

                string path  = Application.StartupPath;
                int    index = path.IndexOf("KaMiFoodSystem");
                path = path.Substring(0, index) + "KaMiFoodSystem";

                string pSaveFilePath  = Application.StartupPath + @"\Images\食物\" + txtFoodName.Text + ".jpg";          //指定存储的路径
                string pSaveFilePath2 = path + @"\KaMiFood\KaMiFood\bin\Debug\Images\食物\" + txtFoodName.Text + ".jpg"; //指定存储的路径
                File.Copy(pLocalFilePath, pSaveFilePath, true);
                File.Copy(pLocalFilePath, pSaveFilePath2, true);
                if (n > 0)
                {
                    MessageBox.Show("添加成功");
                    Transmit.FrmFood.dgvFoodInfo.DataSource = FoodManager.SelectFoodAll();
                    Transmit.FrmFood.dgvFoodInfo.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    Transmit.FrmFood.SelectFood();
                    this.Close();
                }
            }
        }
Exemplo n.º 21
0
        public ActionResult DeleteConfirmed(int id)
        {
            Foods foods = foodRepo.food(id);

            foodRepo.DeleteFood(foods);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 22
0
 void UpdateFoods(int?foodId = null)
 {
     new Thread(() =>
     {
         IEnumerable <object> filtered;
         lock (Foods)
         {
             Foods = ZooConnection.GetModels(ModelType.Food);
             if (foodId.HasValue)
             {
                 filtered = Foods.Where(food => (int)ZooClient.GetProperty(food, "ID") == foodId.Value);
             }
             else
             {
                 filtered = Foods;
             }
         }
         dataGridFoods.Dispatcher.Invoke(() =>
         {
             buttonModifyFood.IsEnabled = false;
             buttonRemoveFood.IsEnabled = false;
             dataGridFoods.ItemsSource  = filtered;
             labelFoodsCount.Content    = filtered.Sum(food => (double)ZooClient.GetProperty(food, "Amount")).ToString();
         });
     }).Start();
 }
Exemplo n.º 23
0
        public async Task ExecuteSearchFoodsCommand()
        {
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }

            cancellationTokenSource = new CancellationTokenSource();
            SetResultVisibility(true, false);

            try
            {
                Foods.Clear();
                var includUnknownFructose = AppPreferences.UnknownFructose;
                foreach (var food in await FoodDataStore.SearchFoodsAsync(SearchText, includUnknownFructose, cancellationTokenSource.Token))
                {
                    Foods.Add(new FoodViewModel(food));
                }
                SetResultVisibility(false, true);

                Analytics.TrackEvent("Search Completed", new Dictionary <string, string> {
                    { "Search Text", SearchText }
                });
            }
            catch (TaskCanceledException)
            {
                // Task was canceled so just handle the exception and move on
            }
            catch (Exception exception)
            {
                Analytics.TrackEvent("Error Searching Food", new Dictionary <string, string> {
                    { "Exception Message", exception.Message }
                });
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Attempt to position the given item at the given index. If the space is occupied already it will fail.
        /// </summary>
        /// <param name="item">The item to be positioned.</param>
        /// <param name="x">The x index of the tile to position at.</param>
        /// <param name="y">The y index of the tile to position at.</param>
        /// <returns>True if successfully positioned, false if the space was occupied.</returns>
        public bool AttemptToPositionAt(GridItem item, int x, int y)
        {
            if (!InBounds(x, y) || this.tiles[x][y].HasInhabitant)
            {
                return(false); // Space occupied
            }

            this.tiles[x][y].AddInhabitant(item);
            item.SetInitialScreenPosition(x * Tile.TILE_SIZE, y * Tile.TILE_SIZE, Tile.TILE_SIZE, Tile.TILE_SIZE);

            // Add the item to the simulation and set up appropriate event handlers
            if (item.GetType() == typeof(Organism))
            {
                var organism = (Organism)item;
                organism.DeathOccurred += OrganismDeathHandler;
                Organisms.Add(organism);
            }
            else if (item.GetType() == typeof(Food))
            {
                var food = (Food)item;
                food.DeathOccurred += FoodEatenHandler;
                Foods.Add(food);
            }



            return(true); // Successfully positioned
        }
Exemplo n.º 25
0
 private void Awake()
 {
     this.cookQueue = new Foods();
     this.animator  = base.GetComponent <Animator>();
     this.cookMeter.gameObject.SetActive(false);
     this.isPaused = true;
 }
Exemplo n.º 26
0
        public void UploadPhoto(Foods foods, HttpPostedFileBase Photo)
        {
            if (Photo != null)
            {
                string fileExtension = Path.GetExtension(Photo.FileName);

                if (!fileExtension.ToLower().Equals(".jpg"))
                {
                    ViewBag.FailMessage = "Photo invalid file type. Please use only .jpg file.";
                }
                else if (Photo.ContentLength > 1000000)
                {
                    ViewBag.FailMessage = "Photo size cannot be more than 1 MB ";
                }
                else if (Photo.ContentLength > 0 && Photo.ContentLength < 1000000)
                {
                    string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), Photo.FileName);
                    Photo.SaveAs(_path);
                    foods.PhotoFile = Photo.FileName;
                }
                else
                {
                    ViewBag.FailMessage = "Invalid. Please check the photo file";
                }
            }
        }
Exemplo n.º 27
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsRefreshing)
            {
                return;
            }

            IsRefreshing = true;

            try
            {
                Foods.Clear();
                var apiService = new Services.ApiService.ApiService();
                var foods      = await apiService.GetAllFoodsAsync();

                foreach (var c in foods)
                {
                    Foods.Add(c);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsRefreshing = false;
            }
        }
Exemplo n.º 28
0
    public void doHunt()
    {
        float goodEncounterProb = (float)0.2f + (Stealth * .06f);

        float rand = Random.Range(0.0f, 1.0f);

        int   food_idx         = Random.Range(0, 9);
        Foods found_food       = SaveSystem.LoadFoods(food_idx);
        float hunt_food_weight = found_food.weight;
        int   hunt_damage      = Mathf.FloorToInt(Random.Range(5f, 10f));

        if (goodEncounterProb > rand)
        {
            message.text = "You found " + found_food.name + "\n You got " + hunt_food_weight.ToString() + "lbs of food";
            if (curr_weight + hunt_food_weight > max_weight)
            {
                Food += max_weight - curr_weight;
            }
            else
            {
                Food = Food + hunt_food_weight;
            }
            SavePlayer();
        }
        else
        {
            float fightChance = calcFightChance();
            float win         = Random.Range(0.0f, 1.0f);
            if (fightChance > win)
            {
                message.text = "You didn't see a Zombie, but it saw you and attacked... \n But you killed it with your " + weapon.name;
                SavePlayer();
            }
            else
            {
                message.text = "You didn't see a Zombie, but it saw you \n It attacked and hurt you for " + ((int)hunt_damage).ToString() + " damage";
                Health       = Health - (int)hunt_damage;
                SavePlayer();
            }
        }

        if (Health <= 0)
        {
            deathMessage = "A hidden zombie attacked you for " + hunt_damage.ToString() + " damage and it killed you";
            SaveSystem.SaveDeathMessage(deathMessage);
            LoadDefault();
            SaveSystem.SaveFood("moderate");
            setDefaultInventory();
            SavePlayer();
            SceneManager.LoadScene(10);
        }
        //modal.SetActive(false);
        yesHunt.enabled = false;
        noHunt.enabled  = false;
        yesHunt.gameObject.SetActive(false);
        noHunt.gameObject.SetActive(false);
        moveAlong.enabled = true;
        moveAlong.gameObject.SetActive(true);
        Inventory.enabled = true;
    }
Exemplo n.º 29
0
        public async override Task InitializeAsync(INavigation navigation)
        {
            await base.InitializeAsync(navigation);

            Foods.Clear();
            Foods.AddRange(await DataStore.FoodEntries.Get());
        }
Exemplo n.º 30
0
 public override void Eat(Foods food)
 {
     this.BaseEat(food, new List <string>()
     {
         nameof(Vegetable), nameof(Fruit)
     }, WeightIncrease);
 }
Exemplo n.º 31
0
        public ActionResult Create(Foods foods)
        {
            if (ModelState.IsValid)
            {
                db.Foods.Add(foods);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(foods);
        }
Exemplo n.º 32
0
 public ActionResult Edit(Foods foods)
 {
     if (ModelState.IsValid)
     {
         db.Entry(foods).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(foods);
 }