예제 #1
0
        public void GetNextCard()
        {
            try
            {
                //Stop hint timer
                #region [ Spelling Mode ]
                if (Controller.Mode == FlashCardMode.Spelling)
                {
                    hintTimer.Enabled = false;
                    Debug.WriteLine("Timer Suspended");
                }
                #endregion

                Controller.Busy = true;
                SelectedCard    = Controller.GetNextCard();
                if (SelectedCard != null)
                {
                    CodeProfiler.Start("GetNextCard-LoadCard");
                    lbCardCounter.Text = Controller.Cards.IndexOf(SelectedCard).ToString() +
                                         " / " + Controller.Cards.Count.ToString();

                    MainPicture.Image = SelectedCard.Image;

                    //In Spelling mode, spell each characters
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        CardLabel.Text = String.Empty;
                        Cursor         = Cursors.WaitCursor;
                        if (SelectedCard.Audio != null)
                        {
                            SelectedCard.Audio.PlaySync();
                        }
                        else
                        {
                            Synth.Speak(SelectedCard.Text);
                        }

                        foreach (char ptrChar in SelectedCard.Text)
                        {
                            Controller.PlayCharSoundSync(ptrChar);
                        }
                        hintTimer.Interval = Controller.SpellingModeHintIntervalInitial;
                        Cursor             = Cursors.Default;
                    }
                    #endregion

                    if (Controller.CaseSensitive)
                    {
                        CardLabel.Text = SelectedCard.Text;
                        ExpectedText   = CardLabel.Text;
                        CurrentIndex   = 0;
                    }
                    else
                    {
                        CardLabel.Text = SelectedCard.Text.ToUpper();
                        ExpectedText   = CardLabel.Text;
                        CurrentIndex   = 0;
                    }

                    //Create puzzle hint
                    #region [ Puzzle Mode Only ]
                    if (Controller.Mode == FlashCardMode.Puzzle)
                    {
                        PuzzleHint.Text = CardLabel.Text;
                        PuzzleHint.Shuffle();
                        for (int x = 0; x < PuzzleHint.Text.Length; x++)
                        {
                            PuzzleHint.HighlightChar(x);
                        }
                    }
                    #endregion

                    MainPicture.Refresh();
                    CardLabel.Refresh();
                    CodeProfiler.Stop("GetNextCard-LoadCard");

                    //Read selected card
                    if (SelectedCard.Audio != null)
                    {
                        SelectedCard.Audio.PlaySync();
                    }
                    else
                    {
                        Synth.Speak(SelectedCard.Text);
                    }

                    //Start hint timer
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        hintTimer.Enabled = Controller.SpellingModePlayHint;
                    }
                    Debug.WriteLine("Timer Enabled");
                    #endregion
                }
            }
            finally { Controller.Busy = false; }
        }
예제 #2
0
        public void KeyPressed(object sender, char key)
        {
            if (Controller.Busy)
            {
                return;                  //Stop responding to key press when controller is busy, e.g Loading card.
            }
            try
            {
                Controller.Busy = true;
                if (SelectedCard == null)
                {
                    return;
                }

                if (!Controller.CaseSensitive)
                {
                    key = char.ToUpper(key);
                }
                if (key == ExpectedText[CurrentIndex])
                {
                    //Character Matched

                    //Stop hint timer
                    #region [ Spelling Mode Only ]
                    if (Controller.Mode == FlashCardMode.Spelling)
                    {
                        hintTimer.Enabled = false;
                        Debug.WriteLine("Timer Suspended");
                    }
                    #endregion

                    //Remove selected character from puzzle hint
                    #region [ Puzzle Mode Only ]
                    if (Controller.Mode == FlashCardMode.Puzzle)
                    {
                        int keyIndex = PuzzleHint.Text.IndexOf(key);
                        PuzzleHint.HideChar(keyIndex);
                    }
                    #endregion

                    CardLabel.HighlightChar(CurrentIndex);
                    CurrentIndex++;
                    Application.DoEvents();

                    //Is End of Word
                    if (CurrentIndex == ExpectedText.Length)
                    {
                        //Spell Character
                        #region [ Vocabulary and Puzzle Mode Only ]
                        if ((Controller.Mode == FlashCardMode.Vocabulary) ||
                            (Controller.Mode == FlashCardMode.Puzzle))
                        {
                            Controller.PlayCharSoundSync(key);
                        }
                        #endregion

                        //Word matched.
                        if (Stars.Count == Stars.Value)
                        {
                            Stars.Value = 1;
                        }
                        else
                        {
                            Stars.Value++;
                        }

                        Score++;
                        LbScore.Text = Score.ToString();
                        //Read word for current card
                        Thread.Sleep(200);
                        if (SelectedCard.Audio != null)
                        {
                            SelectedCard.Audio.PlaySync();
                        }
                        else
                        {
                            Synth.Speak(SelectedCard.Text);
                        }
                        Thread.Sleep(1000);

                        GetNextCard();
                        if (SelectedCard == null)
                        {
                            //Finished...
                            CardLabel.Text       = String.Empty;
                            MainPicture.SizeMode = PictureBoxSizeMode.Zoom; //Override size mode
                            MainPicture.Image    = Image.FromFile(".\\System\\GoodJob.png");
                        }
                    }
                    else
                    {
                        switch (Controller.Mode)
                        {
                        case FlashCardMode.Vocabulary:
                            Controller.PlayCharSound(key);
                            break;

                        case FlashCardMode.Puzzle:
                            Controller.PlayCharSound(key);
                            break;

                        case FlashCardMode.Spelling:
                            hintTimer.Interval = Controller.SpellingModeHintIntervalInitial;
                            hintTimer.Enabled  = Controller.SpellingModePlayHint;
                            Debug.WriteLine("Timer Enabled");
                            break;
                        }
                    }
                }
            }
            finally { Controller.Busy = false; }
        }