Exemplo n.º 1
0
        /// <summary>
        /// Generates the rooms using the seed
        /// </summary>
        public void Generate()
        {
            this.id = human.area;

            // Set the size (in rooms) for the world
            Console.WriteLine("Choosing sizes...");
            Random generation = new Random(seed);
            length = generation.Next(
                id / Constants.IntValue("mapSizeDivisor") + Constants.IntValue("mapSizeBonusMin"),
                id / Constants.IntValue("mapSizeDivisor") + Constants.IntValue("mapSizeBonusMax"));
            width = generation.Next(
                id / Constants.IntValue("mapSizeDivisor") + Constants.IntValue("mapSizeBonusMin"),
                id / Constants.IntValue("mapSizeDivisor") + Constants.IntValue("mapSizeBonusMax"));
            rooms = new _2DRoomList();
            int finishRoom = generation.Next(0, length);

            int[] roomLengths = new int[length];
            for (int i = 0; i < length; ++i)
                roomLengths[i] = generation.Next(11, 33);

            Console.WriteLine("Generating Rooms...");
            // Create all of the rooms with random templates
            for (int y = 0; y < width; ++y)
            {
                // Randomize the column width
                int roomWidth = generation.Next(7, 13);
                for (int x = 0; x < length; ++x)
                {
                    // Randomize the type
                    int type = generation.Next();

                    // Get the room layout with the new parameters
                    char[,] tiles = Template.CreateRoom(type, roomLengths[x], roomWidth);

                    int halfWidth = roomWidth / 2;
                    int halfLength = roomLengths[x] / 2;
                    // Set the paths between rooms
                    if (x != 0)
                    {
                        tiles[0, halfWidth - 1] = Convert(tiles[0, halfWidth - 1], 4);
                        tiles[0, halfWidth + 1] = Convert(tiles[0, halfWidth + 1], 5);
                        tiles[0, halfWidth] = ' ';
                    }
                    if (y != 0)
                    {
                        tiles[halfLength - 1, 0] = Convert(tiles[halfLength - 1, 0], 0);
                        tiles[halfLength + 1, 0] = Convert(tiles[halfLength + 1, 0], 1);
                        tiles[halfLength, 0] = ' ';
                    }
                    if (x != length - 1)
                    {
                        tiles[roomLengths[x] - 1, halfWidth - 1] = Convert(tiles[roomLengths[x] - 1, halfWidth - 1], 6);
                        tiles[roomLengths[x] - 1, halfWidth + 1] = Convert(tiles[roomLengths[x] - 1, halfWidth + 1], 7);
                        tiles[roomLengths[x] - 1, halfWidth] = ' ';
                    }
                    if (y != width - 1 || x == finishRoom)
                    {
                        tiles[halfLength - 1, roomWidth - 1] = Convert(tiles[halfLength - 1, roomWidth - 1], 2);
                        tiles[halfLength + 1, roomWidth - 1] = Convert(tiles[halfLength + 1, roomWidth - 1], 3);
                        tiles[halfLength, roomWidth - 1] = ' ';
                    }

                    // Add the room to the array
                    rooms.Add(new Room(roomLengths[x], roomWidth, tiles));

                    // Place the human within the first room
                    if (x + y == 0)
                        human.Position = new int[] { 1, roomWidth / 2 };
                }
            }
            pathing.Map = this;
            Console.WriteLine("Arranging rooms...");
            rooms.Arrange(length, width);

            Console.WriteLine("Adding enemies...");
            // Add enemies to the map
            for (int x = 0; x < length; ++x)
                for (int y = 0; y < width; ++y)
                {
                    if (x == 0 && y == 0)
                        continue;
                    currentRoom[0] = x;
                    currentRoom[1] = y;

                    int enemyCount = random.Next(Constants.IntValue("mapEnemyMin"), Constants.IntValue("mapEnemyMax") + 1);
                    for (int i = 0; i < enemyCount; ++i)
                    {
                        Minion enemy = new Minion(id);
                        do
                        {
                            enemy.Position = pathing.GetAvailablePosition(new int[] {1, CurrentRoom.VerticalSize / 2});
                            enemy.Room = new int[] { x, y };
                        }
                        while (enemyList.Contains(enemy));
                        enemyList.Add(enemy);
                    }
                    Console.WriteLine("    Room " + (length * y + x));
                }

            Console.WriteLine("Loading Quest Items...");
            SimpleList<int[]> takenRooms = new SimpleList<int[]>();
            // Place the associated quest items in the map
            foreach (QuestItem item in human.QuestItems)
            {
                if (item.Area == id)
                {
                    Boolean taken;
                    do
                    {
                        taken = false;
                        currentRoom[0] = generation.Next(0, length);
                        currentRoom[1] = generation.Next(0, width);
                        foreach (int[] spot in takenRooms)
                            if (currentRoom[0] == spot[0] && currentRoom[1] == spot[1])
                                taken = true;
                    }
                    while (currentRoom[0] + currentRoom[1] == 0 || taken);
                    takenRooms.Add(new int[] { currentRoom[0], currentRoom[1] });
                    int[] tile = pathing.GetAvailablePosition(new int[] {1, rooms[currentRoom[0], currentRoom[1]].VerticalSize / 2});
                    item.Location = new int[] { currentRoom[0], currentRoom[1], tile[0], tile[1] };
                }
            }

            currentRoom[0] = 0;
            currentRoom[1] = 0;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Encounter a minion while exploring
 /// </summary>
 private void Encounter(params Minion[] minion)
 {
     human.battling = 1;
     Enemy enemy;
     if (minion.Length == 0)
         enemy = new Minion(human.area);
     else
         enemy = minion[0];
     int result = Battle.Fight(human, enemy);
     human.battling = 0;
     if (result > 0)
         human += enemy.Reward;
     else if (result == 0)
     {
         try
         {
             File.Delete(directory + human.SaveFile);
         }
         catch (Exception) { }
         Console.BackgroundColor = ConsoleColor.Black;
         Console.ForegroundColor = ConsoleColor.White;
         ConsoleTools.CenterConsole(25, 2);
         Console.WriteLine("        You Lost!");
         ConsoleTools.Pause();
         Environment.Exit(0);
     }
     ConsoleTools.DrawDesign(ConsoleTools.mapGui);
     Draw();
     ConsoleTools.Draw(25, 9, Constants.CharValue("playerToken"));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Begins a practice battle
 /// </summary>
 public static void Action()
 {
     Human practiceHuman = new Human(999, 999);
     Enemy practiceEnemy = new Minion(-1);
     Battle.Fight(practiceHuman, practiceEnemy);
 }