public Sprite.CompassDirections ChooseNetterpillarDirection(Point currentLocation, Sprite.CompassDirections currentDirection)
        {
            Sprite.CompassDirections ChooseNetterpillarDirection_result = (Sprite.CompassDirections) 0;
            GameObjects BestObject;
            GameObjects NextObject = (GameObjects)0;

            switch (currentDirection)
            {
            case Sprite.CompassDirections.East:
                NextObject = arrGameField[currentLocation.X + 1, currentLocation.Y];
                break;

            case Sprite.CompassDirections.West:
                NextObject = arrGameField[currentLocation.X - 1, currentLocation.Y];
                break;

            case Sprite.CompassDirections.South:
                NextObject = arrGameField[currentLocation.X, currentLocation.Y + 1];
                break;

            case Sprite.CompassDirections.North:
                NextObject = arrGameField[currentLocation.X, currentLocation.Y - 1];
                break;
            }

            //Pick the lowest value - Mushroom or empty
            BestObject = (GameObjects)Math.Min(Math.Min(Math.Min((int)arrGameField[currentLocation.X + 1, currentLocation.Y], (int)arrGameField[currentLocation.X - 1, currentLocation.Y]), (int)arrGameField[currentLocation.X, currentLocation.Y + 1]), (int)arrGameField[currentLocation.X, currentLocation.Y - 1]);

            // If the current direction is equal the best direction, stay in current direction
            if (NextObject == BestObject)
            {
                ChooseNetterpillarDirection_result = currentDirection;
            }
            else
            {
                // Select the direction of the best object
                if (BestObject == arrGameField[currentLocation.X + 1, currentLocation.Y])
                {
                    ChooseNetterpillarDirection_result = Sprite.CompassDirections.East;
                }
                else if (BestObject == arrGameField[currentLocation.X - 1, currentLocation.Y])
                {
                    ChooseNetterpillarDirection_result = Sprite.CompassDirections.West;
                }
                else if (BestObject == arrGameField[currentLocation.X, currentLocation.Y + 1])
                {
                    ChooseNetterpillarDirection_result = Sprite.CompassDirections.South;
                }
                else if (BestObject == arrGameField[currentLocation.X, currentLocation.Y - 1])
                {
                    ChooseNetterpillarDirection_result = Sprite.CompassDirections.North;
                }
            }

            ChooseNetterpillarDirection_result = RandomDirection(currentLocation, ChooseNetterpillarDirection_result);
            return(ChooseNetterpillarDirection_result);
        }
示例#2
0
        public Netterpillar(int x, int y, Sprite.CompassDirections initialDirection, bool isComputer)
        {
            NetterBody = new NetterBody[25 + 1];
            int incX = 0, incY = 0;

            IsComputer  = isComputer;
            NetterHeadN = Load(Application.StartupPath + "\\" + IMAGE_PATH + "\\" + (IsComputer ? "" : "Player") + "NetterHeadN.gif");
            NetterHeadS = Load(Application.StartupPath + "\\" + IMAGE_PATH + "\\" + (IsComputer ? "" : "Player") + "NetterHeadS.gif");
            NetterHeadE = Load(Application.StartupPath + "\\" + IMAGE_PATH + "\\" + (IsComputer ? "" : "Player") + "NetterHeadE.gif");
            NetterHeadW = Load(Application.StartupPath + "\\" + IMAGE_PATH + "\\" + (IsComputer ? "" : "Player") + "NetterHeadW.gif");
            for (int i = 0; i < NetterBodyLength; i++)
            {
                NetterBody[i] = new NetterBody(IsComputer);
            }

            // Position the Netterpillar on the given point
            Direction  = initialDirection;
            Location.X = x;
            Location.Y = y;
            // Position each of the body parts
            switch (Direction)
            {
            case Sprite.CompassDirections.East:
                incX = -1;
                break;

            case Sprite.CompassDirections.South:
                incY = -1;
                break;

            case Sprite.CompassDirections.West:
                incX = 1;
                break;

            case Sprite.CompassDirections.North:
                incY = 1;
                break;
            }
            for (int i = 0; i < NetterBodyLength; i++)
            {
                x += incX;
                y += incY;
                NetterBody[i].Location.X = x;
                NetterBody[i].Location.Y = y;
            }
        }
        public Sprite.CompassDirections RandomDirection(Point currentLocation, Sprite.CompassDirections chooseCompassDirections)
        {
            Sprite.CompassDirections RandomDirection_result;
            int x = rand.Next(0, 100);             //Rnd(1)*100;

            RandomDirection_result = chooseCompassDirections;
            if (x < RandomPercent)
            {
                switch (chooseCompassDirections)
                {
                case Sprite.CompassDirections.East:
                    // Try the other directions
                    if (arrGameField[currentLocation.X, currentLocation.Y + 1] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.South;
                    }
                    else if (arrGameField[currentLocation.X, currentLocation.Y - 1] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.North;
                    }
                    else if (arrGameField[currentLocation.X - 1, currentLocation.Y] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.West;
                    }
                    break;

                case Sprite.CompassDirections.West:
                    // Try the other directions
                    if (arrGameField[currentLocation.X, currentLocation.Y + 1] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.South;
                    }
                    else if (arrGameField[currentLocation.X, currentLocation.Y - 1] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.North;
                    }
                    else if (arrGameField[currentLocation.X + 1, currentLocation.Y] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.East;
                    }
                    break;

                case Sprite.CompassDirections.North:
                    // Try the other directions
                    if (arrGameField[currentLocation.X, currentLocation.Y + 1] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.South;
                    }
                    else if (arrGameField[currentLocation.X + 1, currentLocation.Y] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.East;
                    }
                    else if (arrGameField[currentLocation.X - 1, currentLocation.Y] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.West;
                    }
                    break;

                case Sprite.CompassDirections.South:
                    // Try the other directions
                    if (arrGameField[currentLocation.X, currentLocation.Y - 1] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.North;
                    }
                    else if (arrGameField[currentLocation.X + 1, currentLocation.Y] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.East;
                    }
                    else if (arrGameField[currentLocation.X - 1, currentLocation.Y] <= GameObjects.Empty)
                    {
                        RandomDirection_result = Sprite.CompassDirections.West;
                    }
                    break;
                }
            }
            return(RandomDirection_result);
        }