Skip to content

Instantly share code, notes, and snippets.

@jwickster
Created March 1, 2017 20:42
Show Gist options
  • Save jwickster/0b9b686cff481249e6b86cae9ca13a4a to your computer and use it in GitHub Desktop.
Save jwickster/0b9b686cff481249e6b86cae9ca13a4a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
namespace CS3280_Assignment_5
{
public class ClsGame
{
#region Properties
/// <summary>
/// Game type getter and setter
/// </summary>
public string sGameType { get; set; }
#endregion
#region Attributes
/// <summary>
/// Randomizer for the numbers we will need
/// </summary>
Random rand = new Random();
/// <summary>
/// left side integer of addition problem
/// </summary>
public int iAugend; // { get; set; }
/// <summary>
/// second integer of addition problem
/// </summary>
public int iAddend; // { get; set; }
/// <summary>
/// left side integer of subtraction problem
/// </summary>
public int iMinuend; // { get; set; } { get; set; }
/// <summary>
/// right side integer of subtraction problem
/// </summary>
public int iSubtrahend; // { get; set; } { get; set; }
/// <summary>
/// left side integer of multiplication problem
/// </summary>
public int iMultiplicand; // { get; set; } { get; set; }
/// <summary>
/// right side integer of multiplication problem
/// </summary>
public int iMultiplier; // { get; set; }
/// <summary>
/// left side integer of division problem
/// </summary>
public int iDividend; // { get; set; }
/// <summary>
/// right side integer of division problem
/// </summary>
public int iDivisor; // { get; set; }
/// <summary>
/// Holds the gameType answer
/// </summary>
public int ianswer;
/// <summary>
/// Keeps track of the player's score
/// </summary>
public int iScoreTally = 1;
/// <summary>
/// SoundPlayer - Correct - Plays when a user answers correctly
/// </summary>
SoundPlayer correct = new SoundPlayer(Properties.Resources.GameCorrect);
/// <summary>
/// SoundPlayer - Incorrect -Plays when a user answers incorrectly
/// </summary>
SoundPlayer incorrect = new SoundPlayer(Properties.Resources.GameIncorrect);
#endregion
#region Methods
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Add method for the gameType ADD
/// </summary>
public void Add()
{
iAugend = rand.Next(25);
iAddend = rand.Next(25);
int sum = iAugend + iAddend;
ianswer = sum;
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Subtract method for the gameType SUBTRACT
/// </summary>
public void Subtract()
{
iMinuend = rand.Next(50, 100);
iSubtrahend = rand.Next(0,50);
int iDifference = iMinuend - iSubtrahend;
ianswer = iDifference;
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Multiply method for the gameType MULTIPLY
/// </summary>
public void Multiply()
{
iMultiplicand = rand.Next(0, 12);
iMultiplier = rand.Next(0, 12);
int iProduct = iMultiplicand * iMultiplier;
ianswer = iProduct;
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Divide method for the gameType DIVIDE
/// </summary>
public void Divide()
{
do
{
iDividend = rand.Next(0, 20);
iDivisor = rand.Next(1, 20);
int iQuotient = iDividend / iDivisor;
ianswer = iQuotient;
}
while (iDividend % iDivisor != 0);
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Checks the user's input for right or wrong answer
/// </summary>
/// <param name="answer">integer value from user input</param>
/// <param name="yn">return bool value for label indication</param>
/// <returns></returns>
public int isAnswerCorrect(int answer, out bool yn)
{
yn = false;
if(answer == ianswer)
{
iScoreTally++;
yn = true;
correct.Play();
}
else if (answer != ianswer && iScoreTally != 0)
{
yn = false;
incorrect.Play();
}
else
{
iScoreTally = 0;
yn = false;
incorrect.Play();
}
return iScoreTally;
}
#endregion Methods
}//end clsGame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment