private void UpdateIngCard(int transfromIdx, int playerIdx) { int noCardDiff = AllIngTransform[transfromIdx].childCount - AllIngCard[playerIdx].Count; if (noCardDiff > 0) { for (int count = 0; count < noCardDiff; count++) { Destroy(AllIngTransform[transfromIdx].GetChild(AllIngTransform[transfromIdx].childCount - count - 1).gameObject); } } else if (noCardDiff < 0) { for (int count = 0; count > noCardDiff; count--) { Instantiate(prefabIng, AllIngTransform[transfromIdx]).GetComponent <CardBehavior>().canvas = overlayCanvas; } } for (int idx = 0; idx < AllIngCard[playerIdx].Count; idx++) { IngredientCardViz Viz = AllIngTransform[transfromIdx].GetChild(idx).GetComponent <IngredientCardViz>(); Viz.LoadCard(AllIngCard[playerIdx][idx]); } }
private void assignIngredientButton(bool visible, int currentPlayer) { List <string> buttons = new List <string>() { "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P" }; if (visible) { for (int j = 0; j < AllIngCard[currentPlayer].Count; j++) { IngredientCardViz Viz = AllIngTransform[0].GetChild(j).GetComponent <IngredientCardViz>(); Viz.setButton(buttons[j]); } } else { for (int j = 0; j < AllIngTransform[0].childCount; j++) { IngredientCardViz Viz = AllIngTransform[0].GetChild(j).GetComponent <IngredientCardViz>(); Viz.setButton(null); } } }
private void CyclePlayerIng() { List <int> noCard = new List <int>() { player1Ing.Count, player2Ing.Count, player3Ing.Count, player4Ing.Count }; for (int shift = 0; shift < 4; shift++) { int noCardDiff = AllIngTransform[shift].childCount - noCard[(player + shift) % 4]; if (noCardDiff > 0) { for (int count = 0; count < noCardDiff; count++) { Destroy(AllIngTransform[shift].GetChild(AllIngTransform[shift].childCount - count - 1).gameObject); } } else if (noCardDiff < 0) { for (int count = 0; count > noCardDiff; count--) { Instantiate(prefabIng, AllIngTransform[shift]).GetComponent <CardBehavior>().canvas = overlayCanvas; } } for (int idx = 0; idx < AllIngCard[(player + shift) % 4].Count; idx++) { IngredientCardViz Viz = AllIngTransform[shift].GetChild(idx).GetComponent <IngredientCardViz>(); Viz.LoadCard(AllIngCard[(player + shift) % 4][idx]); } } }
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); }