Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            player = new PacMan(levelWidth, levelHeight, tileSize, levelMap);
            cnvLevel.Children.Add(player);


            ghosts.Add(new Ghost(levelWidth, levelHeight, tileSize, levelMap));
            ghosts[0].MrYelow.Visibility = Visibility.Visible;
            ghosts.Add(new Ghost(levelWidth, levelHeight, tileSize, levelMap));
            ghosts[1].MrBlue.Visibility = Visibility.Visible;
            ghosts.Add(new Ghost(levelWidth, levelHeight, tileSize, levelMap));
            ghosts[2].MrPink.Visibility = Visibility.Visible;
            foreach (var ghost in ghosts)
            {
                cnvLevel.Children.Add(ghost);
            }

            CreateLevel();

            timer.Tick    += Tick;
            timer.Interval = TimeSpan.FromMilliseconds(400);
            timer.Start();
        }
Beispiel #2
0
        /// <summary>
        /// Ghost constructor
        /// </summary>
        /// <param name="number">Ghost number</param>
        /// <param name="x">Ghost starting x</param>
        /// <param name="y">Ghost starting y</param>
        /// <param name="color">Ghost color</param>
        /// <param name="direction">Ghost stating direction</param>
        /// <param name="pacman">PacMan Info</param>
        public Ghost(int number, int x, int y, ConsoleColor color, Direction direction, PacMan pacman)
        {
            this.x         = x;
            this.y         = y;
            this.color     = color;
            this.pacman    = pacman;
            this.direction = direction;

            animation      = 0;
            animationTimer = 0;
            animationSpeed = 8;
            ghostNumber    = number;
            speedTimer     = 0;
            moveSpeed      = 2;
            timer          = 0;

            isVulnerable = false;
            rebooted     = true;
            IsDead       = false;

            ghosts = new Dictionary <int, string[]> {
                [0] = sp.gFrame1,
                [1] = sp.gFrame2
            };

            rnd = new Random(ghostNumber ^ DateTime.Now.Millisecond);

            state = GhostState.LeavingSpawn;

            pacman.EatSpecialPoints += Run;
            pacman.Died             += Reboot;
        }
Beispiel #3
0
        private World()
        {
            pacMan = new PacMan();
            ghost = new List<Ghost>();
            for (int i = 0; i < 4; i++)
                ghost.Add(new Ghost());

            int j = 0;
            while (j < NROFBLOCKS * NROFBLOCKS)
            {
                if ((screendata[j] & (POWER | DOT)) != 0)
                    food++;
                j++;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Public Game constructor
        /// </summary>
        /// <param name="kr">Key Reader</param>
        public Game(KeyReader kr)
        {
            // Inicializes the variable level
            level = new Level();
            // Inicializes pacMan passing in the given attributes
            pacMan = new PacMan(51, 25, Direction.Right);
            // Inicializes ghost1 using in the given attributes
            ghost1 = new Ghost(1, 39, 21, ConsoleColor.Red, Direction.Right, pacMan);
            // Inicializes ghost2 using in the given attributes
            ghost2 = new Ghost(2, 46, 21, ConsoleColor.Green, Direction.Left, pacMan);
            // Inicializes ghost3 using in the given attributes
            ghost3 = new Ghost(3, 56, 21, ConsoleColor.Cyan, Direction.Right, pacMan);
            // Inicializes ghost4 using in the given attributes
            ghost4 = new Ghost(4, 63, 21, ConsoleColor.Magenta, Direction.Left, pacMan);
            // Sets kR to be equal to the recieved as an argument
            kR = kr;

            // Calls the GameLoop method
            GameLoop();
        }