예제 #1
0
        private void LoadSelectedLesson()
        {
            CodeProfiler.Start("LoadLesson");
            Debug.WriteLine("Loading lesson: " + SelectedLesson);
            KillImageLoader();

            string lessonPath = LessonBasePath + SelectedLesson;

            string[] files = Directory.GetFiles(lessonPath);
            Array.Sort(files);

            //Clean up old cards. Dispose Audio object.
            foreach (FlashCardItem ptrItem in Cards)
            {
                ptrItem.Dispose();
            }
            Cards.Clear();
            FlashCardItem newItem;

            //Load and sort cards.
            CodeProfiler.Start("Generate Items");
            string CardName;
            string CardText;
            string CardImageType;

            foreach (string ptrFile in files)
            {
                //Card Format
                //[CardIndex]#<Card Name>.<Image type>
                CardImageType = Path.GetExtension(ptrFile).ToLower();
                if (!IsImageTypeSupported(CardImageType))
                {
                    continue;
                }

                CardName = CardText = Path.GetFileNameWithoutExtension(ptrFile);
                if (CardName.Contains("#"))
                {
                    CardText = CardName.Substring(CardName.IndexOf("#") + 1);
                }
                newItem = new FlashCardItem(CardName, CardText, ptrFile);
                Debug.WriteLine("> " + newItem.Text);
                Cards.Add(newItem);
            }
            CodeProfiler.Stop("Generate Items");

            //Load card contents.
            if (UseThread)
            {
                //Use threading to load images.
                CardsLoader = new Thread(LoadCardsData);
                CardsLoader.Start();
                CodeProfiler.Start("LoadCard1");
                Cards[0].Load(); //Make sure first image is loaded
                CodeProfiler.Stop("LoadCard1");
            }
            else
            {
                //Single thread operation (Slower) - Keep for debugging purpose
                foreach (FlashCardItem ptrItem in Cards)
                {
                    CodeProfiler.Start("Load Card " + ptrItem.Name);
                    ptrItem.Load();
                    CodeProfiler.Stop("Load Card " + ptrItem.Name);
                }
            }

            Cards.ResetIndex();
            CardsLoader.Join();
            OnLessonLoaded();
            Debug.WriteLine("Lesson loaded.");
            CodeProfiler.Stop("LoadLesson");
        }
예제 #2
0
        public void GetNextCard()
        {
            Controller.Busy = true;
            foreach (OptionButton ptrButton in Options)
            {
                ptrButton.Enabled        = true;
                ptrButton.Selected       = false;
                ptrButton.HighlightColor = Color.Red;
            }

            try
            {
                SelectedCard = Controller.GetNextCard();
                if (SelectedCard == null)
                {
                    foreach (OptionButton ptrButton in Options)
                    {
                        ptrButton.Text    = string.Empty;
                        ptrButton.Enabled = false;
                    }

                    //Finished...
                    foreach (OptionButton ptrButton in Options)
                    {
                        ptrButton.Hide();
                    }
                    MainPicture.SizeMode = PictureBoxSizeMode.Zoom; //Override size mode
                    MainPicture.Image    = Image.FromFile(".\\System\\GoodJob.png");
                    return;
                }

                Points             = Options.Length - 1;
                lbCardCounter.Text = Controller.Cards.IndexOf(SelectedCard).ToString() +
                                     " / " + Controller.Cards.Count.ToString();

                MainPicture.Image                   = SelectedCard.Image;
                AnswerIndex                         = rand.Next(Options.Length);
                Options[AnswerIndex].Tag            = SelectedCard;
                Options[AnswerIndex].Text           = SelectedCard.Text.ToUpper();
                Options[AnswerIndex].HighlightColor = Color.Lime;

                List <FlashCardItem> usedCards = new List <FlashCardItem>();
                usedCards.Add(SelectedCard);
                for (int x = 0; x < Options.Length; x++)
                {
                    if (x != AnswerIndex)
                    {
                        FlashCardItem randCard;
                        do
                        {
                            randCard        = Controller.Cards.GetRandomCard();
                            Options[x].Tag  = randCard;
                            Options[x].Text = randCard.Text.ToUpper();
                        } while (usedCards.Contains(randCard));
                        usedCards.Add(randCard);
                    }
                }
                if (SelectedCard.Audio != null)
                {
                    SelectedCard.Audio.PlaySync();
                }
                else
                {
                    Synth.Speak(SelectedCard.Text);
                }
            }
            finally { Controller.Busy = false; }
        }
예제 #3
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; }
        }