public void PlayCard(Player p, int selectedCard) { CardInDeck selection = p.playerHand[selectedCard]; CardInDeck[] tempGameBoard = new CardInDeck[gameBoard.Length + 1]; gameBoard.CopyTo(tempGameBoard, 1); tempGameBoard[0] = selection; gameBoard = tempGameBoard; // ShowCard(selection); ModifiedShowCard(selection); tempHand = new CardInDeck[p.playerHand.Length - 1]; for (int j = 0; j < p.playerHand.Length; j++) { // Debug.Log("copying card j=" + j + " letter=" + p.playerHand[j].GLetter); if (j < selectedCard) { tempHand[j] = p.playerHand[j]; } if (j > selectedCard) { tempHand[j - 1] = p.playerHand[j]; } } p.playerHand = tempHand; }
public static async Task AddCardAsync(DbContextOptions <MemCheckDbContext> testDB, Guid deck, Guid card, int?heap = null, DateTime?lastLearnUtcTime = null, DateTime?addToDeckUtcTime = null) { heap ??= RandomHelper.Heap(); lastLearnUtcTime ??= RandomHelper.Date(); using var dbContext = new MemCheckDbContext(testDB); DateTime expiryTime; if (heap.Value != CardInDeck.UnknownHeap) { var heapingAlgo = await HeapingAlgorithm.OfDeckAsync(dbContext, deck); expiryTime = heapingAlgo.ExpiryUtcDate(heap.Value, lastLearnUtcTime.Value); } else { expiryTime = DateTime.MinValue; } var cardForUser = new CardInDeck() { CardId = card, DeckId = deck, CurrentHeap = heap.Value, LastLearnUtcTime = lastLearnUtcTime.Value, ExpiryUtcTime = expiryTime, AddToDeckUtcTime = addToDeckUtcTime ?? DateTime.UtcNow, NbTimesInNotLearnedHeap = 1, BiggestHeapReached = heap.Value }; dbContext.CardsInDecks.Add(cardForUser); await dbContext.SaveChangesAsync(); }
private static ResultCardDeckInfo GetCardDeckInfo(CardInDeck cardInDeck) { return(new ResultCardDeckInfo( cardInDeck.DeckId, cardInDeck.Deck.Description, cardInDeck.CurrentHeap, cardInDeck.BiggestHeapReached, cardInDeck.NbTimesInNotLearnedHeap, cardInDeck.AddToDeckUtcTime, cardInDeck.LastLearnUtcTime, cardInDeck.CurrentHeap == 0 || cardInDeck.ExpiryUtcTime <= DateTime.UtcNow, cardInDeck.ExpiryUtcTime)); }
public void ChooseCard(CardInDeck c) { chosenCard = c; for (int i = 0; i < players[currentPlayerIndex].playerHand.Length; i++) { if (c == players[currentPlayerIndex].playerHand[i]) { currentCardIndex = i; } hasChosen = true; } }
public void ShowCard(CardInDeck c) { GameObject newestPrefab = Instantiate(cardImagePrefab); newestPrefab.transform.SetParent(yourHand.transform); newestPrefab.name = c.GColor + " " + c.GLetter; // newestPrefab.transform.SetParent(Solitaire.handArea.transform, false); Text childText = newestPrefab.GetComponentInChildren <Text>(); cardInfoText = c.GLetter; // "NEW TEXT?"; //c.value + " of " + c. // Image childImage = newestPrefab.GetComponentInChildren<Image>(); // childImage = cardImages[2] as Sprite; childText.text = cardInfoText; }
private static ResultCardDeckInfo GetCardDeckInfo(CardInDeck cardInDeck, Dictionary <Guid, HeapingAlgorithm> heapingAlgoCache) { var heapingAlgo = heapingAlgoCache[cardInDeck.DeckId]; return(new ResultCardDeckInfo( cardInDeck.DeckId, cardInDeck.Deck.Description, cardInDeck.CurrentHeap, cardInDeck.BiggestHeapReached, cardInDeck.NbTimesInNotLearnedHeap, cardInDeck.AddToDeckUtcTime, cardInDeck.LastLearnUtcTime, cardInDeck.CurrentHeap == 0 ? true : heapingAlgo.HasExpired(cardInDeck.CurrentHeap, cardInDeck.LastLearnUtcTime), cardInDeck.CurrentHeap == 0 ? DateTime.MinValue : heapingAlgo.ExpiryUtcDate(cardInDeck.CurrentHeap, cardInDeck.LastLearnUtcTime))); }
private void BuildFullDeck() { FullDeck = new CardInDeck[99]; gameBoard = new CardInDeck[0]; deckIndex = 0; foreach (string colorx in Enum.GetNames(typeof(CardInDeck.CommonColors))) { foreach (string letterx in Enum.GetNames(typeof(CardInDeck.CommonLetters))) { CardInDeck tempCard = new CardInDeck(); tempCard.GLetter = letterx; tempCard.GColor = colorx; FullDeck[deckIndex++] = tempCard; /* * Add copies of letters that occur more than once in the deck */ if (occurs_2X.Contains(letterx)) { FullDeck[deckIndex++] = tempCard; } else if (occurs_3X.Contains(letterx)) { FullDeck[deckIndex++] = tempCard; FullDeck[deckIndex++] = tempCard; } } } foreach (string colorx in Enum.GetNames(typeof(CardInDeck.RareColors))) { foreach (string letterx in Enum.GetNames(typeof(CardInDeck.RareLetters))) { CardInDeck tempCard = new CardInDeck(); tempCard.GLetter = letterx; tempCard.GColor = colorx; FullDeck[deckIndex++] = tempCard; Debug.Log("deckIndex=" + deckIndex + " tempCard=" + tempCard.GColor + " " + tempCard.GLetter); } } }
public async Task <GetCardsInDeck.ViewModel> RunAsync(Guid deckId, Guid cardId) { var card = dbContext.Cards.Single(card => card.Id.Equals(cardId)); var cardForUser = new CardInDeck() { CardId = card.Id, Card = card, DeckId = deckId, CurrentHeap = 0, LastLearnUtcTime = DateTime.MinValue.ToUniversalTime(), AddToDeckUtcTime = DateTime.UtcNow, NbTimesInNotLearnedHeap = 1, BiggestHeapReached = 0 }; dbContext.CardsInDecks.Add(cardForUser); await dbContext.SaveChangesAsync(); return(new GetCardsInDeck.ViewModel(cardForUser.Card.Id, cardForUser.CurrentHeap, cardForUser.LastLearnUtcTime, cardForUser.BiggestHeapReached, cardForUser.NbTimesInNotLearnedHeap, cardForUser.Card.FrontSide, cardForUser.Card.BackSide)); }
public void EndRound() { GameObject newestPrefab; for (int i = 1; i <= 3; i++) { afterDraw = new CardInDeck[players[i].playerHand.Length + 1]; players[i].playerHand.CopyTo(afterDraw, 0); afterDraw[players[i].playerHand.Length] = FullDeck[i]; players[i].playerHand = afterDraw; players[i].playerList.Add(FullDeck[i - 1]); // ?? EditorUtility.DisplayDialog("Debug", "adding " + FullDeck[i - 1].GColor + " " + FullDeck[i - 1].GLetter + " to player " + i, "OK"); Array.Sort(players[i].playerHand, delegate(CardInDeck x, CardInDeck y) { return((x.GColor + x.GLetter).CompareTo(y.GColor + y.GLetter)); }); players[i].playerList.Sort(delegate(CardInDeck x, CardInDeck y) { return((x.GColor + x.GLetter).CompareTo(y.GColor + y.GLetter)); } );; } tempDeck = new CardInDeck[FullDeck.Length - 3]; for (int j = 0; j < FullDeck.Length - 3; j++) { tempDeck[j] = FullDeck[j + 3]; } FullDeck = tempDeck; for (int i = 1; i <= 3; i++) { CardInDeck c = players[i].playerList[0]; newestPrefab = Instantiate(cardImagePrefab); newestPrefab.transform.SetParent(discardPiles[i].transform); newestPrefab.name = c.GColor + " " + c.GLetter; int cardIndex = ImageIndex[c.GLetter]; if (c.GColor == "blue") { cardIndex += 20; } if (c.GColor == "green") { cardIndex += 40; } CardInfo ci = discardPiles[i].GetComponent <CardInfo>(); newestPrefab.GetComponent <Image>().sprite = cardImages[cardIndex]; players[i].playerList.RemoveAt(0); } turnCount++; string possibleWord, blackLetters, blueLetters, redLetters, greenLetters; fs = textFile.text; fLines = Regex.Split(fs, "\r\n"); for (int i = 0; i < fLines.Length - 1; i++) { keypair = Regex.Split(fLines[i], "\t"); words3[keypair[0]] = keypair[1]; } endTurnMessage = ""; oppNbr = 1; for (oppNbr = 1; oppNbr <= 3; oppNbr++) { List <CardInDeck> tempCard = players[oppNbr].playerList; blackLetters = blueLetters = redLetters = greenLetters = ""; searchedBlack.RemoveRange(0, searchedBlack.Count); searchedBlue.RemoveRange(0, searchedBlue.Count); searchedGreen.RemoveRange(0, searchedGreen.Count); searchedRed.RemoveRange(0, searchedRed.Count); for (int i = 0; i < tempCard.Count; i++) { switch (tempCard[i].GColor) { case "black": searchedBlack.Add(i); searchedBlue.Add(i); searchedGreen.Add(i); searchedRed.Add(i); blackLetters += tempCard[i].GLetter; break; case "blue": searchedBlue.Add(i); blueLetters += tempCard[i].GLetter; break; case "green": greenLetters += tempCard[i].GLetter; searchedGreen.Add(i); break; case "red": redLetters += tempCard[i].GLetter; searchedRed.Add(i); break; } } firstFound = ""; possibleWord = blackLetters + blueLetters; // Debug.Log("blackLetters = " + blackLetters + "blueLetters = " + blueLetters + " possible word " + possibleWord + " redLetters= " + redLetters + " searchedBlack.Count=" + searchedBlack.Count); if (possibleWord.Length >= 3) { searchedPos = searchedBlue; Debug.Log("returned from FindWords with blue " + FindWords(possibleWord)); } possibleWord = blackLetters + greenLetters; if (firstFound == "" && possibleWord.Length >= 3) { searchedPos = searchedGreen; Debug.Log("returned from FindWords with green " + FindWords(possibleWord)); } possibleWord = blackLetters + redLetters; if (firstFound == "" && possibleWord.Length >= 3) { // Debug.Log("before Red search: black count=" + searchedBlack.Count + " red count=" + searchedRed.Count + " full list count=" + searchedPos.Count); searchedPos = searchedRed; // EditorUtility.DisplayDialog("Debug", "calling Findwords with red " + possibleWord, "whatever"); Debug.Log("returned from FindWords with red " + FindWords(possibleWord)); } if (firstFound != "") { PlayOppWord(); } } CheckEndButton(); DrawButton.enabled = true; if (CheckWinner() == false) { if (CheckFinish() == false) { SetMessage(endTurnMessage + "Click \"Draw Card\", or drag a discard to your hand"); // Application.Quit(); } } }
public void PlayOppWord() { int childCount; string cardName; int wordValue = 0; string thisLetter; string thisWord = ""; GameObject newestPrefab; Debug.Log("firstFound=" + firstFound); ptr[0] = Convert.ToInt32(firstFound.Substring(3, 1)); ptr[1] = Convert.ToInt32(firstFound.Substring(4, 1)); ptr[2] = Convert.ToInt32(firstFound.Substring(5, 1)); // delete ?? Debug.Log(" Ptrs:" + ptr[0] + ptr[1] + ptr[2] + " posArrs:" + posArr[0] + posArr[1] + posArr[2]); for (int i = 0; i < 3; i++) { CardInDeck c = players[oppNbr].playerList[cardPositions[ptr[i] - 1]]; // posArr? players[oppNbr].playerList[cardPositions[i]].played = true; newestPrefab = Instantiate(cardImagePrefab); newestPrefab.transform.SetParent(oppArea[oppNbr].oppWords[oppWordCount[oppNbr]].transform); newestPrefab.name = c.GColor + " " + c.GLetter; int cardIndex = ImageIndex[c.GLetter]; if (c.GColor == "blue") { cardIndex += 20; } if (c.GColor == "green") { cardIndex += 40; } CardInfo ci = oppArea[oppNbr].oppWords[oppWordCount[oppNbr]].GetComponent <CardInfo>(); newestPrefab.GetComponent <Image>().sprite = cardImages[cardIndex]; childCount = oppArea[oppNbr].oppWords[oppWordCount[oppNbr]].transform.childCount; cardName = oppArea[oppNbr].oppWords[oppWordCount[oppNbr]].transform.GetChild(childCount - 1).name; thisLetter = cardName.Substring(cardName.Length - 1, 1); thisWord += thisLetter; wordValue += LetVal[thisLetter]; } oppWordCount[oppNbr]++; playerScore[oppNbr] += wordValue; Debug.Log(thisWord + " scores " + wordValue + " total = " + playerScore[oppNbr]); #if UNITY_EDITOR EditorUtility.DisplayDialog("Turn" + turnCount, playerName[oppNbr] + " makes " + thisWord + " for " + wordValue + " points, total = " + playerScore[oppNbr], "OK"); #else // SetMessage(playerName[oppNbr] + " makes " + thisWord + " for " + wordValue + " points, total = " + playerScore[oppNbr]); #endif endTurnMessage += playerName[oppNbr] + " makes " + thisWord + " for " + wordValue + " points, total = " + playerScore[oppNbr] + ". "; OppMessageText[oppNbr].text = playerName[oppNbr] + " score: " + playerScore[oppNbr]; ScoreText.text = "Your score: " + playerScore[0]; for (int i = players[oppNbr].playerList.Count - 1; i >= 0; i--) { if (players[oppNbr].playerList[i].played) { players[oppNbr].playerList[i].played = false; players[oppNbr].playerList.RemoveAt(i); } } CheckEndButton(); }
public void ModifiedShowCard(CardInDeck c) { GameObject newestPrefab = Instantiate(cardImagePrefab); newestPrefab.transform.SetParent(yourHand.transform); newestPrefab.name = c.GColor + " " + c.GLetter; switch (currentPlayerIndex) { case 0: newestPrefab.GetComponent <RectTransform>().localPosition = Vector3.zero + Vector3.up * 150; break; case 1: newestPrefab.GetComponent <RectTransform>().localPosition = Vector3.zero + Vector3.right * 150; break; case 2: newestPrefab.GetComponent <RectTransform>().localPosition = Vector3.zero + Vector3.up * -150; break; case 3: newestPrefab.GetComponent <RectTransform>().localPosition = Vector3.zero + Vector3.right * -150; break; } /* Text childText = newestPrefab.GetComponentInChildren<Text>(); * cardInfoText = c.GLetter; * childText.text = cardInfoText; * childText.fontSize = 28; * * switch (c.GColor) * { * case "red": * childText.color = Color.red; * break; * case "green": * childText.color = Color.green; * break; * case "blue": * childText.color = Color.blue; * break; * case "black": * childText.color = Color.black; * break; * } */ ImageIndex["A"] = 0; ImageIndex["B"] = 1; ImageIndex["C"] = 2; ImageIndex["D"] = 3; ImageIndex["E"] = 4; ImageIndex["F"] = 5; ImageIndex["G"] = 6; ImageIndex["H"] = 7; ImageIndex["I"] = 8; ImageIndex["J"] = 60; ImageIndex["K"] = 61; ImageIndex["L"] = 9; ImageIndex["M"] = 10; ImageIndex["N"] = 11; ImageIndex["O"] = 12; ImageIndex["P"] = 13; ImageIndex["Q"] = 62; ImageIndex["R"] = 14; ImageIndex["S"] = 15; ImageIndex["T"] = 16; ImageIndex["U"] = 17; ImageIndex["V"] = 63; ImageIndex["W"] = 18; ImageIndex["X"] = 64; ImageIndex["Y"] = 19; ImageIndex["Z"] = 65; int cardIndex = ImageIndex[c.GLetter]; if (c.GColor == "blue") { cardIndex += 20; } if (c.GColor == "green") { cardIndex += 40; } CardInfo ci = newestPrefab.GetComponent <CardInfo>(); newestPrefab.GetComponent <Image>().sprite = cardImages[cardIndex]; if (hasChosen) { Debug.Log("ci.card=" + ci.card); // ci.card = c; } }
async public Task RunAsync() { var lesson = GetPaukerLesson(); Console.WriteLine(string.Join(',', dbContext.Users)); var user = dbContext.Users.Where(user => user.UserName == "Voltan").Single(); var deck = dbContext.Decks.Where(deck => deck.Owner == user).First(); //var tag = dbContext.Tags.Where(tag => tag.Name == "PaukerImport").Single(); var cardLanguage = dbContext.CardLanguages.Where(cardLanguage => cardLanguage.Name == "Français").Single(); logger.LogInformation($"Cards will be added to deck {deck.Description} of user {user.UserName}");// and tag {tag.Name} will be attached"); const int paukerDisplayedStackIndex = 1; var stack = lesson.Stacks[paukerDisplayedStackIndex + 2]; logger.LogDebug($"Working on stack '{stack.Name}'"); logger.LogDebug($"Stack contains {stack.Cards.Count} cards"); for (int cardIndex = 0; cardIndex < stack.Cards.Count; cardIndex++) { logger.LogInformation($"Working on card {cardIndex} of {stack.Cards.Count}"); PaukerCard paukerCard = stack.Cards[cardIndex]; if (dbContext.Cards.Where(card => card.FrontSide == paukerCard.Front.Text.Trim()).Any()) { logger.LogInformation($"Card already exists in MemCheck with this front, skipping: {paukerCard.Front.Text}"); } else { CreateCard.Request request = new( user.Id, paukerCard.Front.Text.Trim(), Array.Empty <Guid>(), paukerCard.Reverse.Text.Trim(), Array.Empty <Guid>(), "", Array.Empty <Guid>(), cardLanguage.Id, Array.Empty <Guid>(), new[] { user.Id }, CardVersionDescription); Card card = new() { FrontSide = request.FrontSide, BackSide = request.BackSide, AdditionalInfo = request.AdditionalInfo, CardLanguage = cardLanguage, VersionCreator = user, InitialCreationUtcDate = DateTime.Now.ToUniversalTime(), VersionUtcDate = DateTime.Now.ToUniversalTime() }; await dbContext.Cards.AddAsync(card); var usersWithView = new List <UserWithViewOnCard>(); var userWithView = new UserWithViewOnCard() { UserId = user.Id, User = user, CardId = card.Id, Card = card }; dbContext.UsersWithViewOnCards.Add(userWithView); usersWithView.Add(userWithView); card.UsersWithView = usersWithView; //return new GetCardsOfUser.ViewModel(card.Id, card.FrontSide, card.BackSide, card.TagsInCards.Select(tagInCard => tagInCard.Tag.Name)); //var card = await creator.RunAsync(request, user); var targetHeap = GetBestMemCheckHeap(paukerCard, paukerDisplayedStackIndex); var cardInDeck = new CardInDeck() { CardId = card.Id, DeckId = deck.Id, CurrentHeap = targetHeap, LastLearnUtcTime = paukerCard.LearnedDate().ToUniversalTime(), AddToDeckUtcTime = DateTime.UtcNow, NbTimesInNotLearnedHeap = 1, BiggestHeapReached = targetHeap }; await dbContext.CardsInDecks.AddAsync(cardInDeck); //dbContext.SaveChanges(); // var cardLoaded = dbContext.Cards.Where(card => card.Id == memCheckCard.Id).Include(card => card.UsersWithView).Single(); // if (!cardLoaded.UsersWithView.Contains(user)) // throw new ApplicationException(); } //logger.LogDebug($"In stack {paukerDisplayedStackIndex}, {expiredCount} would be expired"); } await dbContext.SaveChangesAsync(); } }