/*Create the Answers list of AnswerCards, which the listview binds to. Generates four AnswerCards, with a Card and Correct properties, indicating if * this is the right answer. Each loop checks if the random card from the full list of cards of the deck is the correct choice, from the randomly * chosen card in the hand shown in the carousel view (The GetHand method is generalized so each game can use it, making it a little harder to * then also generate AnswerCards). Then that card is removed from Cards so there are no duplicates (This means we have to call the DB for a full * list of cards each time..). Then finally, checks to see if the actual answer has been one of the randomly selected, if not it adds it in a random * Position. Maybe it would be better to add the actual answer first, but it needs to be in a random position, so the Answers list needs to be populated * before that.*/ private void Setup() { Answers.Clear(); RandomNumber = Random.Next(0, Cards.Count); Cards = CardDatabase.GetCards(); var NotYet = true; for (var i = 0; i < 4; i++) { RandomNumber = Random.Next(0, Cards.Count); var Card = Cards[RandomNumber]; if (!Card.Answer.Equals(Hand[index].Answer)) { Answers.Add(new AnswerCard(Card, false)); Cards.Remove(Card); } else { Answers.Add(new AnswerCard(Card, true)); Cards.Remove(Card); NotYet = false; } } if (NotYet) { RandomNumber = Random.Next(0, Answers.Count); Answers[RandomNumber] = new AnswerCard(Hand[index], true); } }
public async Task <IActionResult> Edit(int id, [Bind("AnswerCardId,Description,PointValue,DeckId")] AnswerCard answerCard) { if (id != answerCard.AnswerCardId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(answerCard); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnswerCardExists(answerCard.AnswerCardId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DeckId"] = new SelectList(_context.Deck, "DeckId", "Name", answerCard.DeckId); return(View(answerCard)); }
public async Task <int> CreateAnswerCard(CreateAnswerCardModel model) { AnswerCard newCard = MapToEntity(model); context.AnswerCards.Add(newCard); await context.SaveChangesAsync(); return(newCard.AnswerCardId); }
public async Task <IActionResult> Create([Bind("AnswerCardId,Description,PointValue,DeckId")] AnswerCard answerCard) { if (ModelState.IsValid) { _context.Add(answerCard); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DeckId"] = new SelectList(_context.Deck, "DeckId", "Name", answerCard.DeckId); return(View(answerCard)); }
public void ReturnCard(AnswerCard card) { _mustUseCardCount++; if (card.GetDirection() == Direction.LEFT) { _answerBox.DeleteCard(Direction.LEFT); _mustUseLeftCardCount++; } else { _answerBox.DeleteCard(Direction.RIGHT); _mustUseRightCardCount++; } card.gameObject.transform.SetParent(_aCardObjectPool.gameObject.transform); }
public static string DrawFromDeck(int _id, bool _removeFromDeck) { // TODO => Random // If the deck in empty if (AnswerDeck.Count == 0) { if (DiscardPile.Count == 0) { Console.WriteLine("ERROR!! No cards in the deck"); } else { // Put discard pile into card pile foreach (AnswerCard card in DiscardPile) { AnswerDeck.Add(card); } DiscardPile.Clear(); } } // Draw a card AnswerCard newCard = AnswerDeck[0]; AnswerDeck.RemoveAt(0); // Add to a players hand if (PlayerHands.ContainsKey(_id) == false) { PlayerHands.Add(_id, new List <string>()); } PlayerHands[_id].Add(newCard.text); // Return return(newCard.text); }