public void Setup() { Question q1 = new Question(); q1.Text = "Question One"; q1.Responses = 100; q1.Answers.Add(new Answer("answer 1-1", 50)); q1.Answers.Add(new Answer("answer 1-2", 25)); q1.Answers.Add(new Answer("answer 1-3", 25)); Question q2 = new Question(); q2.Text = "Question The second"; q2.Responses = 95; q2.Answers.Add(new Answer("answer 2-1", 50)); q2.Answers.Add(new Answer("answer 2-2", 25)); q2.Answers.Add(new Answer("answer 2-3", 20)); Question q3 = new Question(); q3.Text = "Question Three"; q3.Responses = 86; q3.Answers.Add(new Answer("answer 3-1", 20)); q3.Answers.Add(new Answer("answer 3-2", 26)); q3.Answers.Add(new Answer("answer 3-3", 40)); QuestionCollection questions = new QuestionCollection(); questions.Add(q1); questions.Add(q2); questions.Add(q3); this.game = new SimpleGame(questions); }
public void Setup() { this.questions = new QuestionCollection(); this.simpleQuestion = new Question(); this.simpleQuestion.Text = "Sample Question"; this.simpleQuestion.Responses = 100; this.simpleQuestion.Answers.Add(new Answer("answer 1", 25)); this.simpleQuestion.Answers.Add(new Answer("answer 2", 50)); this.simpleQuestion.Answers.Add(new Answer("answer 3", 25)); this.filename = @"c:\questions.game"; this.DeleteFile(this.filename); }
private void btnAdd_Click(object sender, System.EventArgs e) { Question q = new Question(); q.Text = this.txtQuestion.Text; for (int i = 0; i < this.txtAnswers.Lines.Length; i++) { if (this.txtAnswers.Lines[i] != "") { string[] line = this.txtAnswers.Lines[i].Split('|'); Answer a = new Answer(line[0], Int32.Parse(line[1])); q.Answers.Add(a); } } this.questions.Add(q); this.listQuestions.Items.Add(q.Text); this.txtAnswers.Clear(); this.txtQuestion.Clear(); this.txtQuestion.Focus(); }
public override int IndexOf(Question x) { return m_collection.IndexOf(x); }
public override void CopyTo(Question[] array) { m_collection.CopyTo(array); }
public override void CopyTo(Question[] array, int start) { m_collection.CopyTo(array,start); }
/// <summary> /// Adds a <see cref="Question"/> to the end of the <c>QuestionCollection</c>. /// </summary> /// <param name="item">The <see cref="Question"/> to be added to the end of the <c>QuestionCollection</c>.</param> /// <returns>The index at which the value has been added.</returns> public virtual int Add(Question item) { if (m_count == m_array.Length) EnsureCapacity(m_count + 1); m_array[m_count] = item; m_version++; return m_count++; }
public override bool Contains(Question x) { return m_collection.Contains(x); }
public override bool Contains(Question x) { bool result = false; rwLock.AcquireReaderLock(timeout); try { result = collection.Contains(x); } finally { rwLock.ReleaseReaderLock(); } return result; }
public override void Insert(int pos, Question x) { rwLock.AcquireWriterLock(timeout); try { collection.Insert(pos,x); } finally { rwLock.ReleaseWriterLock(); } }
/// <summary> /// Inserts an element into the <c>QuestionCollection</c> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="Question"/> to insert.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="QuestionCollection.Count"/>.</para> /// </exception> public virtual void Insert(int index, Question item) { ValidateIndex(index, true); // throws if (m_count == m_array.Length) EnsureCapacity(m_count + 1); if (index < m_count) { Array.Copy(m_array, index, m_array, index + 1, m_count - index); } m_array[index] = item; m_count++; m_version++; }
/// <summary> /// Removes the first occurrence of a specific <see cref="Question"/> from the <c>QuestionCollection</c>. /// </summary> /// <param name="item">The <see cref="Question"/> to remove from the <c>QuestionCollection</c>.</param> /// <exception cref="ArgumentException"> /// The specified <see cref="Question"/> was not found in the <c>QuestionCollection</c>. /// </exception> public virtual void Remove(Question item) { int i = IndexOf(item); if (i < 0) throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection."); ++m_version; RemoveAt(i); }
/// <summary> /// Copies the entire <c>QuestionCollection</c> to a one-dimensional /// <see cref="Question"/> array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Question"/> array to copy to.</param> /// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param> public virtual void CopyTo(Question[] array, int start) { if (m_count > array.GetUpperBound(0) + 1 - start) throw new System.ArgumentException("Destination array was not long enough."); Array.Copy(m_array, 0, array, start, m_count); }
/// <summary> /// Returns the zero-based index of the first occurrence of a <see cref="Question"/> /// in the <c>QuestionCollection</c>. /// </summary> /// <param name="item">The <see cref="Question"/> to locate in the <c>QuestionCollection</c>.</param> /// <returns> /// The zero-based index of the first occurrence of <paramref name="item"/> /// in the entire <c>QuestionCollection</c>, if found; otherwise, -1. /// </returns> public virtual int IndexOf(Question item) { for (int i=0; i != m_count; ++i) if (m_array[i].Equals(item)) return i; return -1; }
/// <summary> /// Copies the entire <c>QuestionCollection</c> to a one-dimensional /// <see cref="Question"/> array. /// </summary> /// <param name="array">The one-dimensional <see cref="Question"/> array to copy to.</param> public virtual void CopyTo(Question[] array) { this.CopyTo(array, 0); }
/// <summary> /// Determines whether a given <see cref="Question"/> is in the <c>QuestionCollection</c>. /// </summary> /// <param name="item">The <see cref="Question"/> to check for.</param> /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>QuestionCollection</c>; otherwise, <c>false</c>.</returns> public virtual bool Contains(Question item) { for (int i=0; i != m_count; ++i) if (m_array[i].Equals(item)) return true; return false; }
/// <summary> /// Adds the elements of a <see cref="Question"/> array to the current <c>QuestionCollection</c>. /// </summary> /// <param name="x">The <see cref="Question"/> array whose elements should be added to the end of the <c>QuestionCollection</c>.</param> /// <returns>The new <see cref="QuestionCollection.Count"/> of the <c>QuestionCollection</c>.</returns> public virtual int AddRange(Question[] x) { if (m_count + x.Length >= m_array.Length) EnsureCapacity(m_count + x.Length); Array.Copy(x, 0, m_array, m_count, x.Length); m_count += x.Length; m_version++; return m_count; }
public override void Remove(Question x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
public override int IndexOf(Question x) { int result = 0; rwLock.AcquireReaderLock(timeout); try { result = collection.IndexOf(x); } finally { rwLock.ReleaseReaderLock(); } return result; }
public override int AddRange(Question[] x) { int result = 0; rwLock.AcquireWriterLock(timeout); try { result = collection.AddRange(x); } finally { rwLock.ReleaseWriterLock(); } return result; }
/// <summary> /// Initializes a new instance of the <c>QuestionCollection</c> class /// that contains elements copied from the specified <see cref="Question"/> array. /// </summary> /// <param name="a">The <see cref="Question"/> array whose elements are copied to the new list.</param> public QuestionCollection(Question[] a) { m_array = new Question[a.Length]; AddRange(a); }
public override void CopyTo(Question[] array) { rwLock.AcquireReaderLock(timeout); try { collection.CopyTo(array); } finally { rwLock.ReleaseReaderLock(); } }
public override int AddRange(Question[] x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
/// <summary> /// Removes the element at the specified index of the <c>QuestionCollection</c>. /// </summary> /// <param name="index">The zero-based index of the element to remove.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="QuestionCollection.Count"/>.</para> /// </exception> public virtual void RemoveAt(int index) { ValidateIndex(index); // throws m_count--; if (index < m_count) { Array.Copy(m_array, index + 1, m_array, index, m_count - index); } // We can't set the deleted entry equal to null, because it might be a value type. // Instead, we'll create an empty single-element array of the right type and copy it // over the entry we want to erase. Question[] temp = new Question[1]; Array.Copy(temp, 0, m_array, m_count, 1); m_version++; }
public override void Remove(Question x) { rwLock.AcquireWriterLock(timeout); try { collection.Remove(x); } finally { rwLock.ReleaseWriterLock(); } }