Skip to content

Instantly share code, notes, and snippets.

@jwickster
Created March 1, 2017 20:42
Show Gist options
  • Save jwickster/17d115e5dfdb574eca124b5cfedbb0b8 to your computer and use it in GitHub Desktop.
Save jwickster/17d115e5dfdb574eca124b5cfedbb0b8 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CS3280_Assignment_5
{
public partial class FrmUserInfo : Form
{
#region Attributes
/// <summary>
/// New User object
/// </summary>
clsUser newUser;
/// <summary>
/// Sound player - bark. For clicks to proceed
/// </summary>
SoundPlayer bark = new SoundPlayer(Properties.Resources.Bark);
/// <summary>
/// Sound player - whine. For clicks that result in error
/// </summary>
SoundPlayer whine = new SoundPlayer(Properties.Resources.Whine);
/// <summary>
/// Sound player - Double dog bark. For the 'Let's Go' button, which forwards us to the next screen
/// </summary>
SoundPlayer dblBark = new SoundPlayer(Properties.Resources.DoubleDogBark);
#endregion
#region Methods
///////////////////////////////////////////////////////////////////////////////////////////////
public FrmUserInfo()
{
InitializeComponent();
newUser = new clsUser();
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// On click of submit name, this event sets the name of the user
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUIsubmitName_Click(object sender, EventArgs e)
{
try
{
if (Regex.IsMatch(txtUserName.Text, "[A-z]"))
{
bark.Play();
newUser.sName = txtUserName.Text;
lblAge.Show();
txtAge.Show();
btnUIage.Show();
btnUIsubmitName.Enabled = false;
txtUserName.ReadOnly = true;
}
else
{
whine.Play();
MessageBox.Show("Whoops! Try entering letters!", "Uh-Oh!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// On click of submit age, this event sets the age of the user
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUIage_Click(object sender, EventArgs e)
{
try
{
newUser.iAge = Int32.Parse(txtAge.Text);
if (newUser.iAge > 0 && newUser.iAge <= 100)
{
bark.Play();
lblPuppyHelp.Show();
pbUIHappyPuppy.Show();
lblNameHim.Show();
txtPuppyName.Show();
btnUIsubmitPuppyName.Show();
btnUIage.Enabled = false;
txtAge.ReadOnly = true;
}
else
{
MessageBox.Show("Please enter your age (1 - 100)", "Uh-Oh!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch
{
whine.Play();
MessageBox.Show("Whoops! You must have entered something other than a number!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// The text that is entered in the puppy name field is set here
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUIsubmitPuppyName_Click(object sender, EventArgs e)
{
try
{
if (newUser.sName != null && newUser.iAge != 0)
{
bark.Play();
btnLetsGo.Show();
newUser.sPuppyName = txtPuppyName.Text;
btnUIsubmitPuppyName.Enabled = false;
txtPuppyName.ReadOnly = true;
btnChangeInfo.Visible = true;
}
else
{
whine.Play();
MessageBox.Show("Please enter your name and age before playing!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// When the enter key is pressed in the user name field, this handles the action
/// by acting the same as clicking Submit Name button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtUserName_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
btnUIsubmitName_Click(sender, e);
txtAge.Focus();
}
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// When the enter key is pressed in the user age field, this handles the action
/// by acting the same as clicking Submit Age button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtAge_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
btnUIage_Click(sender, e);
txtPuppyName.Focus();
}
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// When the enter key is pressed in the puppy name field, this handles the action
/// by acting the same as clicking Submit Puppy Name button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPuppyName_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
btnUIsubmitPuppyName_Click(sender, e);
}
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Enables the user to proceed to the next screen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLetsGo_Click(object sender, EventArgs e)
{
try
{
dblBark.Play();
frmMainMenu frmMM = new frmMainMenu(newUser);
frmMM.ShowDialog();
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// When the 'Lets Go' button is highlighted and the enter key is pressed, this handles the
/// action by acting the same as clicking 'Lets Go' button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLetsGo_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
btnLetsGo_Click(sender, e);
}
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Enables the user to change their information
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnChangeInfo_Click(object sender, EventArgs e)
{
try
{
bark.Play();
txtUserName.ReadOnly = false;
btnUIsubmitName.Enabled = true;
txtAge.ReadOnly = false;
btnUIage.Enabled = true;
txtPuppyName.ReadOnly = false;
btnUIsubmitPuppyName.Enabled = true;
}
catch
{
MessageBox.Show("Hmm... Something went wrong!",
"Uh-Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}//end frmUserInfo : Form
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment