Ejemplo n.º 1
0
        private void MovementMonster(ref int smer, PictureBox prisera, int rychlost)
        {
            if (prisera.Image == deadM) // mrtva prisera se nehejbe
            {
                return;
            }
            int i = ((prisera.Location.X) / 30);
            int j = ((prisera.Location.Y) / 30) - 1;

            if (prisera.Image == blueM)
            {
                if (counterBlueM % 2 == 0)
                {
                    smer           = findPath(i, j);
                    directionBlueM = smer;
                }
                else
                {
                    smer = directionBlueM;
                }
                counterBlueM++;
            }
            else if (prisera.Image == yellowM)
            {
                if (pathYellowM.Count == 0)
                {
                    pathYellowM = getPathStackBFS(i, j);
                }
                try
                {
                    var(xR, yR) = ReadInt.ReadVertexName(pathYellowM.Pop().name);

                    if (i - xR == 1)       // pojede doleva
                    {
                        smer = 3;
                    }
                    else if (i - xR == -1) // pojede doprava
                    {
                        smer = 1;
                    }
                    else if (j - yR == 1)  // pojede nahoru
                    {
                        smer = 0;
                    }
                    else //if (yM - yR == -1) // pojede dolu
                    {
                        smer = 2;
                    }
                }
                catch (InvalidOperationException)
                {
                    smer = 5;
                }
            }
            else
            {
                if (pathPurpleM.Count == 0)
                {
                    pathPurpleM = getPathStackDFS(i, j);
                }
                try
                {
                    var(xR, yR) = ReadInt.ReadVertexName(pathPurpleM.Pop().name);

                    if (i - xR == 1)       // pojede doleva
                    {
                        smer = 3;
                    }
                    else if (i - xR == -1) // pojede doprava
                    {
                        smer = 1;
                    }
                    else if (j - yR == 1)  // pojede nahoru
                    {
                        smer = 0;
                    }
                    else //if (yM - yR == -1) // pojede dolu
                    {
                        smer = 2;
                    }
                }
                catch (InvalidOperationException)
                {
                    smer = 5;
                }
            }
            switch (smer)
            {
            case 0:
            {
                prisera.Location = new Point(prisera.Location.X, prisera.Location.Y - rychlost);
                break;
            }

            case 1:
            {
                prisera.Location = new Point(prisera.Location.X + rychlost, prisera.Location.Y);
                break;
            }

            case 2:
            {
                prisera.Location = new Point(prisera.Location.X, prisera.Location.Y + rychlost);
                break;
            }

            case 3:
            {
                prisera.Location = new Point(prisera.Location.X - rychlost, prisera.Location.Y);
                break;
            }

            case 5:
            {
                break;
            }
            }
        }
Ejemplo n.º 2
0
        private int findPath(int xM, int yM)
        {
            int xP = 0;
            int yP = 0;

            switch (directionPacman)
            {
            case 0:
            {
                xP = ((pacman.Location.X) / 30);
                yP = ((pacman.Location.Y) / 30) - 1;
                break;
            }

            case 1:
            {
                xP = ((pacman.Location.X) / 30);
                yP = (((pacman.Location.Y) / 30) - 1);
                break;
            }

            case 2:
            {
                xP = (pacman.Location.X / 30);
                yP = ((pacman.Location.Y) / 30) - 1;
                break;
            }

            case 3:
            {
                xP = ((pacman.Location.X) / 30);
                yP = ((pacman.Location.Y) / 30) - 1;
                break;
            }
            }
            BreathFirstSearch <DirectedUnweightedGraph> .Search(mapGraph, xM + " " + yM);

            var path = BreathFirstSearch <DirectedUnweightedGraph> .GetShortestPath(mapGraph, xP + " " + yP);

            path.Pop(); // popne první vertex, na kterým už monstrum je
            try
            {
                var(xR, yR) = ReadInt.ReadVertexName(path.Pop().name);

                if (xM - xR == 1)       // pojede doleva
                {
                    return(3);
                }
                else if (xM - xR == -1) // pojede doprava
                {
                    return(1);
                }
                else if (yM - yR == 1)  // pojede nahoru
                {
                    return(0);
                }
                else //if (yM - yR == -1) // pojede dolu
                {
                    return(2);
                }
            }
            catch (InvalidOperationException)
            {
                return(5);
            }
        }