public void Init() { card = CardDataTable.Create(); cardIndexer = new CardIndexer(card); condition = ConditionDataTable.Create(); variable = GlobalVariableDataTable.Create(); }
void CreateCardGameElements(List <CardIndexer> phrase) { dropoffs = new List <CardDropoff>(); for (int i = 0; i < phrase.Count; i++) { CardIndexer cardIndexer = phrase[i]; CardData card = cardIndexer.Card; CardPickup cardP = GameObject.Instantiate(CardPickup, PickupParent).GetComponent <CardPickup>(); cardP.transform.position = PickupParent.position; //Pick card based on directionality cardP.SetCard(cardIndexer, Direction); CardDropoff dropoff = GameObject.Instantiate(CardDropOff, DropoffParent).GetComponent <CardDropoff>(); dropoff.transform.position = DropoffParent.position; //From or to length string textCard = Direction == CardManager.Direction.To ? card.To : card.From; string textBlock = Direction == CardManager.Direction.To ? card.From : card.To; //Temp String formatting for capital first letter and period at end if (i == 0) { if (!string.IsNullOrEmpty(textCard)) { textCard = textCard.First().ToString().ToUpper() + textCard.Substring(1); } if (!string.IsNullOrEmpty(textBlock)) { textBlock = textBlock.First().ToString().ToUpper() + textBlock.Substring(1); } } else if (i == phrase.Count - 1) { if (!string.IsNullOrEmpty(textCard)) { textCard += "."; } if (!string.IsNullOrEmpty(textBlock)) { textBlock += "."; } } GameObject uiText = GameObject.Instantiate(TextBlock, BlockUI); uiText.GetComponentInChildren <TextMeshProUGUI>().text = textBlock; dropoff.SetCard(cardIndexer, Direction, uiText); dropoffs.Add(dropoff); } }
/// <summary> /// Gets list of cards that /// A) Has the largest phrases left to right /// B) If there are multiple largest phrases sort by (favorited -> owner -> dateCreated) /// </summary> /// <returns></returns> List <CardIndexer> GetBestPhrase() { List <CardIndexer> cardPhrase = new List <CardIndexer>(); var swipablePhrases = GetSwipablePhrases(); for (int i = 0; i < swipablePhrases.Count; i++) { List <CardIndexer> cardList = swipablePhrases[i]; //Sort by favorite, owned, whatever //Player saved card data not yet available //var sortedCards = cardList.OrderBy(x => x.Card.Favorited).ThenBy(x => x.Card.owner == myself).ThenBy( x => x.Card.owner).ThenBy( x => x.Card.creationDate); //cardPhrase.Add(sortedCards.First()); CardIndexer card = cardList.Count > 0 ? cardList[0] : null; cardPhrase.Add(card); } return(cardPhrase); }
/// <summary> /// Gets list of cards that /// A) Has the largest phrases left to right /// B) Cards of the same size are grouped together (can be swiped through) /// </summary> /// <returns></returns> List <List <CardIndexer> > GetSwipablePhrases() { List <List <CardIndexer> > cardPhrase = new List <List <CardIndexer> >(); for (int i = 0; i < wordIndices.Count;) { List <CardIndexer> cardPile = new List <CardIndexer>(); cardPhrase.Add(cardPile); List <CardIndexer> words = wordIndices[i]; if (words.Count == 0) { i++; continue; } //Sort descending by longest element words.Sort((x, y) => y.Length.CompareTo(x.Length)); //Since list is sorted the largest length is the first element int length = words[0].Length; for (int j = 0; j < words.Count; j++) { CardIndexer cI = words[j]; if (cI.Length == length) { cardPile.Add(cI); } else { break; } } i += length; } return(cardPhrase); }