using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Word_Guessing_Game
{
public partial class FrmNumberGuessingGame : Form
{
private Random whatever = new Random();
int intRandom = 0;
// Random Number
public FrmNumberGuessingGame()
{
InitializeComponent();
intRandom = whatever.Next(999, 10000);
lstOutput.Items.Add("Numbers" + "\t" + "Entered:" + "\t" + "1st" + "\t" + "2nd" + "\t" + "3rd" + "\t" + "4th");
}
private void btnGo_Click(object sender, EventArgs e)
{
int intInputFirstDigit = 0;
int intInputSecondDigit = 0;
int intInputThirdDigit = 0;
int intInputFourthDigit = 0;
int IntInput = 0;
int intClick=1;
//Declare input
int intFirstDigit = 0;
int intSecondDigit = 0;
int intThirdDigit = 0;
int intFourthDigit = 0;
//Declare Digits
string stringOne;
string stringTwo;
string stringThree;
string stringFour;
//Declare Strings used in listbox
intFirstDigit = intRandom / 1000 % 10;
intSecondDigit = intRandom / 100 % 10;
intThirdDigit = intRandom / 10 % 10;
intFourthDigit = intRandom % 10;
//Breaking random number
//Number of Clicks
intClick =Int32.Parse(lstOutput.Items.Count.ToString());
//O and X start
//try if input is numbers
try
{
IntInput = Int32.Parse(txtEnter.Text);
intInputFirstDigit = IntInput / 1000 % 10;
intInputSecondDigit = IntInput / 100 % 10;
intInputThirdDigit = IntInput / 10 % 10;
intInputFourthDigit = IntInput % 10;
//Breaking input number
//O and X start all numbers different
if (intFirstDigit == intInputFirstDigit&&intInputFirstDigit!=intSecondDigit&&intInputFirstDigit!=intThirdDigit&&intInputFirstDigit!=intFourthDigit)
{
stringOne = "O";
}
else
{
stringOne = "X";
}
if (intSecondDigit == intInputSecondDigit&&intInputSecondDigit!=intFirstDigit&&intInputSecondDigit!=intThirdDigit&&intInputSecondDigit!=intFourthDigit)
{
stringTwo = "O";
}
else
{
stringTwo = "X";
}
if (intThirdDigit == intInputThirdDigit&&intInputThirdDigit!=intFirstDigit&&intInputThirdDigit!=intSecondDigit&&intInputThirdDigit!=intFourthDigit)
{
stringThree = "O";
}
else
{
stringThree = "X";
}
if (intFourthDigit == intInputFourthDigit&&intInputFourthDigit!=intFirstDigit&&intInputFourthDigit!=intSecondDigit&&intInputFourthDigit!=intThirdDigit)
{
stringFour = "O";
}
else
{
stringFour = "X";
}
//O and X end all numbers different
//O and X start have numbers the same
if (intFirstDigit == intInputFirstDigit)
{
stringOne="O";
if (intInputFirstDigit == intSecondDigit)
{
stringTwo = "P";
}
if (intInputFirstDigit == intThirdDigit)
{
stringThree = "P";
}
if (intInputFirstDigit == intFourthDigit)
{
stringFour = "P";
}
}
if (intSecondDigit == intInputSecondDigit)
{
stringTwo = "O";
if (intInputSecondDigit == intFirstDigit)
{
stringOne = "P";
}
if (intInputSecondDigit == intThirdDigit)
{
stringThree = "P";
}
if (intInputSecondDigit == intFourthDigit)
{
stringFour = "P";
}
}
if (intThirdDigit == intInputThirdDigit)
{
stringThree = "O";
if (intInputThirdDigit == intFirstDigit)
{
stringOne = "P";
}
if (intInputThirdDigit == intSecondDigit)
{
stringTwo = "P";
}
if (intInputThirdDigit == intFourthDigit)
{
stringFour = "P";
}
}
if (intFourthDigit == intInputFourthDigit)
{
stringFour = "O";
if (intInputFourthDigit == intFirstDigit)
{
stringOne = "P";
}
if (intInputFourthDigit == intSecondDigit)
{
stringTwo = "P";
}
if (intFourthDigit == intThirdDigit)
{
stringThree = "P";
}
}
//O and X end have numbers the same
//P start number in the wrong place
if (intInputFirstDigit!=intFirstDigit&&intInputFirstDigit == intSecondDigit || intInputFirstDigit == intThirdDigit || intInputFirstDigit == intFourthDigit)
{
stringOne = "P";
}
if (intInputSecondDigit != intSecondDigit && intInputSecondDigit == intFirstDigit || intInputSecondDigit == intThirdDigit || intInputSecondDigit == intFourthDigit)
{
stringTwo = "P";
}
if (intInputThirdDigit != intThirdDigit && intInputThirdDigit == intFirstDigit || intInputThirdDigit == intSecondDigit || intInputThirdDigit == intFourthDigit)
{
stringThree = "P";
}
if (intInputFourthDigit != intFourthDigit && intInputFourthDigit == intFirstDigit || intInputFourthDigit == intSecondDigit || intFourthDigit == intThirdDigit)
{
stringFour = "P";
}
//P end number in the wrong place
lstOutput.Items.Add(IntInput + "==>" + "\t" + stringOne + "\t" + stringTwo + "\t" + stringThree + "\t" + stringFour);
if (intFirstDigit == intInputFirstDigit
&& intSecondDigit == intInputSecondDigit
&& intThirdDigit == intInputThirdDigit
&& intFourthDigit == intInputFourthDigit)
{
lblFirstDigit.Text = String.Format("{0:D}", intInputFirstDigit);
lblSecondDigit.Text = String.Format("{0:D}", intInputSecondDigit);
lblThirdDigit.Text = String.Format("{0:D}", intInputThirdDigit);
lblFourthDigit.Text = String.Format("{0:D}", intInputFourthDigit);
MessageBox.Show("Congratulations! You've Got it! Number of Guesses:" + Convert.ToString(intClick),
"", MessageBoxButtons.OK
, MessageBoxIcon.Asterisk);
}
}
//input is not numbers
catch
{
MessageBox.Show("Please key in numbers",
"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
This post has been edited by L1989: 21 June 2009 - 07:23 AM

New Topic/Question
Reply




MultiQuote





|