// gets datatable from DB and fills collection with UNUSED single jeopardy categories public void FillCategories() { // get list of #'s of unused categories List<int> iIDs = DBAccess.UnusedCategoryList(); // remove if too many Random rand = new Random(); while (iIDs.Count > 6) { iIDs.RemoveAt(rand.Next(0, iIDs.Count - 1)); } rand = null; // biuld string of id's for sql string sIDs = ""; foreach (int i in iIDs) { sIDs += string.Format("{0}, ", i); } sIDs = sIDs.Remove(sIDs.Length - 2); // get datatable DataTable dtCategory = DBAccess.GetCategory(sIDs); foreach (DataRow dr in dtCategory.Rows) { cCategory oCategory = new cCategory(); oCategory.Load(dr); this.Add(oCategory); } }
// add given cCategory to collection private void Add(cCategory newCategory) { mcol.Add(newCategory); }
private void Button_Clicked(object sender, EventArgs e) { if (sender is Button) { Button btnQuestion = (Button)sender; string sQuestion = btnQuestion.Name; sQuestion = sQuestion.Remove(0, 3); //MessageBox.Show(sQuestion); // get category of selected question switch (sQuestion[0]) { case 'A': oCategory = oCategories[0]; break; case 'B': oCategory = oCategories[1]; break; case 'C': oCategory = oCategories[2]; break; case 'D': oCategory = oCategories[3]; break; case 'E': oCategory = oCategories[4]; break; case 'F': oCategory = oCategories[5]; break; } int iQuestID; int.TryParse(sQuestion.Remove(0, 1), out iQuestID); int iCost; // check for daily double if (sQuestion == sDailyDouble) { // is daily double frmBetQuestion oBetQuestionForm = new frmBetQuestion(oCategories[char.ConvertToUtf32(sQuestion, 0) - 65].Description, oCategory[iQuestID - 1], iScore, false); oBetQuestionForm.ShowDialog(); iCost = oBetQuestionForm.Bet; } else { iCost = oCategory[iQuestID - 1].Cost; } frmQuestion oQuestionForm = new frmQuestion(oCategory[iQuestID - 1], false); oQuestionForm.ShowDialog(); // manage score if (oQuestionForm.AnswerState == 0) { // didnt answer string sAnswerDescription = oCategory[iQuestID - 1][oCategory[iQuestID - 1].CorrectAnswerID].Description; lblLastQuestion.Text = string.Format("Passed, answer was: {0}", sAnswerDescription); } else if (oQuestionForm.AnswerState == 1) { // answer good iScore += iCost; string sAnswerDescription = oCategory[iQuestID - 1][oCategory[iQuestID - 1].CorrectAnswerID].Description; lblLastQuestion.Text = string.Format("{0} is Correct!", sAnswerDescription); } else { // bad answer iScore -= iCost; string sAnswerDescription = oCategory[iQuestID - 1][oCategory[iQuestID - 1].CorrectAnswerID].Description; lblLastQuestion.Text = string.Format("Incorrect, answer was: {0}", sAnswerDescription); } lblScore.Text = string.Format("Score: {0}", iScore); btnQuestion.Enabled = false; if (CheckForEnd()) { // all questions used, final jeopardy oCategory = new cCategory(); oCategory.FillFinal(); oCategory.FillCategory(); frmBetQuestion oFinalQuestionForm = new frmBetQuestion(oCategory.Description, oCategory[0], iScore, true); oFinalQuestionForm.ShowDialog(); iCost = oFinalQuestionForm.Bet; oQuestionForm = new frmQuestion(oCategory[0], true); oQuestionForm.ShowDialog(); // manage score if (oQuestionForm.AnswerState == 0) { // didnt answer string sAnswerDescription = oCategory[iQuestID - 1][oCategory[iQuestID - 1].CorrectAnswerID].Description; lblLastQuestion.Text = string.Format("Passed, answer was: {0}", sAnswerDescription); } else if (oQuestionForm.AnswerState == 1) { // answer good iScore += iCost; string sAnswerDescription = oCategory[iQuestID - 1][oCategory[iQuestID - 1].CorrectAnswerID].Description; lblLastQuestion.Text = string.Format("{0} is Correct!", sAnswerDescription); } else { // bad answer iScore -= iCost; string sAnswerDescription = oCategory[iQuestID - 1][oCategory[iQuestID - 1].CorrectAnswerID].Description; lblLastQuestion.Text = string.Format("Incorrect, answer was: {0}", sAnswerDescription); } lblScore.Text = string.Format("Score: {0}", iScore); } } }