示例#1
0
        private void moving(ARX.Direction direction)
        {
            Movement.Goto(player, map, direction, chkPacmanMoves.Checked);

            map.Self(player.Y * map.Width + player.X).Visible = true;

            //Mark visited 3x3 case radius from player, catch NullReferenceException if case is null (outside the map)
            try { map.Upper(player.Y * map.Width + player.X).Visible = true; } catch (NullReferenceException) { }
            try { map.Righter(player.Y * map.Width + player.X).Visible = true; } catch (NullReferenceException) { }
            try { map.Lower(player.Y * map.Width + player.X).Visible = true; } catch (NullReferenceException) { }
            try { map.Lefter(player.Y * map.Width + player.X).Visible = true; } catch (NullReferenceException) { }

            try { map.Lefter(map.Upper(player.Y * map.Width + player.X).Coord).Visible = true; } catch (NullReferenceException) { }
            try { map.Righter(map.Upper(player.Y * map.Width + player.X).Coord).Visible = true; } catch (NullReferenceException) { }
            try { map.Lefter(map.Lower(player.Y * map.Width + player.X).Coord).Visible = true; } catch (NullReferenceException) { }
            try { map.Righter(map.Lower(player.Y * map.Width + player.X).Coord).Visible = true; } catch (NullReferenceException) { }

            display();
        }
示例#2
0
        protected override void generatePaths()
        {
            base.generatePaths();

            cases.First().State = ARX.State.Cross;
            cases.Last().State  = ARX.State.Point;

            //Choose starting testAround and initialize it
            int currentCase = rand.Next(cases.Count());

            cases[currentCase].State = ARX.State.Point;

            //Search for new testAround until stack is empty
            while (restEmptyState())
            {
                //Determine in which direction the labyrinth is expandable
                ARX.Direction futurDirection = oneRandAdjacent(currentCase);

                //Expand the labyrinth to the up
                if (futurDirection == ARX.Direction.Up)
                {
                    if (Upper(currentCase).State == ARX.State.Right)
                    {
                        Upper(currentCase).State = ARX.State.Cross;
                    }
                    else
                    {
                        Upper(currentCase).State = ARX.State.Down;
                    }

                    currentCase = Upper(currentCase).Coord;
                }

                //Expand the labyrinth to the right
                else if (futurDirection == ARX.Direction.Right)
                {
                    if (Self(currentCase).State == ARX.State.Down)
                    {
                        Self(currentCase).State = ARX.State.Cross;
                    }
                    else
                    {
                        Self(currentCase).State = ARX.State.Right;
                    }

                    if (Righter(currentCase).State == ARX.State.Void)
                    {
                        Righter(currentCase).State = ARX.State.Point;
                    }

                    currentCase = Righter(currentCase).Coord;
                }

                //Expand the labyrinth to the down
                else if (futurDirection == ARX.Direction.Down)
                {
                    if (Self(currentCase).State == ARX.State.Right)
                    {
                        Self(currentCase).State = ARX.State.Cross;
                    }
                    else
                    {
                        Self(currentCase).State = ARX.State.Down;
                    }

                    if (Lower(currentCase).State == ARX.State.Void)
                    {
                        Lower(currentCase).State = ARX.State.Point;
                    }

                    currentCase = Lower(currentCase).Coord;
                }

                //Expand the labyrinth to the left
                else if (futurDirection == ARX.Direction.Left)
                {
                    if (Lefter(currentCase).State == ARX.State.Down)
                    {
                        Lefter(currentCase).State = ARX.State.Cross;
                    }
                    else
                    {
                        Lefter(currentCase).State = ARX.State.Right;
                    }

                    currentCase = Lefter(currentCase).Coord;
                }
            }

            for (int eachTry = 0; eachTry <= 100 && !pathsFinished(); eachTry++)
            {
                if (eachTry == 100)
                {
                    generatePaths();
                }
            }
        }
