예제 #1
0
파일: Main.cs 프로젝트: jensj12/MeesGame
        /// <summary>
        /// Places a tile between the two points, creating the loop.
        /// </summary>
        private void AddLoopTile(Point one, Point two)
        {
            tileToAdd = new FloorTile();
            behindDoorFlags difference = behindDoorInfo[one.X, one.Y] ^ behindDoorInfo[two.X, two.Y];

            // Check if the difference is exactly one door color
            if (Enum.IsDefined(typeof(behindDoorFlags), difference))
            {
                tileToAdd = new DoorTile();
                (tileToAdd as DoorTile).SecondarySpriteColor = ChooseColor((int)Math.Log((int)difference, 2), false, false);
            }
            if ((!Enum.IsDefined(typeof(behindDoorFlags), difference) && difference != 0) || randomChance(loopHoleChance))
            {
                tileToAdd = new HoleTile();
                if (randomChance(0.5))
                {
                    tileToAdd = new GuardTile();
                }
            }
            tiles.Add(tileToAdd, PointBetween(one, two).X, PointBetween(one, two).Y);
        }
예제 #2
0
파일: Helpers.cs 프로젝트: jensj12/MeesGame
        /// <summary>
        /// Checks if the new exit point is better than the current exit.
        /// </summary>
        private void UpdateBestExit(Point newPoint)
        {
            // The best exit tile has to be next to the edge of the tilefield, the exit will be placed on the edge next to it.
            if (!tiles.NearEdgeOfTileField(newPoint.X, newPoint.Y))
            {
                return;
            }

            // The best exit is the one hardest to reach from the start.
            // Start with the distance from the start tile.
            int             score          = exitScore[newPoint.X, newPoint.Y];
            behindDoorFlags primaryFlags   = behindDoorInfo[newPoint.X, newPoint.Y];
            behindDoorFlags secondaryFlags = primaryFlags;

            // For each door the exit is hidden behind, add the doors the key is hidden behind
            foreach (behindDoorFlags flag in Enum.GetValues(typeof(behindDoorFlags)))
            {
                if ((flag & primaryFlags) != 0)
                {
                    secondaryFlags |= keyBehindDoorInfo[(int)Math.Log((int)flag, 2)];
                }
            }

            // Add some points for each required key.
            foreach (behindDoorFlags flag in Enum.GetValues(typeof(behindDoorFlags)))
            {
                if ((flag & secondaryFlags) != 0)
                {
                    score += doorScore;
                }
            }

            // Update the best exit if it's better.
            if (score > bestExitScore)
            {
                bestExit      = newPoint;
                bestExitScore = score;
            }
        }