Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            wall_pic = new Bitmap("pics/" + "Green" + "Box.png");
            InitializeComponent();
            this.Width = RES_WIDTH + 325;
            this.Height = RES_HEIGHT + 40;

            PopLabel.Text = "Population: " + POPULATION.ToString();
            mutationLabel.Text = "Mutation Rate: " + mutationRate;
            crossoverLabel.Text = "Crossover Rate: " + crossoverRate.ToString();
            eliteLabel.Text = "Elitism (%): " + populationElitism.ToString();

            START_POSITION = new Point(LEN + LEN / 2, LEN + LEN / 2);
            walls = new Wall[RES_HEIGHT / LEN + 1, RES_WIDTH / LEN + 1];
            stepThroughWalls((int i, int j) => { walls[j, i] = new Wall(i * LEN, j * LEN, LEN, LEN); });
            GA_ENGINE = new GeneticAlgorithm(BITS_PER_CHROM, NUMB_STEPS, POPULATION, crossoverRate, mutationRate, populationElitism);
            PAUSE = true;
            DELAY_PAUSE = 0;
            cheese = new Cheese(new Point(), 1, 1, 1);
            cheese.location.X = LEN * ((RES_WIDTH / LEN) / 2) + LEN / 2;
            cheese.location.Y = LEN / 2;
            windowsGraphics = this.CreateGraphics();
            screen = new Bitmap(this.Width, this.Height);
            onScreenGraphics = Graphics.FromImage(screen);
            this.Paint += new PaintEventHandler(DrawGame);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(cheese.KeyDown);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(MainFormKeyDown);
            //this.KeyUp += new System.Windows.Forms.KeyEventHandler(cheese.KeyUp);
        }
Example #2
0
File: Rat.cs Project: ajrod/Ratatat
        /// <summary>
        /// Determines whether the rat is touching the cheese.
        /// </summary>
        /// <param name="cheese">The cheese.</param>
        /// <returns>
        ///   <c>true</c> if the rat is touching the cheese; otherwise, <c>false</c>.
        /// </returns>
        public bool isTouching(Cheese cheese)
        {
            double distance = Math.Sqrt(
                (this.location.X - cheese.location.X) * (this.location.X - cheese.location.X)
                + (this.location.Y - cheese.location.Y) * (this.location.Y - cheese.location.Y));

            return distance < this.radius;
        }