public void Help(object newDesign)
        {
            var numberOfDeletedTexts = 0;
            var controls             = ((Button)newDesign).Parent.Parent.Controls;

            for (var i = 0; i < controls.Count; i++)
            {
                if (controls[i] is Panel panel)
                {
                    foreach (Control c in panel.Controls)
                    {
                        if (!(c is Label label))
                        {
                            continue;
                        }
                        if (label.Name.Contains("answer") &&
                            !GUIGame.IsAnswerCorrect(label.Text) &&
                            numberOfDeletedTexts < 2)
                        {
                            label.Text = "";
                            numberOfDeletedTexts++;
                        }
                    }
                }
            }
        }
Example #2
0
        public void GUIGameTestetObAntwortRichtigIst()
        {
            //Arrange
            GUIGame g = GUIGame.GetInstance();

            g.Solution = "korrekt";
            //Act & Assert
            Assert.IsTrue(GUIGame.IsAnswerCorrect("korrekt"));
            Assert.IsFalse(GUIGame.IsAnswerCorrect("falsch"));
        }
        public void AnswerClick(Label label, VocableGui gui)
        {
            var controls = label?.Parent?.Parent?.Controls;

            if (controls == null)
            {
                throw new ArgumentException(nameof(label));
            }

            var answerLabels = controls
                               .Cast <Control>()
                               .Where(e => e is Panel panel && panel.Name.Equals("pnl_Antworten"))
                               .Cast <Panel>()
                               .SelectMany(e => e.Controls.Cast <Control>())
                               .Where(e => e is Label answerLabel && answerLabel.Name.Contains("answer"))
                               .ToList();

            var correctLabels = answerLabels
                                .Where(e => GUIGame.IsAnswerCorrect(e.Text))
                                .ToList();

            if (correctLabels.Count != 1)
            {
                throw new Exception("Only one answer can be correct");
            }

            if (correctLabels.Any(e => e == label))
            {
                pointsInstance.AnswerIsRight();
            }

            var correctLabel = correctLabels.FirstOrDefault();

            if (correctLabel != null)
            {
                correctLabel.ForeColor = Color.Green;
            }

            var incorrectLabels = answerLabels
                                  .Where(e => !correctLabels.Contains(e));

            foreach (var answerLabel in incorrectLabels)
            {
                answerLabel.ForeColor = Color.Red;
            }
            gui.timer.Interval = 950;
            gui.timer.Start();
        }