Exemplo n.º 1
0
        public void StartNewDay()
        {
            //Calculate Next-day effects

            /*
             *          Nutrients["Fat"] = 0.0;
             *          Nutrients["Carbohydrates"] = 0.0;
             *          Nutrients["Protein"] = 0.0;
             *          Nutrients["Fiber"] = 0.0;
             */
            Yesterday                 = new Player();
            Yesterday.MoneyToDate     = MoneyToDate;
            Yesterday.HappinessToDate = HappinessToDate;
            Yesterday.Nutrients       = Nutrients;
            Yesterday.Calories        = Calories;
            Yesterday.Hunger          = Hunger;
            Yesterday.Energy          = Energy;
            Yesterday.TargetCalories  = 2000;

            MoneyToDate     = 0;
            HappinessToDate = 0;
            Nutrients       = new NutrientSet();
            Calories        = 0;
            Hunger          = 0;
            Energy          = 100;
            TargetCalories  = 0;
            HoursIntoDay    = 0;
            ReadyToEndDay   = false;
        }
Exemplo n.º 2
0
            public override IDictionary <string, object> Serialize(
                object obj,
                System.Web.Script.Serialization.JavaScriptSerializer serializer
                )
            {
                Florine.NutrientSet         ns     = obj as Florine.NutrientSet;
                Dictionary <string, object> result = new Dictionary <string, object>();

                if (null != ns)
                {
                    // Create the representation.
                    System.Collections.ArrayList itemsList = new System.Collections.ArrayList();

                    foreach (KeyValuePair <Florine.Nutrient, NutrientAmount> kvp in ns)
                    {
                        //Add each entry to the dictionary.
                        itemsList.Add(new Dictionary <string, object>()
                        {
                            { "n", new Florine.Nutrient()
                              {
                                  Name = kvp.Key.Name
                              } },
                            { "v", (double)(kvp.Value) }
                        }
                                      );
                    }
                    result["Nutrients"] = itemsList;
                }
                return(result);
            }
Exemplo n.º 3
0
 public void AdjustNutrients(Florine.NutrientSet target)
 {
     foreach (Florine.IGameOption opt in ChosenOptions)
     {
         opt.AdjustNutrients(target);
     }
 }
Exemplo n.º 4
0
            public override object Deserialize(
                IDictionary <string, object> dictionary,
                Type type,
                System.Web.Script.Serialization.JavaScriptSerializer serializer)
            {
                if (dictionary == null)
                {
                    throw new ArgumentNullException("dictionary");
                }

                if (type == typeof(Florine.NutrientSet))
                {
                    // Create the instance to deserialize into.
                    Florine.NutrientSet ns = new Florine.NutrientSet();

                    // Deserialize the ListItemCollection's items.
                    System.Collections.ArrayList itemsList =
                        (System.Collections.ArrayList)dictionary["Nutrients"];
                    foreach (object o in itemsList)
                    {
                        Dictionary <string, object> itm =
                            serializer.ConvertToType <Dictionary <String, object> >(o);

                        ns[serializer.ConvertToType <Florine.Nutrient>(itm["n"])] =
                            serializer.ConvertToType <double>(itm["v"]);
                        //list.Add(serializer.ConvertToType<ListItem>(itemsList[i]));
                    }
                    return(ns);
                }
                return(null);
            }
Exemplo n.º 5
0
 public void ReadyNextPage()
 {
     FTrack.Track();
     CurrentDelta = new NutrientSet();
     if (_currentPage.MainType == PageType.Day_Intro)
     {
         DailyDelta = new NutrientSet();
     }
     _currentPage.AppliedOptions = null;
 }
Exemplo n.º 6
0
 public virtual void AdjustNutrients(NutrientSet target)
 {
     // Probably should change NutrientSet type to inherit directly or implement IEnumX
     foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in Impact)
     {
         NutrientAmount val = 0;
         target.TryGetValue(kvp.Key, out val);
         target[kvp.Key] = val + kvp.Value;
     }
 }
Exemplo n.º 7
0
 public void AdjustNutrients(NutrientSet target)
 {
     // Probably should change NutrientSet type to inherit directly or implement IEnumX
     foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in Parent.Nutrients)
     {
         // Switch Dictionary Type to Concurrent?
         NutrientAmount val = 0;
         target.TryGetValue(kvp.Key, out val);
         target[kvp.Key] = val + kvp.Value;
     }
 }
