コード例 #1
0
    IEnumerator WaitForDrawCard(IngredientCard choice1, IngredientCard choice2, System.Action <IngredientCard> result)
    {
        bool selected = false;

        Debug.Log(choice1);
        Debug.Log(choice2);

        overlayDraw1.GetComponent <IngredientCardViz>().LoadCard(choice1);
        overlayDraw2.GetComponent <IngredientCardViz>().LoadCard(choice2);

        overlayDraw1.GetComponent <IngredientCardViz>().setButton("J");
        overlayDraw2.GetComponent <IngredientCardViz>().setButton("K");

        overlayDraw1.SetActive(true);
        overlayDraw2.SetActive(true);

        while (!selected)
        {
            if (Input.GetKeyDown(KeyCode.J))
            {
                selected = true;
                result(choice1);
            }
            if (Input.GetKeyDown(KeyCode.K))
            {
                selected = true;
                result(choice2);
            }
            yield return(null);
        }
    }
コード例 #2
0
    private void GenerateIngDeck()
    {
        ingredientDeck = new List <IngredientCard>();

        Dictionary <string, bool> paths = new Dictionary <string, bool>
        {
            ["Cards/Ingredient/MeatBonus"]    = true,
            ["Cards/Ingredient/FishBonus"]    = true,
            ["Cards/Ingredient/FlourBonus"]   = true,
            ["Cards/Ingredient/SpinachBonus"] = true,
            ["Cards/Ingredient/Meat"]         = false,
            ["Cards/Ingredient/Fish"]         = false,
            ["Cards/Ingredient/Flour"]        = false,
            ["Cards/Ingredient/Spinach"]      = false
        };

        //load cards
        foreach (string path in paths.Keys)
        {
            if (paths[path])
            {
                for (int i = 0; i < 2; i++)
                {
                    ingredientDeck.Add(Resources.Load(path) as IngredientCard);
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    ingredientDeck.Add(Resources.Load(path) as IngredientCard);
                }
            }
        }

        //shuffle cards
        for (int i = 0; i < ingredientDeck.Count; i++)
        {
            IngredientCard temp        = ingredientDeck[i];
            int            randomIndex = Random.Range(i, ingredientDeck.Count);
            ingredientDeck[i]           = ingredientDeck[randomIndex];
            ingredientDeck[randomIndex] = temp;
        }

        //set index to 0
        ingredientIdx = 0;
    }
コード例 #3
0
    public void LoadCard(IngredientCard c)
    {
        if (c == null)
        {
            return;
        }

        card       = c;
        title.text = c.title;
        art.sprite = c.sprite;

        if (c.bonus)
        {
            bonus.gameObject.SetActive(true);
            bonusBGColor.color = new Color(1f, 1f, 1f);
        }
        else
        {
            bonus.gameObject.SetActive(false);
            bonusBGColor.color = new Color(0f, 0f, 0f, 0f);
        }
    }
コード例 #4
0
    IEnumerator UsableEventPhase()
    {
        Debug.Log("Usable Phase");

        // use or skip
        EventCard selected = null;

        yield return(StartCoroutine(WaitForUsable(AllUsaCard[player - 1], value => selected = value)));

        Debug.Log(selected);

        if (selected != null)
        {
            bool usingSuccessful = true;
            switch (selected.title)
            {
            case "Reloaded":
                if (AllIngCard[player - 1].Count >= 9)
                {
                    usingSuccessful = false;
                    break;
                }
                for (int i = 0; i < 2; i++)
                {
                    IngredientCard draw = ingredientDeck[ingredientIdx];
                    AllIngCard[player - 1].Add(draw);
                    ingredientIdx = (ingredientIdx + 1) % ingredientDeck.Count;
                }

                UpdateIngCard(0, player - 1);
                break;
            }
            if (usingSuccessful)
            {
                AllUsaCard[player - 1].Remove(selected);
            }
            UpdateUsaCard(player - 1);
        }
    }
