/// <summary> /// Sets up the game and creates a new deal based on the given seed. /// </summary> public IEnumerator NewGame(int seed) { yield return(new WaitForEndOfFrame()); // to give itween a chance to avoid it's initalization bug. GetComponent <AudioSource>().Play(); HasWon = false; foreach (var card in FindObjectsOfType <Card>()) { Destroy(card.gameObject); } foreach (var deck in FindObjectsOfType <Deck>()) { if (deck != Dealer) { Destroy(deck.gameObject); } } GameBehavior.Cards.Clear(); Moves = new Stack <Move>(); redoMoves = new Stack <Move>(); ClearStaircases(); for (int i = 0; i < Cells; i++) { CreateFreeCell(); } GoalCells.Clear(); var startPositionX = 0.625f + 0.05f; var xSpacing = Suits <= 6 ? 1.24f : 6.2f / (Suits - 1); for (int i = 0; i < Suits; i++) { var deck = (Instantiate(GameBehavior.Instance.DeckPrefab) as GameObject).GetComponent <Deck>(); deck.CardSpacerY = 0.001f; deck.MaxCardsSpace = 15; deck.transform.position = new Vector3(startPositionX + (i * xSpacing), 3.3f, 0); deck.transform.parent = transform; deck.Type = DeckType.Goal; deck.Index = i; GoalCells.Add(deck); } PlayCells.Clear(); startPositionX = ((Stacks - 1) / 2f) * -1.24f; for (int i = 0; i < Stacks; i++) { var deck = (Instantiate(GameBehavior.Instance.DeckPrefab) as GameObject).GetComponent <Deck>(); deck.enabled = true; deck.CardSpacerY = PlayStackVerticalSpace; deck.MaxCardsSpace = 13; deck.transform.position = new Vector3(startPositionX + (i * 1.24f), 1.6f, 0); deck.transform.parent = transform; deck.Type = DeckType.Play; PlayCells.Add(deck); } Dealer.CreateCards(Suits); var random = new System.Random(seed); Dealer.Shuffle(3, random); Dealer.FlipAllCards(); Dealer.CardSpacerX = 0; Dealer.MaxCardsSpace = 20; foreach (var card in Dealer.Cards) { card.Visible = true; } var count = 0; while (Dealer.Cards.Count > 0) { Dealer.Draw(PlayCells[count % PlayCells.Count], 1); count++; } if (Difficulty < 0) { for (int i = 0; i < -Difficulty * Suits; i++) { // find all aces thru threes that aren't on top of deck already var potentialCards = (from c in GameBehavior.Cards where c.Number <= 3 && c.Deck.TopCard != c select c).ToArray(); if (potentialCards.Length > 0) { var card = potentialCards[random.Next(0, potentialCards.Length)]; //print("Pushing up " + card.ToString()); card.SetDeck(card.Deck.Cards.IndexOf(card) + 1); } } } else { for (int i = 0; i < Difficulty * Suits; i++) { // find all aces thru threes that aren't on bottom of deck already var potentialCards = (from c in GameBehavior.Cards where c.Number <= 3 && c.Deck.BottomCard != c select c).ToArray(); if (potentialCards.Length > 0) { var card = potentialCards[random.Next(0, potentialCards.Length)]; //print("Pushing down " + card.ToString()); card.SetDeck(card.Deck.Cards.IndexOf(card) - 1); } } } CalculateDragableCards(); StartTime = Time.time; }
/// <summary> /// Sets up the game and creates a new deal based on the given seed. /// </summary> public IEnumerator NewGame(int seed) { yield return(new WaitForEndOfFrame()); // to give itween a chance to avoid it's initalization bug. GetComponent <AudioSource>().Play(); HasWon = false; foreach (var card in FindObjectsOfType <Card>()) { Destroy(card.gameObject); } foreach (var deck in FindObjectsOfType <Deck>()) { if (deck != Dealer) { Destroy(deck.gameObject); } } GameBehavior.Cards.Clear(); Moves = new Stack <Move>(); redoMoves = new Stack <Move>(); FreeCells.Clear(); for (int i = 0; i < Cells; i++) { CreateFreeCell(); } GoalCells.Clear(); var startPositionX = 0.625f + 0.05f; var xSpacing = Suits <= 6 ? 1.24f : 6.2f / (Suits - 1); for (int i = 0; i < Suits; i++) { // var deck = (Instantiate(GameBehavior.Instance.DeckPrefab) as GameObject).GetComponent<Deck>(); // var deck = (Instantiate(GameBehavior.Instance.DeckAPrefab) as GameObject).GetComponent<Deck>(); Deck deck = null; if (Screen.orientation == ScreenOrientation.Portrait) // if (Input.deviceOrientation == DeviceOrientation.Portrait) { deck = (Instantiate(GameBehavior.Instance.DeckOtherAPrefab) as GameObject).GetComponent <Deck>(); deck.gameObject.tag = "HelpCard"; } else if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) { deck = (Instantiate(GameBehavior.Instance.DeckAPrefab) as GameObject).GetComponent <Deck>(); deck.gameObject.tag = "HelpCard"; } TempADeck.Add(deck); deck.gameObject.tag = "HelpCard"; deck.CardSpacerY = 0.001f; deck.MaxCardsSpace = 15; // deck.transform.position = new Vector3(startPositionX + (i * xSpacing), 3.3f, 0); if (Screen.orientation == ScreenOrientation.Portrait) { deck.transform.position = new Vector3((0.225f) + (i * 0.5f), 3.3f, 0); } else if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) { //old deck.transform.position = new Vector3(-6.3f, 1.2f + startPositionX - (i * 1.6f), 0); deck.transform.position = new Vector3(+6.3f, 1.2f + startPositionX - (i * 1.6f), 0); } deck.transform.parent = transform; deck.Type = DeckType.Goal; deck.Index = i; decksArray2.Add(deck); GoalCells.Add(deck); } PlayCells.Clear(); startPositionX = ((Stacks - 1) / 2f) * -1.24f; for (int i = 0; i < Stacks; i++) { Deck deck = null; if (Screen.orientation == ScreenOrientation.Portrait) { deck = (Instantiate(GameBehavior.Instance.DeckSmallOtherPrefab) as GameObject).GetComponent <Deck>(); deck.gameObject.tag = "StackCard"; } else if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) { deck = (Instantiate(GameBehavior.Instance.DeckPrefab) as GameObject).GetComponent <Deck>(); deck.gameObject.tag = "StackCard"; } deck.gameObject.tag = "StackCard"; deck.enabled = true; deck.CardSpacerY = PlayStackVerticalSpace; deck.MaxCardsSpace = 13; if (Screen.orientation == ScreenOrientation.Portrait) { // deck.transform.position = new Vector3(startPositionX + (i * 1.24f), 2.8f, 0); deck.transform.position = new Vector3(-1.775f + (i * 0.5f), 1.6f, 0); } else if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) { // deck.transform.position = new Vector3(startPositionX + (i * 1.24f), 1.6f, 0); deck.MaxCardsSpace = 13; // startPositionX = ((Stacks - 1) / 2f); deck.transform.position = new Vector3(startPositionX + (i * 1.24f), 2.8f, 0); } deck.transform.parent = transform; deck.Type = DeckType.Play; PlayCells.Add(deck); decksArray4.Add(deck); } // stackReference = GameObject.FindGameObjectsWithTag("StackCard"); // stackReference[0].transform.GetChild(0).transform.gameObject.transform.localScale = new Vector3(1, 1, 1); Dealer.CreateCards(Suits); var random = new System.Random(seed); Dealer.Shuffle(3, random); Dealer.FlipAllCards(); Dealer.CardSpacerX = 0; Dealer.MaxCardsSpace = 20; // for (int i = 0; i < 4; i++) { // } foreach (var card in Dealer.Cards) { card.Visible = true; } var count = 0; while (Dealer.Cards.Count > 0) { Dealer.Draw(PlayCells[count % PlayCells.Count], 1); count++; } if (Difficulty < 0) { for (int i = 0; i < -Difficulty * Suits; i++) { // find all aces thru threes that aren't on top of deck already var potentialCards = (from c in GameBehavior.Cards where c.Number <= 3 && c.Deck.TopCard != c select c).ToArray(); if (potentialCards.Length > 0) { var card = potentialCards[random.Next(0, potentialCards.Length)]; //print("Pushing up " + card.ToString()); card.SetDeck(card.Deck.Cards.IndexOf(card) + 1); } } } else { for (int i = 0; i < Difficulty * Suits; i++) { // find all aces thru threes that aren't on bottom of deck already var potentialCards = (from c in GameBehavior.Cards where c.Number <= 3 && c.Deck.BottomCard != c select c).ToArray(); if (potentialCards.Length > 0) { var card = potentialCards[random.Next(0, potentialCards.Length)]; //print("Pushing down " + card.ToString()); card.SetDeck(card.Deck.Cards.IndexOf(card) - 1); } } } CalculateDragableCards(); stackReference = GameObject.FindGameObjectsWithTag("StackCard"); for (int i = 0; i < Stacks; i++) { stackReference[i].transform.GetChild(0).transform.gameObject.transform.localScale = new Vector3(1f, 1f, 1f); } StartTime = Time.time; }