Colt

Colt

  • NA
  • 6
  • 1.8k

False Text Display

May 20 2013 2:02 PM
well im finishing up my project and for some reason this code isnt working:

//All of the 'using System...' allows access to various constructors and methods that are preprogrammed

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 WindowsFormsApplication1
{
    //This is the class that is responsible for the form
    public partial class Form1 : Form
    {
        //Creates multiple picture boxes, a timer and text boxes
        PictureBox Pointer, Target;
        Timer Time;
        TextBox Points, Counter, Stop;


        //Creates two constant variables = 500
        const int swidth = 500;
        const int sheight = 500;
       
        //Sets the size of the 'sizePointer' and 'sizeTarger' variables to 6,6
        Size sizePointer = new Size(6, 6);
        Size sizeTarget = new Size(6, 6);        
               
        //Sets 'TimeInterval' to 1
        int TimeInterval = 1;
       
        //The actual form
        public Form1()
        {
            //Allows the form to be created
            InitializeComponent();


            //Allows the random constructor to be used
            Random rnd = new Random();
            //Sets two variables to be random numbers between 50 and 450
            int x = rnd.Next(50, 450);
            int y = rnd.Next(50, 450); 
                                   
            //Sets 'Time' to be a timer
            Time = new Timer();
            //Turns the timer on
            Time.Enabled = true;
            //Sets the speed of the timer to the variable 'TimeInterval'
            Time.Interval = TimeInterval;  
            //Makes 'Tick' happen when the TimeInterval has been reached
            Time.Tick += new EventHandler(Tick);
           
           
            //Sets the width of the form to 'swidth'
            this.Width = swidth;
            //Sets the height of the form to 'sheight'
            this.Height = sheight;
            //Sets the starting position of the form to center screen
            this.StartPosition = FormStartPosition.CenterScreen;
           
            //Sets 'Pointer' as a picture box
            Pointer = new PictureBox();
            //Sets the size of 'Pointer' to be 'sizePointer'
            Pointer.Size = sizePointer;
            //Adds 'Pointer' to the form
            this.Controls.Add(Pointer);
           
            //Sets 'Target' as a picture box
            Target = new PictureBox();
            //Sets the size of 'Target' to be 'sizeTarget'
            Target.Size = sizeTarget;
            //Creates 'Target' at the point (x,y) which are the random variables
            Target.Location = new Point(x,y);
            //Sets 'Target' to be black
            Target.BackColor = Color.Black;
            //Adds 'Target' to the form
            this.Controls.Add(Target);


            //Sets 'Points' as a text box
            Points = new TextBox();
            //Makes 'Points' read only
            Points.ReadOnly = Enabled;
            //Adds 'Points' to the form
            this.Controls.Add(Points);
            //Sets the text in 'Points' to 0
            Points.Text = "0";


            //Sets 'Counter' as a text box
            Counter = new TextBox();
            //Makes 'Counter' read only
            Counter.ReadOnly = Enabled;
            //Sets the location of 'Counter' to (384, 0)
            Counter.Location = new Point(384, 0);
            //Adds 'Counter' to the form
            this.Controls.Add(Counter);
            //Sets the text in 'Counter' to 20
            Counter.Text = "20";


            //Sets 'Stop' as a text box
            Stop = new TextBox();
            //Makes 'Stop' read only
            Stop.ReadOnly = Enabled;
            //Sets the location of 'Stop' to (185, 200)
            Stop.Location = new Point(185, 200);            
        }  
             
        //Creates the 'Tick' method
        void Tick(object sender, EventArgs e)
        {
            //Creates a new location for pointer at its current x and y coordenates
            Pointer.Location = new Point(Pointer.Location.X, Pointer.Location.Y); 
            //Calls 'Movement' method
            Movement();
            //Calls 'Tag' method
            Tag();        
            //Calls 'Time' method
            Timer();
            //Calls 'End' method
            End();
        }


        //Creates the 'End' method
        private void End()
        {
            //Creates 'c' as a string and sets it to 0
            bool c = Convert.ToBoolean(0);
            //Starts a conditional loop
            //Conditions are that the text in 'Counter' is 0
            if (Convert.ToBoolean(Counter.Text = Convert.ToString(c)))
            {
                Counter.Text = "0";
                //Adds 'Stop' to the form
                this.Controls.Add(Stop);
                //Sets the text in 'Stop' to Times Up
                Stop.Text = "Times Up, your score \n is " + Points.Text;                  
            }
        }


        //Creates the 'Timer' method
        private void Timer()
        {
            //Starts a conditional loop
            //Conditions are that 'TimeInterval' is set to 1
            if (Convert.ToBoolean(TimeInterval) == Convert.ToBoolean(1))
            {
                //Creates 'CounterValue' and sets it to 0
                double CounterValue = 0.0;
                //Creates 'b' and sets it to the text from 'Counter'
                string b = Counter.Text;                
                //Creates 'isParse' 
                bool isParse = Double.TryParse(Counter.Text, out CounterValue);
                if (isParse)
                {
                    //Sets 'b' to 'CounterValue' - .01 
                    b = (CounterValue - .01).ToString();
                }
                //Sets the text displayed in the Points to 'b'
                Counter.Text = Convert.ToString(b);
            }
        }


        //Creates the 'resetTarget' method
        private void resetTarget()
        {
            //Allows the random constructor to be used
            Random rnd = new Random();
            //Sets two variables to be random numbers between 50 and 450
            int x = rnd.Next(50, 450);
            int y = rnd.Next(50, 450);    
   
            //Makes a new target at the point (x,y)
            Target.Location = new Point(x, y);
        }


        //Creates the 'Tag' method
        private void Tag()
        {          
            //Starts conditional loop
            //Conditions are that the pointers edges touch the targets edges
            if (Pointer.Bounds.IntersectsWith(Target.Bounds))
            {
                //Creates 'a' and sets it to what the current text in 'Points'
                //and adds 1 to it
                int a = int.Parse(Points.Text) + 1;
                //Sets the text displayed in the Points to 'a'
                Points.Text = Convert.ToString(a);      
                //Calls the 'resetTarget' method
                resetTarget();
            }
        }


        //Creates the 'Movement' method
        private void Movement()
        {
            //Starts conditional loop 
            //Condition is that the mouses y coord is above or below 'Pointer's height or the mouses x coord is left or right of 'Pointer's width
            if (this.PointToClient(MousePosition).Y >= Pointer.Height / 2 && this.PointToClient(MousePosition).Y <= ClientSize.Height - Pointer.Height / 2 || this.PointToClient(MousePosition).X >= Pointer.Width / 2 && this.PointToClient(MousePosition).X <= ClientSize.Width - Pointer.Width / 2)
            {
                //sets 'X' to the mouses x coord - the 'Pointer's width / 2
                int X = this.PointToClient(MousePosition).X - Pointer.Width / 2;
                //sets 'Y' to the mouses y coord - 'Pointer's height / 2
                int Y = this.PointToClient(MousePosition).Y - Pointer.Height / 2;


                //Makes a new pointer at the point (X,Y)
                Pointer.Location = new Point(X, Y);
            }
        }
    }
}

my problem is that in the top right corner of the form it says false where it should be counting down from 20. if you could help me with this it would be much apreciated. (this is a windows form application)

Answers (2)