Esempio n. 1
0
        public string GetCardLabel(GameRules gameRules)
        {
            var result = CurrentCard.ToString();

            if (gameRules.EnableSuits)
            {
                var limiter = gameRules.DeckSize / 4;
                //var suits = new List<string> { "Spade", "Diamond", "Heart", "Club" };
                for (int i = 0; i < limiter; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        var num = 1 + 4 * i + j;
                        if (CurrentCard == num)
                        {
                            result = $"{i + 1} {gameRules.Suits[j]}";
                            break;
                        }
                    }
                }
            }


            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// RemoveCardImage - Removes a card from a grid
        /// </summary>
        /// <param name="removeFromGrid"></param>
        /// <param name="imageToRemove"></param>
        public void RemoveCardImage(Grid removeFromGrid, Image imageToRemove)
        {
            TurnPlayed = false;
            bool remove = false;

            foreach (Card card in currentPlayer.Cards)
            {
                if (imageToRemove == card.myImage)
                {
                    CurrentCard = card;
                    remove      = true;
                }
            }
            if (remove)
            {
                if (currentPlayer is ComputerPlayer && !CurrentCard.faceUp)
                {
                    CurrentCard.SetFaceUp();
                    imageToRemove = CurrentCard.myImage;
                }
                removeFromGrid.Children.Remove(imageToRemove);
                currentPlayer.Cards.Remove(CurrentCard);

                myGame.UpdatePlayers(currentPlayer);
            }
            cardPlayed = remove;
            OrderCards();
        }
Esempio n. 3
0
 /// <summary>
 /// Updates the current flashcard based on the review verdict
 /// </summary>
 /// <param name="levelUp">Whether the flashcard is moving up a level</param>
 private void UpdateCard(bool levelUp)
 {
     ///note: not final implementation
     //sets the flashcard's last review date and adjusts the flashcard's level accordingly
     CurrentCard.Date  = DateTime.UtcNow;
     CurrentCard.Level = levelUp ? CurrentCard.Level + 1 : 0;
     CurrentCard.Save();
 }
Esempio n. 4
0
 public override void PoolRecycle()
 {
     if (CurrentCard != null)
     {
         CurrentCard.PoolRecycle();
     }
     CurrentCard = null;
     base.PoolRecycle();
 }
Esempio n. 5
0
 private void btn_knewAnswerYES_Click(object sender, EventArgs e)
 {
     //CurrentCard.AddSuccessfulAttempt(Quiz, CurrentCard, true);
     foreach (var card in CurrentCard.GetRequiredAnswerCards(Quiz))
     {
         card.AddSuccessfulAttempt(Quiz, true);
     }
     SetCard();
 }
Esempio n. 6
0
 private void btn_knewAnswerNO_Click(object sender, EventArgs e)
 {
     //CurrentCard.AddFailedAttempt(Quiz, CurrentCard, true, false);
     foreach (var card in CurrentCard.GetRequiredAnswerCards(Quiz))
     {
         card.AddFailedAttempt(Quiz, true, false);
     }
     SetCard();
 }
Esempio n. 7
0
        public bool Answer(TAnswer answer)
        {
            // stop the timer
            // check the answer
            // store the correctness and time with the flashcard for the user.

            CurrentResult.StopTime  = DateTime.Now;
            CurrentResult.Answer    = answer;
            CurrentResult.IsCorrect = CurrentCard.CheckAnswer(answer);
            return(CurrentResult.IsCorrect);
        }
    public void Start()
    {
        IsFirstCard = true;
        instance    = this;

        while (Pile.instance.pile[0].Model.color == "wild")
        {
            Pile.RestockPile();
            Pile.instance.Shuffle();
        }

        GameManager.PlayerIndex--;
        setCurrentCard(Pile.instance.pile[0], true);
        Pile.instance.pile.RemoveAt(0);
        IsFirstCard = false;
        GameManager.PlayerIndex++;
    }
 public void OnEndDrag(PointerEventData eventData)
 {
     GetComponent <CanvasGroup>().blocksRaycasts = true;
     if (IsDraggable)
     {
         Destroy(placeholder);
         RaycastResult rr = eventData.pointerCurrentRaycast;
         if (rr.isValid && rr.gameObject.tag == "CurrentCard" && controller.CanBePlayed())
         {
             CurrentCard.setCurrentCard(gameObject);
             GameManager.CheckVictoryCondition();
         }
         else
         {
             ReturnCard();
         }
     }
 }
