Exemple #1
0
        private async void InfoButton_Clicked(object sender, EventArgs e)
        {
            InfoButton.IsEnabled = false;
            EquationItem equation = Equations.EquationsList.FirstOrDefault(x => x.LabelText == "Compton Scattering");
            await Navigation.PushModalAsync(new DerivationViewer(equation, "demo"));

            InfoButton.IsEnabled = true;
        }
Exemple #2
0
        private async void InfoButton_Clicked(object sender, EventArgs e)
        {
            InfoButton.IsEnabled = false;
            EquationItem equation = Equations.EquationsList.FirstOrDefault(x => x.LabelText == "Quantum Tunnelling Probability");

            await this.Navigation.PushModalAsync(new DerivationViewer(equation, "demo"));

            InfoButton.IsEnabled = true;
        }
    public void Reaction(EquationItem item, int propid)
    {
        List <int>       Energy     = item.Energy;
        List <GoodsItem> goods      = item.goods;
        List <GoodsItem> products   = item.product;
        List <int>       goodsnum   = item.goodsnum;
        List <int>       productnum = item.productnum;

        if (checkGoods(goods, goodsnum))
        {
            for (int i = 0; i < goods.Count; i++)
            {
                goods[i].itemHeld -= goodsnum[i];
                if (goods[i].itemHeld == 0)
                {
                    myBag.itemList.Remove(goods[i]);
                }
            }
            for (int i = 0; i < products.Count; i++)
            {
                if (myBag.itemList.Contains(products[i]))
                {
                    products[i].itemHeld += productnum[i];
                }
                else
                {
                    myBag.itemList.Add(products[i]);
                    products[i].itemHeld = productnum[i];
                }
            }

            for (int i = 0; i < Energy.Count; i++)
            {
                if (Energy[i] == propid)
                {
                    if (i == 0)
                    {
                        addEnergy(propid, 10);
                    }
                    if (i == 1)
                    {
                        addEnergy(propid, 5);
                    }
                }
            }
        }
        UpdateBag();
        //Debug.Log(Energy[0] + Energy[1]);
    }
Exemple #4
0
        private async void DetailsButton_Clicked(object sender, EventArgs e)
        {
            ((Button)sender).IsEnabled = false;

            string id = ((Button)sender).ClassId;

            EquationItem selected = this.Equations.FirstOrDefault(item => item.Id == id);

            if (selected != null)
            {
                await this.Navigation.PushModalAsync(new DerivationViewer(selected));
            }

            ((Button)sender).IsEnabled = true;
        }
Exemple #5
0
    private void EquationActBegin(string id)
    {
        ActTime = 0;
        foreach (var item in myBag.equationList)
        {
            if (item.Equationid == int.Parse(id))
            {
                reactItem = item;
                break;
            }
        }
        if (BagManager.instance.checkGoods(reactItem.goods, reactItem.goodsnum))
        {
            isAct = true;
        }

        Debug.Log("11");
    }
