public static CardPile MakeCardPile(int i) { System.Random rand = new System.Random(); GameObject g = Instantiate(Resources.Load("Card_Select"), new Vector3(0, 0), Quaternion.identity) as GameObject; g.tag = "CardPile"; CardPile c = g.GetComponent <CardPile>(); List <CardState> cards = new List <CardState>(); for (int k = 0; k < i + 1; k++) { //cards.Add(allCardBuilders[rand.Next(allCardBuilders.Count)].GetCardState(0)); cards.Add(CardStateBuilder.GetRandomCard()); } c.AddList(cards); int num = 5; if (i < num) { num = i; } c.Initiate(num); return(c); }
private IEnumerator DoTasks() { controller.RunningTasks(true); List <Task> tasks = cardState.GetTasks(); bool flag = false; int i = 0; foreach (Task task in tasks) { //set the appropriate task switch (tasks[i].type) { case Task.Input.Null: tasks[i].Run(null); break; case Task.Input.Enemy: controller.SetSelectionType(GameController.SelectionType.SelectEntity); while (!(controller.GetInput().GetComponent <Entity>() is Enemy)) { yield return(null); } task.Run(controller.GetInput()); break; case Task.Input.Player: controller.SetSelectionType(GameController.SelectionType.SelectEntity); while (!(controller.GetInput().GetComponent <Entity>() is Player)) { yield return(null); } task.Run(controller.GetInput()); break; case Task.Input.Entity: controller.SetSelectionType(GameController.SelectionType.SelectEntity); flag = true; while (controller.GetInput() == null) { yield return(null); } task.Run(controller.GetInput()); StartCoroutine(Animation(controller.GetInput())); controller.SetInput(null); break; case Task.Input.Card: controller.SetSelectionType(GameController.SelectionType.SelectCard); while (controller.GetInput() == null) { yield return(null); } cardState.GetTasks()[i].Run(controller.GetInput()); break; case Task.Input.DiscardCard: GameObject g = Instantiate(Resources.Load("Card_Select"), new Vector3(0, 0), Quaternion.identity) as GameObject; g.tag = "CardPile"; CardPile c = g.GetComponent <CardPile>(); c.AddList(controller.currentPlayer.GetDiscards()); c.Initiate(5); controller.SetSelectionType(GameController.SelectionType.CardPileSelect); while (controller.GetInput() == null) { yield return(null); } cardState.GetTasks()[i].Run(controller.GetInput()); c.DestroyAll(); break; } i++; } GameObject.FindWithTag("MainCamera").GetComponent <AudioSource>().PlayOneShot(cardState.soundEffect, 1); // Lose energy and discard played card Player p = (Player)controller.currentEntity.gameObject.GetComponent <Entity>(); p.LoseEnergy(cardState.GetCost()); if (!flag) { p = (Player)controller.currentEntity.gameObject.GetComponent <Entity>(); p.Discard(gameObject); } controller.RunningTasks(false); controller.SetInput(null); controller.SetSelectionType(GameController.SelectionType.SelectCardToPlay); }