public Room(GameSetup gs, int roomCount) { Name = gs.RoomNames[roomCount]; Description = gs.RoomDescriptions[roomCount]; Items = new List <Item>(); Enemies = new List <Enemy>(); if (gs.ItemNames[roomCount] != "") { Items.Add(new Item(gs.ItemNames[roomCount], gs.ItemDescriptions[roomCount], gs.ItemDamages[roomCount])); } if (gs.EnemyNames[roomCount] != "") { Enemies.Add(new Enemy(gs.EnemyNames[roomCount], gs.EnemyHealth[roomCount], gs.EnemyDamage[roomCount])); } }
public void Setup() { Console.Clear(); GameSetup gs = new GameSetup(); GameSetup = gs; string[] roomNamePath = Directory.GetFiles(@"Project/Assets/"); for (int i = 0; i < roomNamePath.Length; i++) { using (StreamReader sr = File.OpenText(roomNamePath[i])) { string line = ""; while ((line = sr.ReadLine()) != null) { switch (i) { case 0: int damage; Int32.TryParse(line, out damage); gs.EnemyDamage.Add(damage); break; case 1: int health; Int32.TryParse(line, out health); gs.EnemyHealth.Add(health); break; case 2: gs.EnemyNames.Add(line); break; case 3: int damageWeapon; Int32.TryParse(line, out damageWeapon); gs.ItemDamages.Add(damageWeapon); break; case 4: gs.ItemDescriptions.Add(line); break; case 5: gs.ItemNames.Add(line); break; case 6: gs.RoomDescriptions.Add(line); break; case 7: gs.RoomNames.Add(line); break; } } } } Console.WriteLine("Welcome to Castle Grimtol!"); Console.WriteLine("What is your name?"); string playerName = Console.ReadLine(); Player player = new Player(playerName); Console.Clear(); bool valid = false; while (!valid) { Console.WriteLine($"Is the Castle 5x5, 6x6, or 7x7{player.Name}?"); Console.WriteLine("Just type 5, 6, or 7 to choose!"); string roomCountString = Console.ReadLine(); int roomCount; if (Int32.TryParse(roomCountString, out roomCount)) { if (roomCount < 5 || roomCount > 7) { continue; } CurrentPlayer = player; Rooms = new Room[roomCount, roomCount]; int loop = roomCount * roomCount; Random rand = new Random(); for (int i = 0; i < loop; i++) { if (i == 0) { Rooms[roomCount - 1, (roomCount - 1) / 2] = new Room(gs, i); continue; } bool roomValid = false; while (!roomValid) { var index1 = rand.Next(0, roomCount); var index2 = rand.Next(0, roomCount); if (Rooms[index1, index2] == null) { Rooms[index1, index2] = new Room(gs, i); roomValid = true; } } } CurrentRoom = Rooms[roomCount - 1, (roomCount - 1) / 2]; bool notStart = true; while (notStart) { int endY = rand.Next(0, roomCount); int endX = rand.Next(0, roomCount); if (Rooms[endY, endX].Equals(CurrentRoom)) { continue; } else { EndingRoom = Rooms[endY, endX]; notStart = false; } } Console.Clear(); valid = true; } else { Console.Clear(); Console.WriteLine($"{roomCountString} is not a valid number! Enter a valid number!"); } } }