示例#3
0
        protected override void generatePaths()
        {
            base.generatePaths();

            cases.First().State = ARX.State.Cross;
            cases.Last().State  = ARX.State.Point;

            List <int> currentPoints = new List <int>();

            //Choose starting points and initialize them
            for (int eachInstance = 0; eachInstance < pathInstances; eachInstance++)
            {
                int newCoord;
                do
                {
                    newCoord = rand.Next(cases.Count());
                }while (currentPoints.Contains(newCoord));

                cases[newCoord].State = ARX.State.Point;
                currentPoints.Add(newCoord);
            }

            //Search for new testAround until stack is empty
            while (restEmptyState())
            {
                for (int currentPoint = 0; currentPoint < currentPoints.Count; currentPoint++)
                {
                    //Determine in which direction the labyrinth is expandable
                    ARX.Direction futurDirection = oneRandAdjacent(currentPoints[currentPoint]);

                    //Expand the labyrinth to the up
                    if (futurDirection == ARX.Direction.Up)
                    {
                        if (Upper(currentPoints[currentPoint]).State == ARX.State.Right)
                        {
                            Upper(currentPoints[currentPoint]).State = ARX.State.Cross;
                        }
                        else
                        {
                            Upper(currentPoints[currentPoint]).State = ARX.State.Down;
                        }

                        currentPoints[currentPoint] = Upper(currentPoints[currentPoint]).Coord;
                    }

                    //Expand the labyrinth to the right
                    else if (futurDirection == ARX.Direction.Right)
                    {
                        if (Self(currentPoints[currentPoint]).State == ARX.State.Down)
                        {
                            Self(currentPoints[currentPoint]).State = ARX.State.Cross;
                        }
                        else
                        {
                            Self(currentPoints[currentPoint]).State = ARX.State.Right;
                        }

                        if (Righter(currentPoints[currentPoint]).State == ARX.State.Void)
                        {
                            Righter(currentPoints[currentPoint]).State = ARX.State.Point;
                        }

                        currentPoints[currentPoint] = Righter(currentPoints[currentPoint]).Coord;
                    }

                    //Expand the labyrinth to the down
                    else if (futurDirection == ARX.Direction.Down)
                    {
                        if (Self(currentPoints[currentPoint]).State == ARX.State.Right)
                        {
                            Self(currentPoints[currentPoint]).State = ARX.State.Cross;
                        }
                        else
                        {
                            Self(currentPoints[currentPoint]).State = ARX.State.Down;
                        }

                        if (Lower(currentPoints[currentPoint]).State == ARX.State.Void)
                        {
                            Lower(currentPoints[currentPoint]).State = ARX.State.Point;
                        }

                        currentPoints[currentPoint] = Lower(currentPoints[currentPoint]).Coord;
                    }

                    //Expand the labyrinth to the left
                    else if (futurDirection == ARX.Direction.Left)
                    {
                        if (Lefter(currentPoints[currentPoint]).State == ARX.State.Down)
                        {
                            Lefter(currentPoints[currentPoint]).State = ARX.State.Cross;
                        }
                        else
                        {
                            Lefter(currentPoints[currentPoint]).State = ARX.State.Right;
                        }

                        currentPoints[currentPoint] = Lefter(currentPoints[currentPoint]).Coord;
                    }
                }
            }

            for (int eachTry = 0; eachTry <= 100 && !pathsFinished(); eachTry++)
            {
                if (eachTry == 100)
                {
                    generatePaths();
                }
            }
        }