Exemple #6
0
    private void BagInitiate()
    {
        goodsItemList.RemoveChildrenToPool();
        equationItemList.RemoveChildrenToPool();

        energyprogress1.value = energy1.num;
        energyprogress2.value = energy2.num;
        energyprogress3.value = energy3.num;
        foreach (var item in myBag.itemList)
        {
            if (item != null)
            {
                GButton gButton = goodsItemList.AddItemFromPool().asButton;
                gButton.GetChild("number").asTextField.text = item.itemHeld.ToString();
                gButton.GetChild("icon").asLoader.url       = UIPackage.GetItemURL("NewBagPackage", "goods" + item.Itemid);
                gButton.GetChild("id").asTextField.text     = item.Itemid.ToString();
                gButton.GetChild("title").asTextField.text  = item.itemInfo;
                gButton.onClick.Add(() => { ClickItem(gButton); });
            }
        }
        for (int i = 0; i < 30 - myBag.itemList.Count; i++)
        {
            GButton gButton = goodsItemList.AddItemFromPool().asButton;
            gButton.GetChild("number").asTextField.text = "";
            gButton.GetChild("icon").asLoader.url       = "";
            gButton.GetChild("id").asTextField.text     = "";
            gButton.GetChild("title").asTextField.text  = "";
            gButton.onClick.Add(() => { ClickItem(gButton); });
        }

        foreach (var item in myBag.equationList)
        {
            if (item != null)
            {
                GComponent gComponent = equationItemList.AddItemFromPool().asCom;
                gComponent.GetChild("id").asTextField.text          = item.Equationid.ToString();
                gComponent.GetChild("Equation").asLoader.url        = UIPackage.GetItemURL("NewBagPackage", "reaction" + item.Equationid);
                gComponent.GetChild("FirstEnergy").asLoader.url     = UIPackage.GetItemURL("NewBagPackage", "energy" + item.FirstEnergy);
                gComponent.GetChild("SecondEnergy").asLoader.url    = UIPackage.GetItemURL("NewBagPackage", "energy" + item.SecondEnergy);
                gComponent.GetChild("information").asTextField.text = item.itemInfo;
                string productid = "";
                foreach (var itemid in item.productid)
                {
                    productid += productid + itemid + " ";
                }
                gComponent.GetChild("productid").asTextField.text = productid;
                gComponent.GetChild("UseBtn").asButton.onClick.Add(() => { UseEquation(gComponent); });
            }
        }

        if (button1.selected)
        {
            prop.url       = UIPackage.GetItemURL("NewBagPackage", "prop1");
            mainEnergy.url = UIPackage.GetItemURL("NewBagPackage", "energy1");
        }
        else if (button2.selected)
        {
            prop.url       = UIPackage.GetItemURL("NewBagPackage", "prop2");
            mainEnergy.url = UIPackage.GetItemURL("NewBagPackage", "energy2");
        }
        else if (button3.selected)
        {
            prop.url       = UIPackage.GetItemURL("NewBagPackage", "prop3");
            mainEnergy.url = UIPackage.GetItemURL("NewBagPackage", "energy3");
        }
        else
        {
            prop.url         = UIPackage.GetItemURL("NewBagPackage", "prop1");
            mainEnergy.url   = UIPackage.GetItemURL("NewBagPackage", "energy1");
            propid           = 1;
            button1.selected = true;
        }

        if (myBag.propsItems[0].equation != null)
        {
            EquationItem equation = myBag.propsItems[0].equation;
            chooseEquation.GetChild("equation").asLoader.url     = UIPackage.GetItemURL("NewBagPackage", "reaction" + equation.Equationid);
            chooseEquation.GetChild("FirstEnergy").asLoader.url  = UIPackage.GetItemURL("NewBagPackage", "energy" + equation.FirstEnergy);
            chooseEquation.GetChild("SecondEnergy").asLoader.url = UIPackage.GetItemURL("NewBagPackage", "energy" + equation.SecondEnergy);
            chooseEquation.GetChild("id").asTextField.text       = equation.Equationid.ToString();
            chooseEquation.GetChild("sign").asTextField.text     = "";
            string id = equation.Equationid.ToString();
            chooseEquation.GetChild("actBtn").asButton.onTouchBegin.Add(() => { EquationActBegin(id); });
            chooseEquation.GetChild("actBtn").asButton.onTouchEnd.Add(() => { EquationActEnd(id); });
        }

        button1.onClick.Add(() => { changeProp(1); });
        button2.onClick.Add(() => { changeProp(2); });
        button3.onClick.Add(() => { changeProp(3); });
    }
        private IEnumerable <SolutionItem> GetSolution()
        {
            var a       = _mainModel.ParameterA;
            var b       = _mainModel.ParameterB;
            var c       = _mainModel.ParameterC;
            var complex = _mainModel.AcceptComplexNumberSolutions;

            yield return(SolutionItem.WithEquation("initial equation", true, new[]
            {
                EquationItem.With("{0}x²", a),
                EquationItem.With("{0}x", b),
                EquationItem.With("{0}", c)
            }));

            if (a == 0 || b == 0 || c == 0 || Math.Abs(a) == 1 || Math.Abs(b) == 1 || Math.Abs(c) == 1)
            {
                yield return(SolutionItem.WithEquation("simplify equation", new[]
                {
                    EquationItem.With("{0}x²", a),
                    EquationItem.With("{0}x", b),
                    EquationItem.With("{0}", c)
                }));
            }

            if (a == 0 && b == 0)
            {
                if (c == 0)
                {
                    yield return(SolutionItem.WithString("solve", "x = any number"));
                }
                else
                {
                    yield return(SolutionItem.WithString("different constant values", "impossible equation"));
                }

                yield break;
            }

            if (c != 0)
            {
                yield return(SolutionItem.WithEquation("constant term to right hand side", new[]
                {
                    EquationItem.With("{0}x²", a),
                    EquationItem.With("{0}x", b)
                }, new[]
                {
                    EquationItem.With("{0}", -c)
                }));
            }

            if (a == 0)
            {
                if (b != 1)
                {
                    yield return(SolutionItem.WithEquation("divide both sides by coeficient of x", new[]
                    {
                        EquationItem.With("({0} / {1})x", b, b)
                    }, new[]
                    {
                        EquationItem.With("{0} / {1}", -c, b)
                    }));

                    yield return(SolutionItem.WithEquation("simplify equation", new[]
                    {
                        EquationItem.With("x")
                    }, new[]
                    {
                        EquationItem.With("{0} / {1}", -c, b)
                    }));
                }

                var r = -c / b;

                yield return(SolutionItem.WithEquation("solve", new[]
                {
                    EquationItem.With("x")
                }, new[]
                {
                    EquationItem.With("{0}", r)
                }));

                yield break;
            }

            if (a != 1)
            {
                if (b == 0)
                {
                    yield return(SolutionItem.WithEquation("divide both sides by coeficient of x²", new[]
                    {
                        EquationItem.With("({0} / {1})x²", a, a)
                    }, new[]
                    {
                        EquationItem.With("{0} / {1}", -c, a)
                    }));
                }
                else
                {
                    yield return(SolutionItem.WithEquation("divide both sides by coeficient of x²", new[]
                    {
                        EquationItem.With("({0} / {1})x²", a, a),
                        EquationItem.With("({0} / {1})x", b, a)
                    }, new[]
                    {
                        EquationItem.With("{0} / {1}", -c, a)
                    }));
                }

                b /= a;
                c /= a;
                a  = 1;

                yield return(SolutionItem.WithEquation("simplify equation", new[]
                {
                    EquationItem.With("x²", a),
                    EquationItem.With("{0}x", b)
                }, new[]
                {
                    EquationItem.With("{0}", -c)
                }));
            }

            var e = b / 2;
            var d = Math.Pow(e, 2);

            if (b != 0)
            {
                yield return(SolutionItem.With("calculate half of the coefficient of x and square it", new FormattableItem[]
                {
                    TextItem.With("d = "),
                    Equation.With(new[]
                    {
                        EquationItem.With("({0} / 2)²", b)
                    }, new[]
                    {
                        EquationItem.With("{0}", d)
                    })
                }));

                yield return(SolutionItem.WithEquation("add it to both sides of equation", new[]
                {
                    EquationItem.With("x²", a),
                    EquationItem.With("{0}x", b),
                    EquationItem.With("{0}", d)
                }, new[]
                {
                    EquationItem.With("{0}", -c),
                    EquationItem.With("{0}", d)
                }));
            }

            var f = -c + d;

            if (e != 0)
            {
                yield return(SolutionItem.WithEquation("complete the square and simplify", new[]
                {
                    EquationItem.With("(x + {0})²", e),
                }, new[]
                {
                    EquationItem.With("{0}", f)
                }));
            }

            if (f < 0)
            {
                if (!complex)
                {
                    yield return(SolutionItem.WithString("square on left equals negative value on right", "impossible equation"));

                    yield break;
                }
            }
            else
            {
                complex = false;
            }

            if (e != 0 || f != 0)
            {
                yield return(SolutionItem.WithEquation("square root both sides", new[]
                {
                    EquationItem.With("x"),
                    EquationItem.With("{0}", e),
                }, new[]
                {
                    EquationItem.With("±√({0})", f)
                }));
            }

            if (e != 0)
            {
                yield return(SolutionItem.WithEquation("isolate x", new[]
                {
                    EquationItem.With("x"),
                }, new[]
                {
                    EquationItem.With("{0}", -e),
                    EquationItem.With("±√({0})", f)
                }));
            }

            var g = Math.Sqrt(Math.Abs(f));

            if (e != 0 && g != 0)
            {
                yield return(SolutionItem.WithEquation("simplify equation", new[]
                {
                    EquationItem.With("x"),
                }, new[]
                {
                    EquationItem.With("{0}", -e),
                    EquationItem.With("±{0}", complex, g)
                }));
            }

            if (complex)
            {
                if (g == 0)
                {
                    yield return(SolutionItem.WithEquation("solve", new[]
                    {
                        EquationItem.With("x")
                    }, new[]
                    {
                        EquationItem.With("{0}", -e),
                    }));
                }
                else
                {
                    yield return(SolutionItem.With("solve", new FormattableItem[]
                    {
                        Equation.With(new[]
                        {
                            EquationItem.With("x")
                        }, new[]
                        {
                            EquationItem.With("{0}", -e),
                            EquationItem.With("{0}", complex, g)
                        }),
                        TextItem.With(", "),
                        Equation.With(new[]
                        {
                            EquationItem.With("x")
                        }, new[]
                        {
                            EquationItem.With("{0}", -e),
                            EquationItem.With("-{0}", complex, g)
                        })
                    }));
                }

                yield break;
            }

            var rs = new[] { -e - g, -e + g }
            .OrderBy(x => x)
            .ToArray();

            if (g == 0)
            {
                yield return(SolutionItem.WithEquation("solve", new[]
                {
                    EquationItem.With("x")
                }, new[]
                {
                    EquationItem.With("{0}", complex, rs[0])
                }));
            }
            else
            {
                yield return(SolutionItem.With("solve", new FormattableItem[]
                {
                    Equation.With(new[]
                    {
                        EquationItem.With("x")
                    }, new[]
                    {
                        EquationItem.With("{0}", complex, rs[0])
                    }),
                    TextItem.With(", "),
                    Equation.With(new[]
                    {
                        EquationItem.With("x")
                    }, new[]
                    {
                        EquationItem.With("{0}", complex, rs[1])
                    })
                }));
            }
        }
