/// <summary> /// Reserches and returns the number of the button which should have been clicked according to the context. /// </summary> /// <returns>number of the correct button</returns> private int FindGoodAnswer() { ComponentFocus current = Series[CurrentSeries].Components[CurrentComponent]; ComponentFocus previous = Series[CurrentSeries].Components[PreviousComponent]; if (current.Color == previous.Color && tlpButtons.Contains(buttonSameColor)) { return(tlpButtons.GetRow(buttonSameColor) + 1); } else if (current.DotNumber == previous.DotNumber && tlpButtons.Contains(buttonSameDotNumber)) { return(tlpButtons.GetRow(buttonSameDotNumber) + 1); } else if (current.Shape == previous.Shape && tlpButtons.Contains(buttonSameShape)) { return(tlpButtons.GetRow(buttonSameShape) + 1); } else { return(tlpButtons.GetRow(buttonOther) + 1); } }
/// <summary> /// Checks if the right button was clicked according to the context and increments scores. /// </summary> /// <param name="button">The clicked button.</param> private void CheckAnswer(Button button) { ComponentFocus current = Series[CurrentSeries].Components[CurrentComponent]; ComponentFocus previous = Series[CurrentSeries].Components[PreviousComponent]; bool isRight = false; switch (button.Name) //switch on the button we clicked { case "buttonSameColor": isRight = (current.Color == previous.Color); break; case "buttonSameShape": isRight = (current.Shape == previous.Shape); break; case "buttonSameDotNumber": isRight = (current.DotNumber == previous.DotNumber); break; case "buttonOther": isRight = true; if (tlpButtons.Contains(buttonSameColor)) { if (current.Color == previous.Color) { isRight = false; } } if (tlpButtons.Contains(buttonSameDotNumber)) { if (current.DotNumber == previous.DotNumber) { isRight = false; } } if (tlpButtons.Contains(buttonSameShape)) { if (current.Shape == previous.Shape) { isRight = false; } } break; default: break; } if (isRight) { Score.GoodAnswers++; MessageBox.Show("Bonne réponse !"); } else { int buttonNumber = FindGoodAnswer(); MessageBox.Show("Mauvaise réponse ! Il fallait cliquer sur le bouton " + buttonNumber + "."); } }