gemma browse

gemma browse

  • NA
  • 10
  • 61.3k

creating a form but i think there something wrong with the array?

Dec 14 2010 12:58 PM
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;
using System.Threading;

namespace Picklager
{
    public partial class Form1 : Form
    {// am declaring and initialising the valueables
        int count = 1;   // count for counting the number of times the user makes a correct of incorrect guess    
        int numm = 1; // to count the number of correct guesses
        int less = 1;// to coint the wrong guesses

        int s = GetRandNum(1, 100); // my point here is to name the random nuimbers
        int y = GetRandNum1(1, 100);//  s and y to use them in the if statements

        public Form1()
        {
            InitializeComponent();
        }
        static int GetRandNum(int iStart, int iEnd)// generate random numbers for s,  button 1
        {
            Random r = new Random();

            // //sleeping helps generate random number

            Thread.Sleep(r.Next(100));
            int num = r.Next(iStart, iEnd);

            return num;
        }
        static int GetRandNum1(int iStart, int iEnd)// istart for the beginning 1 and end as it's max 100
        {
            Random p = new Random(); // ive generated a 2nd random running methods
            Thread.Sleep(p.Next(100)); // for the text box 2 to distinguish them
            int nu = p.Next(iStart, iEnd);

            return nu;

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Convert.ToString(GetRandNum(1, 100));// the generated number is converted int a string and place in textbox1
            textBox2.Text = Convert.ToString(GetRandNum1(1, 100));
            textBox3.Text = Convert.ToString(count); // a count is made
            button1.Enabled = false;                  // button1 is disabled once a user presses it                 
            count++;
            if (s > y)// if statement to show the number of correct and incorrect guesses
            {
                textBox5.Text = Convert.ToString(numm);
                numm++;
            }
            if (y > s)
            {
                textBox6.Text = Convert.ToString(less);
                less++;
            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox2.Text = Convert.ToString(GetRandNum1(1, 100));
            textBox1.Text = Convert.ToString(GetRandNum(1, 100));
            textBox3.Text = Convert.ToString(count);
            button2.Enabled = false;
            count = count + 1;
            if (y > s)
            {
                textBox5.Text = Convert.ToString(numm);
                numm++;
            }
            if (s > y)
            {
                textBox6.Text = Convert.ToString(less);
                less++;
            }



        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();// to close the program
        }

        private void button4_Click(object sender, EventArgs e)
        {
            {// to enable the two buttons 1 & 2  after a guess.
                button1.Enabled = true;
                button2.Enabled = true;

            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            // help message
            MessageBox.Show("Type in the right password.Press  buttton 1 & 2 to make a guess of the biggest and the next button to make another guess");

        }

        private void button6_Click(object sender, EventArgs e)
        {
            const string pass = "password";
            bool passes = Convert.ToBoolean(pass);
            passes = true;
            try
            {
                while (passes != false)
                {
                    textBox4.Text = Convert.ToString(passes);

                }
            }
            catch (Exception p)
            {
                textBox4.Text = (p.Message);
            }

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            
        }
    }
}


Answers (1)