Esempio n. 10
0
        private void llb_overrideIwasRight_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!userCopyingAnswer)
            {
                return;
            }

            foreach (var card in CurrentCard.GetRequiredAnswerCards(Quiz))
            {
                var answerAttempts = card.GetProgressData(Quiz).AnswerAttempts;
                answerAttempts.RemoveAt(answerAttempts.Count - 1);  // Remove last answer attempt
#warning Success attempt is not added to the end of the list, but one index before ?
                card.AddSuccessfulAttempt(Quiz, true);
            }
            SetCard();

            lbl_cardSideToAnswer.Focus();  // Needed for KeyPress() event to be triggered when it should
        }
Esempio n. 11
0
 private void btn_save_Click(object sender, EventArgs e)
 {
     if (txt_filename.Text.Trim().Length == 0)
     {
         MessageBox.Show("You must supply a filename!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         CurrentCard.Filename = $"{txt_filename.Text}.fler";
         if (!File.Exists(Path.Combine(CARD_DIR, CurrentCard.Filename)) || MessageBox.Show("A card with this filename already exists! Do you want to overwrite it?", "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
         {
             CurrentCard.Save();
             CurrentCard.PurgeImageCache();
             Cards[CurrentCard.Filename] = CurrentCard;
             GoBack(null, null);
         }
     }
 }
Esempio n. 12
0
        public void OpenCard(string buttonName)
        {
            var nextCard = buttonsCollection.GetCustomButtonByName(buttonName);

            if (!WaitNextMove && nextCard != FirstCard)
            {
                RoundWin = false;

                CurrentCard = buttonsCollection.GetCustomButtonByName(buttonName);

                MovesCount++;

                if (MovesCount > 1)
                {
                    SecondCard = CurrentCard;
                }
                else
                {
                    FirstCard = CurrentCard;
                }

                if (IsGameStarted && CurrentCard.Closed)
                {
                    SoundPlayer.PlayButtonSound();
                    CurrentCard.ShowImage();

                    if (MovesCount == 2)
                    {
                        WaitNextMove = true;
                        var successMove = Result();
                        UpdateScore();
                        DelayAndClose(successMove);
                    }
                }
            }
            else
            {
                SoundPlayer.PlayCannotOpenCardSound();
            }
        }
Esempio n. 13
0
        private void labelX12_Click(object sender, EventArgs e)
        {
            if (CurrentCard == null)
            {
                return;
            }

            if (labelX12.Text == "查看调整")
            {
                panelEx1.Text = CurrentCard.adjust;
                labelX10.Text = "复制调整";
                labelX12.Text = "查看说明";
                HideColoredCardName();
            }
            else
            {
                panelEx1.Text = CurrentCard.GetAllInfo();
                labelX10.Text = "复制说明";
                labelX12.Text = "查看调整";
                ShowColoredCardName();
            }
        }
Esempio n. 14
0
        private void lbl_cardSideToAnswer_Click(object sender, EventArgs e)
        {
            if (PractiseMode != QuizPractiseMode.Flashcards)
            {
                return;
            }

            if (newRoundPending)
            {
                return;
            }

            foreach (var c in lbl_cardSideToAsk.Controls.OfType <CorrectAnswer>())
            {
                lbl_cardSideToAsk.Controls.Remove(c);
                c.Dispose();
            }
            foreach (var c in lbl_cardSideToAsk.Controls.OfType <WrongAnswer>())
            {
                lbl_cardSideToAsk.Controls.Remove(c);
                c.Dispose();
            }
            foreach (var c in lbl_cardSideToAsk.Controls.OfType <RoundCompleted>())
            {
                lbl_cardSideToAsk.Controls.Remove(c);
                c.Dispose();
            }

            if (newCardPending)
            {
                SetCard();

                return;
            }

            //lbl_cardSideToAnswer.Text = CurrentCard.GetSideToAnswer(Quiz);
            lbl_cardSideToAnswer.Text = CurrentCard.GetAllAnswers(Quiz);
            pnl_knewAnswer.Visible    = true;
        }
Esempio n. 15
0
 //bindet to Start button
 public void StartAnsweringMethod()
 {
     if (!topicQuestioningStarted)
     {
         Topic.StartQuestioning();
         topicQuestioningStarted = true;
     }
     while (!CheckForLearning(CurrentCard))
     {
         if (IndexCard < Topic.Count - 1)
         {
             CurrentCard.FinishAnswer(false);
             IndexCard++;
         }
         else
         {
             return;
         }
     }
     CurrentCard.StartAnswering();
     OpenLearningCardPanelMethod(OpenLearningCardPanelMessage.QUESTION_PANEL);
     HasStarted = false;
 }
Esempio n. 16
0
        public void LearningCardMethod(bool answer)
        {
            CurrentCard.FinishAnswer(answer);
            if (answer)
            {
                TrueAnswers++;
            }

            if (Topic.Count - 1 == IndexCard && learnRounds == 1)
            {
                OpenLearningCardPanelMethod(OpenLearningCardPanelMessage.FINISH_PANEL);
            }
            else if (Topic.Count - 1 == IndexCard)
            {
                learnRounds--;
                IndexCard = 0;
                StartAnsweringMethod();
            }
            else
            {
                IndexCard++;
                StartAnsweringMethod();
            }
        }
Esempio n. 17
0
    /*
     * @name    OnMouseOver
     * @purpose When the mouse is hovering over the collider the card is assiged to the correct placement
     *
     * @return  Void
     */
    private void OnMouseOver()
    {
        if (CurrentCard != null)
        {
            if (CurrentCard.CType == "Region" && gameObject.name == "Region Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.RegionGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Regionz;
                Regionz++;
            }
            else if (CurrentCard.CType == "Condition" && gameObject.name == "Condition Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.ConditionGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Conditionz;
                Conditionz++;
            }
            else if (CurrentCard.CType == "Plant" && gameObject.name == "Plant Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.PlantGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Plantz;
                Plantz++;
            }
            else if (CurrentCard.CType == "Invertebrate" && gameObject.name == "Invertebrate Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.InvertebrateGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Invertebratez;
                Invertebratez++;
            }
            else if (CurrentCard.CType == "Animal" && gameObject.name == "Animal Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.AnimalGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Animalz;
                Animalz++;
            }
            else if (CurrentCard.CType == "Special Region" && gameObject.name == "Special Region Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.SpecialRegionGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Specialz;
                Specialz++;
            }
            else if (CurrentCard.CType == "Multi-Player" && gameObject.name == "Multiplayer Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.MultiplayerGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Multiz;
                Multiz++;
            }
            else if (CurrentCard.CType == "Human" && gameObject.name == "Human Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.HumanGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Humanz;
                Humanz++;
            }
            else if (CurrentCard.CType == "Microbe" && gameObject.name == "Microbe Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.MicrobeGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Microbez;
                Microbez++;
            }
            else if (CurrentCard.CType == "Fungi" && gameObject.name == "Fungi Card Placement")
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.FungiGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Fungiz;
                Fungiz++;
            }
            else if (gameObject.name == "Discard Pile Placement" && GameManager.Instance.Person.CardDiscarded == false)
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.DiscardGameObject).transform;

                //changes the sorting layer so the next prite is on top
                CurrentCard.GetComponent <SpriteRenderer>().sortingOrder = Discardz;
                Discardz++;
            }

            //if there is no gameobject or something did not work right the card goes back to the hand
            else if (gameObject.name == null)
            {
                CurrentCard.ParentReturn = GameObject.Find(GameManager.Instance.Person.HandGameObject).transform;
            }
        }
    }
