Exemple #1
0
        public GhostMovement(Cell[,] myMaze, Pacman pacman, int thickness, int imageSize, string Path, Random rand, DispatcherTimer timer, DispatcherTimer pacmanTimer)
        {
            this.pacmanTimer     = pacmanTimer;
            this.thickness       = thickness;
            this.imageSize       = imageSize;
            converter            = new CoordinatesConverter(thickness, imageSize);
            ghost                = new Ghost(myMaze, pacman.currentPosition, rand);
            collapse             = new Collapse(pacman, ghost);                          //екземпляр класу зіткнення, який приймає вхідними параметрами привида та пакмена
            currentGhostPosition = converter.ToCanvasCoordinates(ghost.currentPosition); //поточне розташування
            BitmapImage pacmanBitmap = new System.Windows.Media.Imaging.BitmapImage(new Uri(Path, UriKind.Relative));

            ghostImage        = new Image();
            ghostImage.Source = pacmanBitmap;
            Canvas.SetLeft(ghostImage, currentGhostPosition.X);
            Canvas.SetTop(ghostImage, currentGhostPosition.Y);
            ((MainWindow)System.Windows.Application.Current.MainWindow).canvas.Children.Add(ghostImage);
            this.timer     = timer;
            timer.Interval = TimeSpan.FromSeconds((imageSize + 2 * thickness) / 100.0);
            timer.Tick    += Timer_Tick;;
            timer.Start();
        }
Exemple #2
0
        public Coins(Cell[,] myMaze, Pacman pacman, int thickness, int imageSize)
        {
            this.pacman = pacman;
            CoordinatesConverter conver = new CoordinatesConverter(thickness, imageSize);

            coinsMap = new Image[myMaze.GetLength(0), myMaze.GetLength(1)];
            BitmapImage coinBitmap = new BitmapImage(new Uri(@".\Images\coin.png", UriKind.Relative));

            for (int i = 0; i < myMaze.GetLength(0); i++)//розмістити в кожній клітинці монетку
            {
                for (int j = 0; j < myMaze.GetLength(1); j++)
                {
                    Image coinImage = new Image();
                    coinImage.Source = coinBitmap;
                    coinsMap[i, j]   = coinImage;
                    MyPoint coinPosition = conver.ToCanvasCoordinates(new MyPoint(i, j));
                    Canvas.SetLeft(coinImage, coinPosition.X);
                    Canvas.SetTop(coinImage, coinPosition.Y);
                    ((MainWindow)System.Windows.Application.Current.MainWindow).canvas.Children.Add(coinImage);
                }
            }
        }
Exemple #3
0
        public PacmanMovement(Cell[,] myMaze, int thickness, int imageSize, GameScore gs, DispatcherTimer moveTimer)
        {
            this.thickness = thickness;
            this.imageSize = imageSize;

            pacman = new Pacman(myMaze);
            coins  = new Coins(myMaze, pacman, thickness, imageSize);
            coins.SetCellVisited(pacman.currentPosition);
            converter = new CoordinatesConverter(thickness, imageSize);
            this.gs   = gs;

            currentPacmanPosition   = converter.ToCanvasCoordinates(pacman.currentPosition);
            pacmanBitmapUp          = new BitmapImage(new Uri(@".\Images\upFirst.png", UriKind.Relative));
            pacmanBitmapDown        = new BitmapImage(new Uri(@".\Images\downFirst.png", UriKind.Relative));
            pacmanBitmapLeft        = new BitmapImage(new Uri(@".\Images\leftFirst.png", UriKind.Relative));
            pacmanBitmapRight       = new BitmapImage(new Uri(@".\Images\rigthFirst.png", UriKind.Relative));
            pacmanBitmapUpSecond    = new BitmapImage(new Uri(@".\Images\upSecond.png", UriKind.Relative));
            pacmanBitmapDownSecond  = new BitmapImage(new Uri(@".\Images\downSecond.png", UriKind.Relative));
            pacmanBitmapLeftSecond  = new BitmapImage(new Uri(@".\Images\leftSecond.png", UriKind.Relative));
            pacmanBitmapRightSecond = new BitmapImage(new Uri(@".\Images\rigthSecond.png", UriKind.Relative));
            BitmapImage pacmanBitmap = new BitmapImage(new Uri(@".\Images\basic.png", UriKind.Relative));

            pacmanImage        = new Image();
            pacmanImage.Source = pacmanBitmap;
            Canvas.SetLeft(pacmanImage, currentPacmanPosition.X);
            Canvas.SetTop(pacmanImage, currentPacmanPosition.Y);
            ((MainWindow)System.Windows.Application.Current.MainWindow).canvas.Children.Add(pacmanImage);
            (System.Windows.Application.Current.MainWindow).KeyDown += this.HandleKeyDown;

            animDuration = (imageSize + 2 * thickness) / 100.0;

            this.moveTimer        = moveTimer;
            moveTimer.Interval    = TimeSpan.FromSeconds((imageSize + 2 * thickness) / 110.0);
            moveTimer.Tick       += Timer_Tick;
            chewingTimer          = new DispatcherTimer();
            chewingTimer.Interval = TimeSpan.FromSeconds(0.1);
            chewingTimer.Tick    += Chewing_Tick;
        }