示例#1
0
        private void DrawEnemy(PacmanAINeural.SimplePacmanEnemyController enemy)
        {
            int radius = 20;

            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(enemy.pos.X * zoom, enemy.pos.Y * zoom, radius, radius);
            Pen pen = new System.Drawing.Pen(Color.Yellow);

            if (!enemy.isSleeping)
            {
                pen = new System.Drawing.Pen(enemy.isEdible ? Color.Green : Color.Red);
                if (enemy.isGettingReady)
                {
                    pen = new System.Drawing.Pen(Color.DarkMagenta);
                }
            }
            g.DrawEllipse(pen, rectangle);
        }
示例#2
0
        public SimplePacman(PacmanAINeural.SimplePacmanController controller, bool fastNoDraw, Random rand = null)
        {
            InitializeComponent();
            KeyDown += new KeyEventHandler(keyDownHandler);
            KeyUp   += new KeyEventHandler(keyUpHandler);

            keys_down = new bool[1];
            key_props = new[] { Keys.Up, Keys.Down, Keys.Left, Keys.Right };

            width  = Picture.Width / zoom;
            height = Picture.Height / zoom;
            image  = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g      = Graphics.FromImage(image);

            if (controller != null)
            {
                this.controller = controller;
            }
            else
            {
                this.controller = new PacmanAINeural.SimplePacmanController();
            }
            this.controller.gameState = this;

            enemies = new PacmanAINeural.SimplePacmanEnemyController[3];

            for (int i = 0; i < enemies.Length; i++)
            {
                enemies[i] = new PacmanAINeural.SimplePacmanEnemyController(this);
                enemies[i].reactionTime = (i * 15) + 10;
            }
            controller.pos = new Point(3 * width / 8, 3 * height / 8);
            enemies[0].pos = new Point(width / 8, height / 8);
            enemies[1].pos = new Point(6 * width / 8, height / 8);

            /*enemies[2].pos = new Point(  width / 8, 6*height / 8);
            *  enemies[3].pos = new Point(6*width / 8, 6*height / 8);*/

            //int myData = 0; // dummy data

            /*tickHandler = new TimerEventHandler(tick);
             * fastTimer = timeSetEvent(fastNoDraw ? 1 : 20, fastNoDraw? 1:20, tickHandler, ref myData, 1);*/

            Application.ApplicationExit += new EventHandler(closeHandler);

            if (rand == null)
            {
                Random = new Random();
            }
            else
            {
                Random = rand;
            }
            this.fastNoDraw = fastNoDraw;
            if (fastNoDraw)
            {
                loop();
            }
            else
            {
                loopWithWaiting();

                /*int myData = 0; // dummy data
                 * tickHandler = new TimerEventHandler(tick);
                 * fastTimer = timeSetEvent(fastNoDraw ? 1 : 20, fastNoDraw? 1:20, tickHandler, ref myData, 1);*/
            }
        }