Esempio n. 18
0
        private void ResolveOnWhoPlayedCard(Player OnWhoPlr)
        {
            switch (CurrentCard.ToString())
            {
            case "TargetAttack": GoToNextPlayer(OnWhoPlr);
                break;

            case "Blank":
            {
                switch (_test_blank)
                {
                case BlankResults.Double:
                {
                    ItsGiving = true;
                    GoToNextPlayer(OnWhoPlr);
                    for (byte b = 0; b < playerboxes.Length; b++)
                    {
                        playerboxes[b].Image = Properties.Resources.back;
                    }
                    label1.Text = $"Гравець в якого витягують карту {CurrentPlayer.Name}";
                }
                break;

                case BlankResults.Triple:
                {
                    if (comboBox1.Text == String.Empty || comboBox2.Text == String.Empty)
                    {
                        MessageBox.Show("Ви не обрали!");
                        return;
                    }
                    for (byte i = 0; i < OnWhoPlr.Cards.Count; i++)
                    {
                        if (OnWhoPlr.Cards[i].ToString() == comboBox2.Text)
                        {
                            CurrentPlayer.Cards.Add(OnWhoPlr.GiveCard(i));
                            break;
                        }
                    }
                }
                break;

                case BlankResults.FiveCards:
                {
                    pictureBox12.Cursor = Cursors.Hand;
                    infoLabel.Text      = "Оберіть карту з відбою!";
                    swap_i = 1;
                }
                break;
                }
            }
            break;

            case "Favor":
            {
                ch.privius_plr = CurrentPlayer;
                GoToNextPlayer(OnWhoPlr);
                ItsGiving   = true;
                label2.Text = $"Оберіть карту для гравця {ch.privius_plr.Name}";
            }
            break;
            }
        }
    /// <summary>
    /// Check the state of all cards and trigger any needed events
    /// </summary>
    private void CheckTheRules()
    {
        CheckRulesNextUpdate = false;

        switch (myGameMode)
        {
        case GameMode.DefaultTowerRules:            // Inspired by one of my favorite card games, Fortunes Tower from Fable 2 - <3

            GameObject[] gObjs = FindObjectsOfType <GameObject>();

            //Get all card objs
            var allCards = from GameObject g in gObjs
                           where   g.GetComponent <CardBehavior>() != null
                           orderby g.GetComponent <CardBehavior>().Index
                           select g;

            //-------------------------------------------------------------------------------------------------------------------------//
            // DA RULES                             -----------------------------------------------------------------------------------//
            //-------------------------------------------------------------------------------------------------------------------------//

            // ------------------
            // RULE 1 : DEFENDERS
            // ------------------

            // Check for Trigger Card to add Player "Defender" (blocks attacks)
            if (CurrentCard.name.ToLower().Contains("king"))
            {
                if (PlayerPerks.ContainsKey(DEFENDER))          //Increment the defender count
                {
                    int newValue = PlayerPerks[DEFENDER];
                    newValue++;
                    PlayerPerks[DEFENDER] = newValue;
                    UpdateBanner("You now have " + PlayerPerks[DEFENDER] + " Defenders!", Color.yellow);
                }
                else
                {
                    PlayerPerks.Add(DEFENDER, 1);               //Set the defender count to one
                    UpdateBanner("You now have a Defender!", Color.yellow);
                }
            }

            // ---------------------
            // RULE 2 : NUMBER MATCH
            // ---------------------

            // Build list of adjacent cards from adjacent indexes
            List <int>        adjacentCardIndexes = TowerRules.getAdjacentIndexes(CurrentCard.GetComponent <CardBehavior>().Index);
            List <GameObject> adjacentCards       = new List <GameObject>();
            foreach (int i in adjacentCardIndexes)
            {
                GameObject adjCard = allCards.FirstOrDefault(g => g.GetComponent <CardBehavior>().Index == i);

                if (adjCard != null)
                {
                    adjacentCards.Add(adjCard);
                }
            }

            // Check if the adjacent card number matches the current card number
            int CurrentCardNum = GetNumberFromCardName(CurrentCard.name);

            List <GameObject> matchingCards = adjacentCards.Where(g => GetNumberFromCardName(g.name) == CurrentCardNum).ToList();
            bool cardMatch = matchingCards.Any();

            if (cardMatch)
            {
                // If the player has a defender, block the attack
                int defenders = 0;
                PlayerPerks.TryGetValue(DEFENDER, out defenders);
                if (PlayerPerks.ContainsKey(DEFENDER) && defenders > 0)
                {
                    PlayerPerks[DEFENDER] = defenders - 1;
                    UpdateBanner("Defender Blocked You!" + NL +
                                 PlayerPerks[DEFENDER] + " Defenders left.", Color.white);
                }
                else     // Otherwise take damage
                {
                    SpawnAnimatedWeaponOnTarget(CurrentCard);
                    DecrementScore(300);
                    UpdateBanner("Ouch!", Color.red);
                }
            }

            // ------------------------
            // RULE 3 : STOLE TREASURE!
            // ------------------------

            //If there were no matching cards above, play coin effect and add points
            if (!cardMatch)
            {
                CoinSoundEffectPlayer.SelectNewClip();
                CoinSoundEffectPlayer.Play();
                UpdateBanner("You got 150 coins!", Color.yellow);
                IncrementScore(150);
                PlayParticleEffect(CurrentCard);
            }

            //-------------------------------------------------------------------------------------------------------------------------//
            // END OF DA RULES <3                   -----------------------------------------------------------------------------------//
            //-------------------------------------------------------------------------------------------------------------------------//

            break;

        case GameMode.KilledByRoyalty:

            if (CurrentCard.name.ToLower().Contains("king") ||
                CurrentCard.name.ToLower().Contains("queen") ||
                CurrentCard.name.ToLower().Contains("jack"))
            {
                SpawnAnimatedWeaponOnTarget(CurrentCard);

                //Subtract from score
                int axeScoreDamage = 300;
                DecrementScore(axeScoreDamage);
            }
            else
            {
                IncrementScore(100);
                PlayParticleEffect(CurrentCard);
            }
            break;
        }
        return;
    }
