using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp9 { public partial class Form1 : Form { public static List pool; public static int index = 0; public static Random rng; public static Boolean showAnswer = true; public static int rights = 0; public static int total = 0; public static String TOP_ALIGN = "\n\n\n\n\n"; public class Cards { public string Q; public string A; public Cards() { Q = A = ""; } public Cards(params string[] tokens) { Q = tokens[0]; A = tokens[1]; } } public Form1() { InitializeComponent(); FlashCard.SelectionAlignment = HorizontalAlignment.Center; Score_TextBox.TextAlign = HorizontalAlignment.Center; rng = new Random(); pool = new List(); string slacker; // Normally, I would use "Add New Item" in Visual Studios to place a text file that by // default is 2 directories above the one containing the executable, but I figure since // you may already be placing image files into the executable-directory, why not place the // cards file here as well? using (StreamReader inFile = new StreamReader("cards.txt")) { slacker = inFile.ReadLine(); while (slacker != null) { pool.Add(new Cards(slacker.Split('#')[0], slacker.Split('#')[1])); slacker = inFile.ReadLine(); } } /* pool.Add(new Cards("What is the return type of a Predicate?", "Boolean")); pool.Add(new Cards("What is the correct bracket notation for a 3-D jagged array?", "[][][]")); // Conventional == [ , , ] pool.Add(new Cards("Describe the functionality of a SortedList.", "This is Dictionary collection that maintains sorted order, and is memory-efficient.")); pool.Add(new Cards("What is the default scope of attributes/methods defined within a class?", "Private")); */ index = rng.Next(pool.Count); FlashCard.Text = TOP_ALIGN + pool[index].Q; } private void FlashCard_Click(object sender, EventArgs e) { if (showAnswer) { FlashCard.Text = TOP_ALIGN + pool[index].A; showAnswer = false; } else { FlashCard.Text = TOP_ALIGN + pool[index].Q; showAnswer = true; } } private void Response_Button(object sender, EventArgs args) { /* if (index < pool.Count) index++; */ Button alpha = sender as Button; //if (alpha.Text.CompareTo("Right") == 0) // So forth and so on // rights++; if (alpha == Right_Button) { rights++; } index = rng.Next(pool.Count); total++; progressBar1.PerformStep(); Score_TextBox.ForeColor = Color.FromArgb(255, (int)(255 * (1 - (float)rights / total)), (int)(255 * ((float)rights / total)), 0); Score_TextBox.Text = String.Format("{0:0.00%}", (float)rights/total); if (progressBar1.Value == progressBar1.Maximum) { History_TextBox.AppendText(Score_TextBox.Text + " "); Score_TextBox.Text = ""; progressBar1.Value = 0; rights = 0; total = 0; } showAnswer = true; FlashCard.Text = TOP_ALIGN + pool[index].Q; } } }