그래서 lblScore.Text
및 lblScore.Text = iCorrectACount.ToString();
이라는 레이블이 있습니다. iCorrectACount
은 기본적으로 사용자가 몇 개의 질문에 답을했는지에 대한 카운터입니다. 이제 내가 원하는 것은이 숫자가 선택한 난이도에 따라 최종 점수를 곱하는 것입니다. 즉, 쉬운 질문을 선택하면 iCorrectACount
에 0을 곱해서 문자열로 변환합니다. 보통 질문을 선택하면 iCorrectACount
에 1.5를 곱합니다. 문자열로 변환하고 어려운 질문을 선택하면 iCorrectACount
에 2를 곱해서 문자열로 전송하지만 어떻게 처리해야할지 모르겠습니다.기준에 따라 라벨 값을 변경하는 방법
내 코드는 다음과 같다 :
private void QuizReset()
{
// Resets the difficulty selection control and shows it again upon resetting the quiz
difficultySelectionControl.Reset();
difficultySelectionControl.BringToFront();
// Disabled the 'Next' button and prompts the user to select a difficulty - User cannot continue without choosing
btnNext.Enabled = false;
lblStatus.Text = "Please select a difficulty";
// Sets the number of questions and correct answers to zero
iCorrectACount = 0;
iCurrentQIndex = 0;
}
private void LoadQuestions(Difficulty difficulty)
{
// Defines a random variable to be used to shuffle the order of the questions and answers
var rand = new Random();
// Loads the corresponding XML document with 'Easy', 'Medium' or 'Hard' questions depending on difficulty chosen
var xdoc = XDocument.Load(GetFileNameFor(difficulty));
// List of questions that are filtered from the XML file based on them being wrapped in question tags
_questions = xdoc.Descendants("question")
.Select(q => new Question()
{
ID = (int)q.Attribute("id"),
Difficulty = (int)q.Attribute("difficulty"),
QuestionText = (string)q.Element("text"),
Answers = q.Element("answers")
.Descendants()
// Stores all answers into a string
.Select(a => (string)a)
// Randomizing answers
.OrderBy(a => rand.Next())
.ToArray(),
CorrectAnswer = (string)q.Element("answers")
.Descendants("correctAnswer")
// Use value instead of index
.First()
})
// Selects questions that match the difficulty integer of the option the user chose
.Where(q => q.Difficulty == (int)difficulty + 1)
// Randomizing questions
.OrderBy(q => rand.Next())
.ToList();
lblStatus.Text = String.Format("There are {0} questions in this section", _questions.Count);
}
private string GetFileNameFor(Difficulty difficulty)
{
switch (difficulty)
{
case Difficulty.Easy: return "quiz_easy.xml";
case Difficulty.Medium: return "quiz_medium.xml";
case Difficulty.Hard: return "quiz_hard.xml";
default:
throw new ArgumentException();
}
}
private void PickQuestion()
{
questionControl.DisplayQuestion(_questions[iCurrentQIndex]);
questionControl.BringToFront();
iCurrentQIndex++;
}
private void FormMain_Load(object sender, EventArgs e)
{
QuizReset();
lblScore.Text = "0";
}
private void miNewQuiz_Click(object sender, EventArgs e)
{
QuizReset();
lblScore.Text = "0";
}
private void miExit_Click(object sender, EventArgs e)
{
Close();
}
private void miHelp_Click(object sender, EventArgs e)
{
FormHowToPlay form = new FormHowToPlay();
form.ShowDialog();
}
private void miAbout_Click(object sender, EventArgs e)
{
AboutBox1 aboutForm = new AboutBox1();
aboutForm.ShowDialog();
}
private void btnNext_Click(object sender, EventArgs e)
{
if (iCurrentQIndex < _questions.Count)
{
PickQuestion();
lblStatus.Text = String.Format("Question {0} of {1}", iCurrentQIndex, _questions.Count);
}
else
{
btnNext.Enabled = false;
lblStatus.Text = String.Format("You answered {0} questions correctly out of a possible {1}",
iCorrectACount, _questions.Count);
this.Hide();
SummaryForm sumForm = new SummaryForm();
DialogResult result = sumForm.ShowDialog();
MenuForm mnuform = new MenuForm();
mnuform.ShowDialog();
}
}
private void difficultySelectionControl_DifficultySelected(object sender, DifficultySelectedEventArgs e)
{
iCurrentQIndex = 0;
LoadQuestions(e.Difficulty);
btnNext.Enabled = true;
}
private void questionControl_QuestionAnswered(object sender, QuestionAnsweredEventArgs e)
{
if (e.IsCorrect)
iCorrectACount++;
lblScore.Text = iCorrectACount.ToString();
}
그것은 내가 알아 내야 마지막 작은 일이고 나는 그래서 그것을 얻을하는 방법을 알아낼 수없는 어려움 = 쉬운/중/하드의 경우, iCorrectAmount
에 1/1.5/2/0을 곱하십시오.
도움이나 조언을 주셔서 감사합니다.
예제를 제공해 주시겠습니까? 당신이 의미하는 것이 확실하지 않습니다 (용서하세요) – user2141272
예제를 추가했습니다 –
어떤 클래스 정의에'private difficulty m_difficulty'를 추가합니까? – user2141272