Exemple #8
0
        public DerivationViewer(EquationItem equationItem, string backToName = "List")
        {
            InitializeComponent();

            this.ViewerTitle.Text = equationItem.LabelText;
            this.BackButton.Text  = $"Back to {backToName}";

            MathView view = new MathView()
            {
                FontSize = equationItem.FontSize, HeightRequest = equationItem.HeightRequest
            };

            view.LaTeX = $@"{equationItem.EquationLatex}";
            this.ViewArea.Children.Add(view);

            BoxView boxView = new BoxView
            {
                HeightRequest   = 1,
                BackgroundColor = Color.FromHex("#999"),
                Margin          = new Thickness(0, 20, 0, 20)
            };

            this.ViewArea.Children.Add(boxView);

            foreach (var s in equationItem.DerivationStepsLatex)
            {
                if (s.IsButton)
                {
                    StackLayout infoArea = new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal
                    };
                    Label forTheAbove = new Label
                    {
                        Text                  = $"For the above: ",
                        VerticalOptions       = LayoutOptions.Center,
                        VerticalTextAlignment = TextAlignment.Center,
                    };
                    Label infoLabel = new Label
                    {
                        Text                  = $"See \"{s.ButtonNavigation}\"",
                        VerticalOptions       = LayoutOptions.Center,
                        VerticalTextAlignment = TextAlignment.Center,
                    };
                    Button infoButton = new Button
                    {
                        Text            = "PEEK",
                        Style           = (Style)Application.Current.Resources["BlueButton"],
                        VerticalOptions = LayoutOptions.Center,
                        FontSize        = 14,
                    };
                    infoButton.Clicked += async(sender, args) =>
                    {
                        var equationToShow = Equations.EquationsList.FirstOrDefault(x => x.LabelText == s.ButtonNavigation);
                        if (equationToShow != null)
                        {
                            await this.Navigation.PushModalAsync(new DerivationViewer(equationToShow, equationItem.LabelText));
                        }
                    };
                    infoArea.Children.Add(forTheAbove);
                    infoArea.Children.Add(infoLabel);
                    infoArea.Children.Add(infoButton);
                    this.ViewArea.Children.Add(infoArea);
                }
                else
                {
                    MathView newview = new MathView {
                        FontSize = s.FontSize, HeightRequest = s.HeightRequest
                    };
                    newview.LaTeX = $@"{s.Latex}";
                    this.ViewArea.Children.Add(newview);
                }
            }
        }