Esempio n. 1
0
        public Visualizer(BasePacman pacman = null)
        {
            InitializeComponent();
            KeyDown           += new KeyEventHandler(keyDownHandler);
            Picture.MouseDown += new MouseEventHandler(mouseDownHandler);
            Picture.MouseMove += new MouseEventHandler(mouseMoveHandler);
            // load images
            sprites = Util.LoadImage("sprites.png");
            // initialize graphics
            image = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g     = Graphics.FromImage(image);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            //g.ScaleTransform(2.0f, 2.0f);
            gameState = new GameState();

            this.Width  = gameState.Map.PixelWidth + 7;            // screenplayer test
            this.Height = gameState.Map.PixelHeight + 49;          // screenplayer test
            //gameState.PacmanMortal = false;
            gameState.StartPlay();
            gameState.GameOver += new EventHandler(gameOverHandler);

            if (pacman != null)
            {
                controller           = pacman;
                gameState.Controller = pacman;
            }

            // IMPORTANT SETTINGS AREA //
            // try load controller
            //tryLoadController("SmartDijkstraPac");
            // load stream
            // tryLoadStream("best22030");
            // start timer ( must always be the last to be started! )

            int myData = 0;             // dummy data

            tickHandler = new TimerEventHandler(tick);
            fastTimer   = timeSetEvent(50, 50, tickHandler, ref myData, 1);

            /*gameState.Ghosts[1].Enabled = false;
            *  gameState.Ghosts[2].Enabled = false;
            *  gameState.Ghosts[3].Enabled = false;*/
        }
Esempio n. 2
0
        /*private void loadNeuralPacman(string name) {
         *  BasePacman pacman = new RandomPac();
         *  controller = pacman;
         *  gameState.Controller = pacman;
         * }*/

        private void tryLoadController(string name)
        {
            byte[]   assemblyBytes    = LoadBytes(Path.Combine(WorkingDir, "PacmanAI.dll"));
            byte[]   assemblyPdbBytes = LoadBytes(Path.Combine(WorkingDir, "PacmanAI.pdb"));
            Assembly assembly         = Assembly.Load(assemblyBytes, assemblyPdbBytes);

            foreach (Type type in assembly.GetTypes())
            {
                if (type.BaseType == typeof(BasePacman))
                {
                    BasePacman pacman = (BasePacman)Activator.CreateInstance(type);
                    if (pacman.Name == name)
                    {
                        controller           = pacman;
                        gameState.Controller = pacman;
                        return;
                    }
                }
            }
        }