C#:
using System;
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 WordHandlerAssignment
{//start of program
public partial class frmWordHandler : Form
{
static string word;
static string[] wordBank = new string[5];
static int i = 0;
static int tries=3;
static string randomWord = " ";
public frmWordHandler()
{
InitializeComponent();
}
private void btnBackToMain_Click(object sender, EventArgs e)
{
{
frmSplashScreen mainForm = new frmSplashScreen();
mainForm.Show();
this.Hide();
}
}
private void frmWordHandler_Load(object sender, EventArgs e)
{
}
private void btnStoreWord_Click(object sender, EventArgs e)
{
word = txtStoreWords.Text.ToUpper();
//lengthCheck(word);
//vowelStart(word);
//recur(word);
if ((lengthCheck(word) == true) && (recur(word) == true) && (vowelStart(word) == true))
{
wordBank[i] = txtStoreWords.Text;
lstStoreWords.Items.Add(word);
i++;
// MessageBox.Show("Word Accepted!", "Well Done!");
}
if (lstStoreWords.Items.Count == 5)
{
MessageBox.Show("Press start along bottom to start!", "Well Done!");
btnStart.Visible = true;
}
}
private bool recur(string word)
{ //start of recur mthod
int i = 0;
int charCount = 0;
for (i = 0; i < word.Length; i++)
{
for (int j = 1; j < word.Length; j++)
{
if (j != i && word[i] == word[j])
{
charCount++;
}
}
}
if (charCount == 0)
{
MessageBox.Show("Word must have reoccurring letter!");
txtStoreWords.ResetText();
txtStoreWords.Focus();
return false;
}
else
{
//MessageBox.Show("Word Accepted, has reoccurence");
txtStoreWords.ResetText();
txtStoreWords.Focus();
return true;
}
}//end of recur method
private bool vowelStart(string word)
{
char vowel = word[0];
switch (vowel)
{ //start of switch
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return true;
break;
default:
MessageBox.Show("The word must start with vowel!");
return false;
break;
}//end of switch
}
private bool lengthCheck(string word)
{
if (word.Length > 4 && word.Length < 9)
{
return true;
}
else
{
MessageBox.Show("The word must be between 4 and 9 characters long!");
txtStoreWords.ResetText();
return false;
}
}
private void btnInstructions_Click(object sender, EventArgs e)
{
frmInstructions mainForm = new frmInstructions();
mainForm.Show();
this.Hide();
}
private void btnStart_Click(object sender, EventArgs e)
{
randomNumber();
btnGuess.Visible = true;
txtGuess.Visible = true;//setting buttons to become visible to start guessing
btnStoreWord.Visible = false;
txtStoreWords.Visible = false;
lblGuessBox.Visible = true;
lblGuesses.Visible = true;
lstStoreWords.Visible = false;
}
private void btnGuess_Click(object sender, EventArgs e)
{
string guess = txtGuess.Text.ToString();
if (wordGuess(guess) == true)
{
MessageBox.Show("Well done!");
DialogResult answer;
answer = MessageBox.Show("Play again?");
if (answer == DialogResult.No)
{
Close();
Environment.Exit(0);
}
else if (answer == DialogResult.Yes)
{
tries.Equals(3);
randomNumber();
}
else if(wordGuess(guess) == false)
{
MessageBox.Show("Your ****!");
//tries = tries - 1;
}
}
}
private bool wordGuess(string word)
{
if (!word.Equals(randomWord))
{
return false;
}
else
{
return true;
}
}
private void randomNumber()
{
Random rand = new Random();
string randomWord = wordBank[(rand.Next(0,(wordBank.Length - 1)))];
}
private void lblGuessBox_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}//end of program