Esempio n. 20
0
        public string BotsChoice(List <Card> UserPlayedCards)
        {
            int strongCard = 0;
            int mediumCard = 0;
            int weakCard   = 0;

            for (int i = 0; i < UserPlayedCards.Count; i++)
            {
                if (UserPlayedCards[i].GetAttributeRank("Power") == 1)
                {
                    weakCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Power") == 2)
                {
                    mediumCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Power") == 3)
                {
                    strongCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Cunning") == 1)
                {
                    weakCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Cunning") == 2)
                {
                    mediumCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Cunning") == 3)
                {
                    strongCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Intelligence") == 1)
                {
                    weakCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Intelligence") == 2)
                {
                    mediumCard++;
                }
                if (UserPlayedCards[i].GetAttributeRank("Intelligence") == 3)
                {
                    strongCard++;
                }
            }
            int CardRank = 0;

            if ((strongCard == mediumCard) && (strongCard == weakCard))
            {
                CardRank = 0;
            }
            else
            {
                if (strongCard < mediumCard)
                {
                    if (strongCard < weakCard)
                    {
                        CardRank = 3;
                    }
                    else
                    {
                        CardRank = 1;
                    }
                }
                else
                {
                    if (mediumCard < weakCard)
                    {
                        CardRank = 2;
                    }
                    else
                    {
                        CardRank = 1;
                    }
                }
            }
            string selectedAttribute = "Power";

            if (CardRank == 0)
            {
                int Power        = CurrentCard.Power - ((CurrentCard.GetAttributeRank("Power") - 1) * 5);
                int Cunning      = CurrentCard.Cunning - ((CurrentCard.GetAttributeRank("Cunning") - 1) * 5);
                int Intelligence = CurrentCard.Intelligence - ((CurrentCard.GetAttributeRank("Intelligence") - 1) * 5);
                if (Power > Cunning)
                {
                    if (Power > Intelligence)
                    {
                        selectedAttribute = "Power";
                    }
                    else
                    {
                        selectedAttribute = "Intelligence";
                    }
                }
                else
                {
                    if (Cunning > Intelligence)
                    {
                        selectedAttribute = "Cunning";
                    }
                    else
                    {
                        selectedAttribute = "Intelligence";
                    }
                }
            }
            else
            {
                if (CardRank == 1)
                {
                    if (CurrentCard.GetAttributeRank("Power") == 2)
                    {
                        selectedAttribute = "Power";
                    }
                    else if (CurrentCard.GetAttributeRank("Cunning") == 2)
                    {
                        selectedAttribute = "Cunning";
                    }
                    else //////////////можна ускладнити
                    {
                        selectedAttribute = "Intelligence";
                    }
                }
                if (CardRank == 2)
                {
                    if (CurrentCard.GetAttributeRank("Power") == 3)
                    {
                        selectedAttribute = "Power";
                    }
                    else if (CurrentCard.GetAttributeRank("Cunning") == 3)
                    {
                        selectedAttribute = "Cunning";
                    }
                    else //////////////можна ускладнити
                    {
                        selectedAttribute = "Intelligence";
                    }
                }
                if (CardRank == 3)
                {
                    if (CurrentCard.GetAttributeRank("Power") == 1)
                    {
                        selectedAttribute = "Power";
                    }
                    else if (CurrentCard.GetAttributeRank("Cunning") == 1)
                    {
                        selectedAttribute = "Cunning";
                    }
                    else //////////////можна ускладнити
                    {
                        selectedAttribute = "Intelligence";
                    }
                }
            }
            return(selectedAttribute);
        }
Esempio n. 21
0
 /// <summary>
 /// Finds if multiple answers are required to be provided to this card.
 /// </summary>
 /// <returns>True if multiple answers must be provided; otherwise False.</returns>
 private bool IsCurrentCardMultiAnswer()
 {
     return(CurrentCard.GetRequiredAnswerCards(Quiz).Count() > 1);
 }
Esempio n. 22
0
        private void InQuiz_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (PractiseMode != QuizPractiseMode.Writing)
            {
                return;
            }

            if (e.KeyChar == '\u001b')
            {
                // ignore ESC
                return;
            }

            if (e.KeyChar == '\b')
            {
                // BACKSPACE
                if (!newCardPending && !newRoundPending && CurrentInput.Length > 0)
                {
                    CurrentInput = CurrentInput.Remove(CurrentInput.Length - 1);
                }
            }
            else if (e.KeyChar == '\r')
            {
                // ENTER

                e.Handled = true;

                foreach (var c in lbl_cardSideToAsk.Controls.OfType <CorrectAnswer>())
                {
                    lbl_cardSideToAsk.Controls.Remove(c);
                    c.Dispose();
                }
                foreach (var c in lbl_cardSideToAsk.Controls.OfType <WrongAnswer>())
                {
                    lbl_cardSideToAsk.Controls.Remove(c);
                    c.Dispose();
                }
                foreach (var c in lbl_cardSideToAsk.Controls.OfType <RoundCompleted>())
                {
                    lbl_cardSideToAsk.Controls.Remove(c);
                    c.Dispose();
                }

                if (newRoundPending)
                {
                    SetCard();

                    return;
                }

                if (newCardPending)
                {
                    SetCard();

                    return;
                }

                // Check answer
                var chk = CurrentCard.WrittenAnswerCheck(Quiz, CurrentInput, CurrentCard.MultiAnswersAlreadyEntered(Quiz), !userCopyingAnswer);
                if (chk.IsCorrect())
                {
                    newCardPending = true;
                    llb_overrideIwasRight.Visible = false;
                    var correctAnswer = new CorrectAnswer(CurrentCard, Quiz, chk.Certainty);
                    lbl_cardSideToAsk.Controls.Add(correctAnswer);
                    correctAnswer.Show();

                    CurrentCard = CardPicker.GenerateCard(Quiz); // Generate new card now so that it will be shown on next instance if the user stops practising now
                    lbl_cardSideToAnswer.Text = CurrentInput;
                }
                else
                {
                    llb_overrideIwasRight.Visible = true;
                    userCopyingAnswer             = true;
                    var wrongAnswer = new WrongAnswer(CurrentCard, Quiz);
                    lbl_cardSideToAsk.Controls.Add(wrongAnswer);
                    wrongAnswer.Show();

                    // Check if the user answered another card
                    var answeredCards = new List <Card>();
                    foreach (var card in Quiz.Cards)
                    {
                        var testCheck = card.WrittenAnswerCheck(Quiz, CurrentInput, null, false, false);
                        if (testCheck.IsCorrect())
                        {
                            answeredCards.Add(card);
                        }
                    }

                    if (answeredCards.Count > 0)
                    {
                        MessageBox.Show($"Your answer is wrong to the current card, but correct to other(s):\r\n\r\n" +
                                        string.Join("\r\n", answeredCards.Select(x => x.GetSideToAsk(Quiz))),
                                        "You answered other card(s)", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    CurrentInput = "";
                }
            }
            else if (!newCardPending && !newRoundPending)
            {
                if (cardSideAnswerPromptBeingShown)
                {
                    lbl_cardSideToAnswer.Text      = "";
                    cardSideAnswerPromptBeingShown = false;
                }

                CurrentInput += e.KeyChar;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Generates a card to be shown - or shows the last one from the previous session if it hadn't been answered.
        /// </summary>
        public void SetCard()
        {
            newRoundPending   = false;
            newCardPending    = false;
            userCopyingAnswer = false;

            foreach (var c in lbl_cardSideToAsk.Controls.OfType <CorrectAnswer>())
            {
                lbl_cardSideToAsk.Controls.Remove(c);
                c.Dispose();
            }
            foreach (var c in lbl_cardSideToAsk.Controls.OfType <WrongAnswer>())
            {
                lbl_cardSideToAsk.Controls.Remove(c);
                c.Dispose();
            }
            foreach (var c in lbl_cardSideToAsk.Controls.OfType <RoundCompleted>())
            {
                lbl_cardSideToAsk.Controls.Remove(c);
                c.Dispose();
            }
            foreach (var c in lbl_cardSideToAnswer.Controls.OfType <MultiAnswer>())
            {
                lbl_cardSideToAnswer.Controls.Remove(c);
                c.Dispose();
            }

            llb_overrideIwasRight.Visible = false;
            pnl_knewAnswer.Visible        = false;

            CurrentInput = "";

            CurrentCard = CardPicker.GenerateCard(Quiz);
            if (CurrentCard == null)
            {
                // Round completed

                var roundCompleted = new RoundCompleted(Quiz, PractiseMode, this);
                lbl_cardSideToAsk.Controls.Add(roundCompleted);
                roundCompleted.Show();
                CardPicker.NewRound(Quiz);
                lbl_cardSideToAnswer.Text = "";
                newRoundPending           = true;

                return;
            }

            if (PractiseMode == QuizPractiseMode.Writing)
            {
                if (!IsCurrentCardMultiAnswer())
                {
                    lbl_cardSideToAnswer.Text = "Enter your answer ...";
                }
                else
                {
                    // Multi Answer Card
                    var multiAns = new MultiAnswer();
                    lbl_cardSideToAnswer.Text = "";
                    foreach (var card in CurrentCard.MultiAnswersAlreadyEntered(Quiz))
                    {
                        multiAns.CurrentLabel.Text = card.GetSideToAnswer(Quiz);
                        multiAns.CurrentLabel.Clone();
                    }
                    multiAns.CurrentLabel.Text = "Enter your answers ...";
                    lbl_cardSideToAnswer.Controls.Add(multiAns);
                }
            }
            else
            {
                lbl_cardSideToAnswer.Text = "Click here to reveal";
            }
            cardSideAnswerPromptBeingShown = true;


            if (Quiz.ProgressData.GetLearningProgress() == 1.0)
            {
                if (!Quiz.ProgressData.MasterNoticeShowed)
                {
                    MessageBox.Show("Congratulations! It seems you have learned the whole quiz! Practise until you feel confident - then start a full test, through the " +
                                    "quiz config menu, by clicking the gear button in the bottom right corner", "Quiz Mastered!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Quiz.ProgressData.MasterNoticeShowed = true;
                }
            }
        }