示例#4
0
        public static void Goto(Player player, Map map, ARX.Direction direction, bool pacmanMode)
        {
            int playerIndexBefore = player.Y * map.Width + player.X;

            if (pacmanMode)
            {
                if (direction == ARX.Direction.Up)
                {
                    if (player.Rotation == 0)
                    {
                    }
                    else if (player.Rotation == 90)
                    {
                        player.Rotation = (player.Rotation + 270) % 360;
                    }
                    else if (player.Rotation == 180)
                    {
                        player.Rotation = (player.Rotation + 180) % 360;
                    }
                    else if (player.Rotation == 270)
                    {
                        player.Rotation = (player.Rotation + 90) % 360;
                    }

                    goForward(player, map);
                }
                else if (direction == ARX.Direction.Right)
                {
                    if (player.Rotation == 90)
                    {
                    }
                    else if (player.Rotation == 180)
                    {
                        player.Rotation = (player.Rotation + 270) % 360;
                    }
                    else if (player.Rotation == 270)
                    {
                        player.Rotation = (player.Rotation + 180) % 360;
                    }
                    else if (player.Rotation == 0)
                    {
                        player.Rotation = (player.Rotation + 90) % 360;
                    }

                    goForward(player, map);
                }
                else if (direction == ARX.Direction.Down)
                {
                    if (player.Rotation == 180)
                    {
                    }
                    else if (player.Rotation == 270)
                    {
                        player.Rotation = (player.Rotation + 270) % 360;
                    }
                    else if (player.Rotation == 0)
                    {
                        player.Rotation = (player.Rotation + 180) % 360;
                    }
                    else if (player.Rotation == 90)
                    {
                        player.Rotation = (player.Rotation + 90) % 360;
                    }

                    goForward(player, map);
                }
                else if (direction == ARX.Direction.Left)
                {
                    if (player.Rotation == 270)
                    {
                    }
                    else if (player.Rotation == 0)
                    {
                        player.Rotation = (player.Rotation + 270) % 360;
                    }
                    else if (player.Rotation == 90)
                    {
                        player.Rotation = (player.Rotation + 180) % 360;
                    }
                    else if (player.Rotation == 180)
                    {
                        player.Rotation = (player.Rotation + 90) % 360;
                    }

                    goForward(player, map);
                }
            }

            else
            {
                if (direction == ARX.Direction.Up)
                {
                    if (player.Rotation == 0 && map.Upper(playerIndexBefore).Accessible)
                    {
                        goForward(player, map);
                    }
                    else if (player.Rotation == 90 && map.CanGoRight(playerIndexBefore) && map.Righter(playerIndexBefore).Accessible)
                    {
                        player.X += 1;
                    }
                    else if (player.Rotation == 180 && map.CanGoDown(playerIndexBefore) && map.Lower(playerIndexBefore).Accessible)
                    {
                        player.Y += 1;
                    }
                    else if (player.Rotation == 270 && map.CanGoLeft(playerIndexBefore) && map.Lefter(playerIndexBefore).Accessible)
                    {
                        player.X -= 1;
                    }
                }
                else if (direction == ARX.Direction.Right)
                {
                    player.Rotation = (player.Rotation + 90) % 360;
                }
                else if (direction == ARX.Direction.Down)
                {
                    if (player.Rotation == 0 && map.CanGoDown(playerIndexBefore) && map.Lower(playerIndexBefore).Accessible)
                    {
                        player.Y += 1;
                    }
                    else if (player.Rotation == 90 && map.CanGoLeft(playerIndexBefore) && map.Lefter(playerIndexBefore).Accessible)
                    {
                        player.X -= 1;
                    }
                    else if (player.Rotation == 180 && map.CanGoUp(playerIndexBefore) && map.Upper(playerIndexBefore).Accessible)
                    {
                        player.Y -= 1;
                    }
                    else if (player.Rotation == 270 && map.CanGoRight(playerIndexBefore) && map.Righter(playerIndexBefore).Accessible)
                    {
                        player.X += 1;
                    }
                }
                else if (direction == ARX.Direction.Left)
                {
                    player.Rotation = (player.Rotation + 270) % 360;
                }
            }

            int playerIndexAfter = player.Y * map.Width + player.X;

            canGoRight = false;
            canGoLeft  = false;

            couldGoRight = false;
            couldGoLeft  = false;

            if (player.Rotation == 0)
            {
                if (map.CanGoRight(playerIndexAfter))
                {
                    canGoRight = true;
                }

                if (map.CanGoLeft(playerIndexAfter))
                {
                    canGoLeft = true;
                }

                if (map.Upper(playerIndexAfter) != null && map.CanGoRight(map.Upper(playerIndexAfter).Coord))
                {
                    couldGoRight = true;
                }

                if (map.Upper(playerIndexAfter) != null && map.CanGoLeft(map.Upper(playerIndexAfter).Coord))
                {
                    couldGoLeft = true;
                }

                if (map.CanGoUp(playerIndexAfter))
                {
                    vision = 1;

                    if (map.Upper(playerIndexAfter) != null && map.CanGoUp(map.Upper(playerIndexAfter).Coord))
                    {
                        vision = 2;
                    }
                }
                else
                {
                    vision = 0;
                }
            }
            else if (player.Rotation == 90)
            {
                if (map.CanGoDown(playerIndexAfter))
                {
                    canGoRight = true;
                }

                if (map.CanGoUp(playerIndexAfter))
                {
                    canGoLeft = true;
                }

                if (map.Righter(playerIndexAfter) != null && map.CanGoDown(map.Righter(playerIndexAfter).Coord))
                {
                    couldGoRight = true;
                }

                if (map.Righter(playerIndexAfter) != null && map.CanGoUp(map.Righter(playerIndexAfter).Coord))
                {
                    couldGoLeft = true;
                }

                if (map.CanGoRight(playerIndexAfter))
                {
                    vision = 1;

                    if (map.CanGoRight(map.Righter(playerIndexAfter).Coord))
                    {
                        vision = 2;
                    }
                }
                else
                {
                    vision = 0;
                }
            }
            else if (player.Rotation == 180)
            {
                if (map.CanGoLeft(playerIndexAfter))
                {
                    canGoRight = true;
                }

                if (map.CanGoRight(playerIndexAfter))
                {
                    canGoLeft = true;
                }

                if (map.Lower(playerIndexAfter) != null && map.CanGoLeft(map.Lower(playerIndexAfter).Coord))
                {
                    couldGoRight = true;
                }

                if (map.Lower(playerIndexAfter) != null && map.CanGoRight(map.Lower(playerIndexAfter).Coord))
                {
                    couldGoLeft = true;
                }

                if (map.CanGoDown(playerIndexAfter))
                {
                    vision = 1;

                    if (map.Lower(playerIndexAfter) != null && map.CanGoDown(map.Lower(playerIndexAfter).Coord))
                    {
                        vision = 2;
                    }
                }
                else
                {
                    vision = 0;
                }
            }
            else
            {
                if (player.Rotation == 270)
                {
                    if (map.CanGoUp(playerIndexAfter))
                    {
                        canGoRight = true;
                    }

                    if (map.CanGoDown(playerIndexAfter))
                    {
                        canGoLeft = true;
                    }

                    if (map.Lefter(playerIndexAfter) != null && map.CanGoUp(map.Lefter(playerIndexAfter).Coord))
                    {
                        couldGoRight = true;
                    }

                    if (map.Lefter(playerIndexAfter) != null && map.CanGoDown(map.Lefter(playerIndexAfter).Coord))
                    {
                        couldGoLeft = true;
                    }

                    if (map.CanGoLeft(playerIndexAfter))
                    {
                        vision = 1;

                        if (map.Lefter(playerIndexAfter) != null && map.CanGoLeft(map.Lefter(playerIndexAfter).Coord))
                        {
                            vision = 2;
                        }
                    }
                    else
                    {
                        vision = 0;
                    }
                }
            }
        }