Exemplo n.º 8
0
        public void ApplyOption(IGameOption option)
        {
            option.ImpactPlayer(this);

            NutrientSet Delta = new NutrientSet();

            option.AdjustNutrients(Delta);

            // Now Adjust Based on Targets.


            // Adjust Based on Deltas.
        }
Exemplo n.º 9
0
        public void Tick(int Hours)
        {
            //Raw Calories.
            HoursIntoDay += (double)Hours;
            double target_kcal  = 2000.0; // * HoursIntoDay/24;
            double current_kcal = 0
                                  + 9 * Nutrients["Fat"]
                                  + 4 * Nutrients["Protein"]
                                  + 4 * Nutrients["Carbohydrates"];

            Calories       = current_kcal;
            TargetCalories = target_kcal;

            if (Hours > 0)
            {
                if (HoursIntoDay > 7)
                {
                    Energy -= Hours * (100 / 16);
                }
                //Energy = 100 * Math.Min(1.0, Calories/target_kcal);
                Hunger = 100 - Energy;
                Focus  = Energy;

                //Adjust back up for simple carbs

                //Nutrient Target
                NutrientSet Delta = new NutrientSet();
                foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in Nutrients)
                {
                    //if(kvp.Key.Class != Nutrient.NutrientType.Macro) {
                    Delta[kvp.Key] = kvp.Key.DailyTarget / Hours;
                    //}
                }
                foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in Delta)
                {
                    //Nutrients[kvp.Key] -= Delta[kvp.Key];
                }
            }
        }
Exemplo n.º 10
0
 public System.Web.UI.Control RenderNutrientBlock(
     Florine.NutrientSet Nutrients,
     string Title,
     bool IncludeNutrientDetails
     )
 {
     System.Web.UI.WebControls.Panel pPanel = new System.Web.UI.WebControls.Panel();
     pPanel.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
     pPanel.BorderWidth = new System.Web.UI.WebControls.Unit("1 px");
     System.Web.UI.HtmlControls.HtmlTable tab = new System.Web.UI.HtmlControls.HtmlTable();
     if (null == Nutrients)
     {
         return(tab);
     }
     if (Nutrients.Count == 0)
     {
         return(tab);
     }
     if (null != Title)
     {
         tab.Rows.Add(new System.Web.UI.HtmlControls.HtmlTableRow()
         {
             Cells =
             {
                 new System.Web.UI.HtmlControls.HtmlTableCell()
                 {
                     ColSpan  = 2,
                     Controls =
                     {
                         new System.Web.UI.HtmlControls.HtmlGenericControl("b")
                         {
                             InnerHtml = Title
                         }
                     }
                 }
             }
         });
     }
     foreach (KeyValuePair <Florine.Nutrient, Florine.NutrientAmount> kvp in Nutrients)
     {
         tab.Rows.Add(new System.Web.UI.HtmlControls.HtmlTableRow()
         {
             Cells =
             {
                 new System.Web.UI.HtmlControls.HtmlTableCell()
                 {
                     Controls =
                     {
                         new System.Web.UI.WebControls.Literal()
                         {
                             Text = kvp.Key.Name.ToString()
                         }
                     }
                 },
                 new System.Web.UI.HtmlControls.HtmlTableCell()
                 {
                     Controls =
                     {
                         new System.Web.UI.WebControls.Literal()
                         {
                             Text = kvp.Value.ToString("N2")
                         }
                     }
                 }
             }
         });
         if (IncludeNutrientDetails &&
             null != kvp.Key.Units
             )
         {
             tab.Rows[tab.Rows.Count - 1].Cells.Add(
                 new System.Web.UI.HtmlControls.HtmlTableCell()
             {
                 Controls =
                 {
                     new System.Web.UI.WebControls.Literal()
                     {
                         Text = "/"
                                + ((null == kvp.Key.DailyTarget)?
                                   "??"
                                                                            :kvp.Key.DailyTarget.ToString())
                                + kvp.Key.Units.ToString()
                     }
                 }
             }
                 );
         }
     }
     pPanel.Controls.Add(tab);
     return(pPanel);
 }
Exemplo n.º 11
0
 private string _serializeNutrientSet(Florine.NutrientSet target)
 {
     return(_getSerializer().Serialize(target));
 }
Exemplo n.º 12
0
 public void AdjustNutrients(Florine.NutrientSet n)
 {
 }
Exemplo n.º 13
0
 public Player()
 {
     Avatar    = new Avatar();
     Nutrients = new NutrientSet();
 }