public String getWord_hard(int count) { difficulty diff = new difficulty(); // Initialise the displayWord variable. String displayWord = ""; // Runs the setHardDiff_jumbled method and stores the returned value in fileDir. String fileDir = diff.setHardDiff_jumbled(); // Reads the file and stores the complete text document in the string wordBank. String wordBank = File.ReadAllText(fileDir); // Splits the wordBank at each semi-colon. String[] words = wordBank.Split(';'); // Try catch statement used to pick up overflow on the array. try { // Sets the current word. displayWord = words[count]; } catch (Exception e) { // Displays an error message to the user if there are no more words in the text file. MessageBox.Show("You have run out of words. Please increase the difficulty."); } // Returns the word to be displayed. return(displayWord); }
public bool compareWord_hard(String userAnswer, int count) { difficulty diff = new difficulty(); // Sets the file directory by running setEasyDiff_words method, and stores in fileDir. String fileDir = diff.setHardDiff_words(); // Reads complete text file and stores in variable wordBank. String wordBank = File.ReadAllText(fileDir); // Splits the wordBank at each semi-colon. String[] words = wordBank.Split(';'); // If the user answer is the same as the word read into the file. if (userAnswer == words[count]) { // Returned value is true. return(true); } else { // Returned value is false. return(false); } }
private void hardDiff_Click(object sender, EventArgs e) { difficulty diff = new difficulty(); word word = new word(); // Sets the count to 0. count = 0; // Sets the string displayWord to the returned value from getWord_hard. String displayWord = word.getWord_hard(count); // Displays the word to the user. guessWordBox.Text = displayWord; // Shows the correct label for the difficulty chosen. easyDiffLabel.Show(); medDiffLabel.Hide(); hardDiffLabel.Hide(); // Shows the new word button. newWordButton.Show(); // Sets the difficulty variable to 3 (hard) difficulty = 3; //WB Tetsing Console.WriteLine("Hard Button Press"); Console.WriteLine("Expected difficulty HARD"); Console.WriteLine("Difficulty: " + difficulty); Console.WriteLine("Count: " + count); Console.WriteLine("Current Word: " + displayWord); }
private void submitWord_Click(object sender, EventArgs e) { difficulty diff = new difficulty(); word word = new word(); // Gets user input and stores in String variable userAnswer. String userAnswer = answerWordBox.Text; // If difficulty is easy. if (difficulty == 1) { // Sets vaiable result with returned value from compareWord method. bool result = word.compareWord_easy(userAnswer, count); // If result is true. if (result == true) { // New Word // Increase count. count++; // Get new word. String displayWord = word.getWord_easy(count); // Display new word to user. guessWordBox.Text = displayWord; // Increase Score. score++; //WB Testing Console.WriteLine("Submit Button Press"); Console.WriteLine("Returned value: " + result); Console.WriteLine("New Count: " + count); Console.WriteLine("New Score: " + score); } else { // Minus one from score. score--; // Show message box containing error message. MessageBox.Show("Thats Incorrect -1 Point"); //WB Testing Console.WriteLine("Submit Button Press"); Console.WriteLine("Returned value: " + result); Console.WriteLine("New Count: " + count); Console.WriteLine("New Score: " + score); } scoreLabel.Text = score.ToString(); } // If difficulty is medium. if (difficulty == 2) { bool result = word.compareWord_med(userAnswer, count); if (result == true) { // New Word // Increase count. count++; // Get new word. String displayWord = word.getWord_med(count); // Display new word to user. guessWordBox.Text = displayWord; // Increase Score. score++; //WB Testing Console.WriteLine("Submit Button Press"); Console.WriteLine("Returned value: " + result); Console.WriteLine("New Count: " + count); Console.WriteLine("New Score: " + score); } else { // Minus one from score. score--; // Show message box containing error message. MessageBox.Show("Thats Incorrect -1 Point"); //WB Testing Console.WriteLine("Submit Button Press"); Console.WriteLine("Returned value: " + result); Console.WriteLine("New Count: " + count); Console.WriteLine("New Score: " + score); } scoreLabel.Text = score.ToString(); } // If difficulty is hard. if (difficulty == 3) { bool result = word.compareWord_hard(userAnswer, count); if (result == true) { // New Word // Increase count. count++; // Get new word. String displayWord = word.getWord_hard(count); // Display new word to user. guessWordBox.Text = displayWord; // Increase Score. score++; //WB Testing Console.WriteLine("Submit Button Press"); Console.WriteLine("Returned value: " + result); Console.WriteLine("New Count: " + count); Console.WriteLine("New Score: " + score); } else { // Minus one from score. score--; // Show message box containing error message. MessageBox.Show("Thats Incorrect -1 Point"); //WB Testing Console.WriteLine("Submit Button Press"); Console.WriteLine("Returned value: " + result); Console.WriteLine("New Count: " + count); Console.WriteLine("New Score: " + score); } scoreLabel.Text = score.ToString(); } }
private void newWordButton_Click(object sender, EventArgs e) { difficulty diff = new difficulty(); // Increase Count. count++; // If difficulty is easy. if (difficulty == 1) { word word = new word(); // Get easy word from file. String displayWord = word.getWord_easy(count); // Display word to user. guessWordBox.Text = displayWord; //WB Testing Console.WriteLine("New Word Button Press"); Console.WriteLine("Expected Difficulty EASY"); Console.WriteLine("Difficulty: " + difficulty); Console.WriteLine("New word displayed: " + displayWord); } // If difficulty is medium. if (difficulty == 2) { word word = new word(); // Get medium word from file. String displayWord = word.getWord_med(count); // Display word to user. guessWordBox.Text = displayWord; //WB Testing Console.WriteLine("New Word Button Press"); Console.WriteLine("Expected Difficulty MEDIUM"); Console.WriteLine("Difficulty: " + difficulty); Console.WriteLine("New word displayed: " + displayWord); } // If difficulty is hard. if (difficulty == 3) { word word = new word(); // Get hard word from file. String displayWord = word.getWord_hard(count); // Display word to user. guessWordBox.Text = displayWord; //WB Testing Console.WriteLine("New Word Button Press"); Console.WriteLine("Expected Difficulty HARD"); Console.WriteLine("Difficulty: " + difficulty); Console.WriteLine("New word displayed: " + displayWord); } //WB Testing Console.WriteLine("New Count: " + count); }