示例#5
0
        protected override void generatePaths()
        {
            base.generatePaths();

            Stack <int> active = new Stack <int>();

            //Choose starting point and initialize it
            active.Push(rand.Next(cases.Count()));
            cases[active.Last()].State = ARX.State.Point;

            //Search for new point until stack is empty
            while (active.Count() > 0)
            {
                //Determine in which direction the labyrinth is expandable
                ARX.Direction futurDirection = oneRandEmpty(active.First());

                //If there isn't anywhere to go, free one space from the stack
                if (futurDirection == ARX.Direction.Null)
                {
                    active.Pop();
                }

                //Expand the labyrinth to the up
                else if (futurDirection == ARX.Direction.Up)
                {
                    if (Upper(active.First()).State == ARX.State.Right)
                    {
                        Upper(active.First()).State = ARX.State.Cross;
                    }
                    else
                    {
                        Upper(active.First()).State = ARX.State.Down;
                    }

                    active.Push(Upper(active.First()).Coord);
                }

                //Expand the labyrinth to the right
                else if (futurDirection == ARX.Direction.Right)
                {
                    if (Self(active.First()).State == ARX.State.Down)
                    {
                        Self(active.First()).State = ARX.State.Cross;
                    }
                    else
                    {
                        Self(active.First()).State = ARX.State.Right;
                    }

                    if (Righter(active.First()).State == ARX.State.Void)
                    {
                        Righter(active.First()).State = ARX.State.Point;
                    }

                    active.Push(Righter(active.First()).Coord);
                }

                //Expand the labyrinth to the down
                else if (futurDirection == ARX.Direction.Down)
                {
                    if (Self(active.First()).State == ARX.State.Right)
                    {
                        Self(active.First()).State = ARX.State.Cross;
                    }
                    else
                    {
                        Self(active.First()).State = ARX.State.Down;
                    }

                    if (Lower(active.First()).State == ARX.State.Void)
                    {
                        Lower(active.First()).State = ARX.State.Point;
                    }

                    active.Push(Lower(active.First()).Coord);
                }

                //Expand the labyrinth to the left
                else if (futurDirection == ARX.Direction.Left)
                {
                    if (Lefter(active.First()).State == ARX.State.Down)
                    {
                        Lefter(active.First()).State = ARX.State.Cross;
                    }
                    else
                    {
                        Lefter(active.First()).State = ARX.State.Right;
                    }

                    active.Push(Lefter(active.First()).Coord);
                }
            }
        }