コード例 #5
0
    IEnumerator DrawIngredientPhase()
    {
        Debug.Log("Draw Ingredient Phase");
        yield return(new WaitForSeconds(1));

        // check number of card
        while (AllIngCard[player - 1].Count < 2)
        {
            AllIngCard[player - 1].Add(ingredientDeck[ingredientIdx]);
            ingredientIdx = (ingredientIdx + 1) % ingredientDeck.Count;
            UpdateIngCard(0, player - 1);
        }

        // draw two choose 1
        IngredientCard choice1 = ingredientDeck[ingredientIdx];
        IngredientCard choice2 = ingredientDeck[ingredientIdx + 1];

        ingredientIdx = (ingredientIdx + 2) % ingredientDeck.Count;

        IngredientCard selected = null;

        yield return(StartCoroutine(WaitForDrawCard(choice1, choice2, value => selected = value)));

        overlayDraw1.SetActive(false);
        overlayDraw2.SetActive(false);

        if (AllIngCard[player - 1].Count <= 7)
        {
            AllIngCard[player - 1].Add(selected);
        }

        UpdateIngCard(0, player - 1);
        assignIngredientButton(false, player - 1);

        phase = "DrawEvent";
    }
コード例 #6
0
    IEnumerator WaitForCooking(DishCard dishCard)
    {
        assignIngredientButton(true, player - 1);
        List <IngredientCard> needed = new List <IngredientCard>(dishCard.ingredients);

        List <int> used = new List <int>();

        while (needed.Count > 0)
        {
            int idx = -1;

            if (Input.GetKeyDown(KeyCode.Q))
            {
                idx = 0;
            }
            else if (Input.GetKeyDown(KeyCode.W))
            {
                idx = 1;
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                idx = 2;
            }
            else if (Input.GetKeyDown(KeyCode.R))
            {
                idx = 3;
            }
            else if (Input.GetKeyDown(KeyCode.T))
            {
                idx = 4;
            }
            else if (Input.GetKeyDown(KeyCode.Y))
            {
                idx = 5;
            }
            else if (Input.GetKeyDown(KeyCode.U))
            {
                idx = 6;
            }
            else if (Input.GetKeyDown(KeyCode.I))
            {
                idx = 7;
            }
            else if (Input.GetKeyDown(KeyCode.O))
            {
                idx = 8;
            }
            else if (Input.GetKeyDown(KeyCode.P))
            {
                idx = 9;
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                used = new List <int>();
                break;
            }

            if (idx > -1 && idx < AllIngCard[player - 1].Count)
            {
                IngredientCard pop = needed.Find(x => x.title == AllIngCard[player - 1][idx].title);
                if (pop != null)
                {
                    if (!used.Contains(idx))
                    {
                        used.Add(idx);
                        needed.Remove(pop);
                        IngredientCardViz Viz = AllIngTransform[0].GetChild(idx).GetComponent <IngredientCardViz>();
                        Viz.setSelected(true);
                        UpdateIngCard(0, player - 1);
                    }
                }
            }

            yield return(null);
        }

        if (needed.Count == 0)
        {
            used.Sort();

            int bonus = 0;
            int shift = 0;
            foreach (int idx in used)
            {
                if (AllIngCard[player - 1][idx - shift].bonus)
                {
                    bonus++;
                }
                AllIngCard[player - 1].RemoveAt(idx - shift);
                shift++;
            }
            UpdateIngCard(0, player - 1);

            //update score
            scores[player - 1] += dishCard.score + bonus;

            //Check end game
            int _player = 0;
            foreach (int score in scores)
            {
                Debug.Log(score);
                _player++;
                if (score >= WINSCORE)
                {
                    Debug.Log(_player.ToString() + "Win");
                    winner = _player;
                    yield return(StartCoroutine(GameEnd()));

                    break;
                }
            }

            AllDishCard.Remove(dishCard);
            UpdateDishCard();
        }
        assignIngredientButton(false, player - 1);
    }