Ejemplo n.º 1
0
        private CardClass GetClassValue()
        {
            var lastChar = CardName.Substring(CardName.Length - 1, 1).ToUpper();

            if (lastChar == "C")
            {
                return(CardClass.Club);
            }
            else if (lastChar == "S")
            {
                return(CardClass.Spade);
            }
            else if (lastChar == "H")
            {
                return(CardClass.Heart);
            }
            else if (lastChar == "D")
            {
                return(CardClass.Diamond);
            }
            else
            {
                return(CardClass.Joker);
            }
        }
Ejemplo n.º 2
0
        private int GetCardValue()
        {
            var firstChar  = CardName.Substring(0, 1).ToUpper();
            var cardValues = new List <int>()
            {
                12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
            };
            var cardFirstNames = new List <string>()
            {
                "A", "K", "Q", "J", "1", "9", "8", "7", "6", "5", "4", "3", "2"
            };

            var cardValue = (from f in cardFirstNames
                             where f == firstChar
                             select f).FirstOrDefault();

            return(cardValues[cardFirstNames.IndexOf(cardValue)]);
        }
Ejemplo n.º 3
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");
        }