Ejemplo n.º 1
0
    public void DoSetup(LiquidType lt, CocktailMeasure measure, Glass glass)
    {
        RefreshNeeded = true;
        LiquidType    = lt;
        Text.enabled  = true;
        Image.enabled = true;
        Liquid        = null;
        Measure       = measure;
        Glass         = glass;

        if (Measure != null)
        {
            Image.sprite = TexNone;
            Won          = IngredientWin.None;
        }
        else
        {
            Image.sprite = TexIncorrect;
            Won          = IngredientWin.Wrong;
        }
    }
Ejemplo n.º 2
0
    public void Update()
    {
        if (RefreshNeeded)
        {
            RefreshNeeded = false;

            bool hasMeasure = HasMeasure();
            bool hasLiquid  = HasLiquid();


            if (hasMeasure && Glass != null)
            {
                Won = GetWin();

                switch (Won)
                {
                case IngredientWin.None:
                    Image.sprite = TexNone;
                    break;

                case IngredientWin.Partial:
                    Image.sprite = TexMiddle;
                    break;

                case IngredientWin.Exact:
                    Image.sprite = TexCorrect;
                    break;

                case IngredientWin.Over:
                    Image.sprite = TexPlus;
                    break;

                case IngredientWin.Wrong:
                    Image.sprite = TexIncorrect;
                    break;
                }


                if (hasLiquid && Glass != null)
                {
                    float liquidAmount = Liquid.amount;

                    if (Liquid.type == LiquidType.Beer && Glass.BeerHead != null)
                    {
                        liquidAmount += Glass.BeerHead.amount;
                    }

                    Text.text = GlassLiquid.LiquidTypeAndMlWithMeasureToString(liquidAmount, Measure.Amount, Liquid.type, Glass.GlassType);
                }
                else
                {
                    Text.text = String.Format("{0}", Measure.Text);
                }
            }
            else if (hasLiquid)
            {
                Image.sprite = TexIncorrect;
                Text.text    = GlassLiquid.LiquidTypeAndMeasureToStringFloatAmount(Liquid.amount, Liquid.type, Glass.GlassType);
                Won          = IngredientWin.Wrong;
            }
            else
            {
                Image.sprite = TexIncorrect;
                Text.text    = String.Format("??? {0} ", LiquidType);
            }
        }
    }
Ejemplo n.º 3
0
    // 1-5 stars.
    public int GetWin()
    {
        bool hasIngredients = false, havePartialIngredients = false, haveMissingIngredients = false, haveCorrectAmounts = false, haveOver = false, emptyGlass = true;
        int  extraIngredients = 0;

        foreach (var ingredient in ingredients)
        {
            if (ingredient.LiquidType == LiquidType.BeerHead || ingredient.LiquidType == LiquidType.None)
            {
                continue;
            }

            hasIngredients = true;

            if (ingredient.Measure == null)
            {
                extraIngredients++;
                continue;
            }
            else
            {
                IngredientWin win = ingredient.GetWin();
                switch (win)
                {
                case IngredientWin.None:
                    haveMissingIngredients = true;
                    break;

                case IngredientWin.Partial:
                    havePartialIngredients = true;
                    haveCorrectAmounts     = false;
                    break;

                case IngredientWin.Exact:
                    if (havePartialIngredients == false)
                    {
                        haveCorrectAmounts = true;
                    }
                    break;

                case IngredientWin.Over:
                    haveOver = true;
                    break;

                case IngredientWin.Wrong:
                    extraIngredients++;
                    break;
                }
            }
        }

        if (haveMissingIngredients)
        {
            haveCorrectAmounts = false;
        }

        int score = 5;

        //Debug.LogFormat("Has={0}, Partial={1}, Missing={2}, Correct={3}, Over={4}, Empty={5}, Extra={6}", hasIngredients, havePartialIngredients, haveMissingIngredients, haveCorrectAmounts, haveOver, emptyGlass, extraIngredients);

        if (hasIngredients == false)
        {
            //Debug.Log("No Ingredients");
            return(0);
        }

        if (extraIngredients > 0)
        {
            if (extraIngredients == 1)
            {
                score--;
            }
            else if (extraIngredients == 2)
            {
                score -= 2;
            }
            else if (extraIngredients >= 3)
            {
                score -= 3;
            }

            //Debug.Log("Extra " + extraIngredients);
        }

        if (!haveCorrectAmounts)
        {
            if (haveMissingIngredients)
            {
                score -= 2;
            }

            if (havePartialIngredients || haveOver)
            {
                score--;
            }
        }

        if (score < 0)
        {
            score = 0;
        }
        else if (score > 5)
        {
            score = 5;
        }

        return(score);
    }