private void GenerateWorld() { int currentX = 0, currentY = 0; List <int> xPositions = new List <int>(), yPositions = new List <int>(); // create locations foreach (IAreaType aT in this.Story.getAreas()) { List <ILocation> newLocs = StoryGenerationClass.Instance.getLocation(aT.getName(), aT.getValue()); foreach (ILocation l in newLocs) { l.setLocation(currentX, currentY); locations.Add(l); xPositions.Add(currentX); yPositions.Add(currentY); bool bNotFound = true, bLocationAvailable = false; int lastPosition = xPositions.Count - 1; while (!bLocationAvailable) { // get new location int direction = StoryGenerationClass.Instance.getRandomNumber(4); if (direction == 0) // up { bNotFound = true; for (int i = 0; i < xPositions.Count; i++) { if (xPositions[i] == currentX && yPositions[i] == currentY + 1) { bNotFound = false; direction++; } } if (bNotFound) { currentY += 1; bLocationAvailable = true; } } if (direction == 1) // down { bNotFound = true; for (int i = 0; i < xPositions.Count; i++) { if (xPositions[i] == currentX && yPositions[i] == currentY - 1) { bNotFound = false; direction++; } } if (bNotFound) { currentY--; bLocationAvailable = true; } } if (direction == 2) // right { bNotFound = true; for (int i = 0; i < xPositions.Count; i++) { if (xPositions[i] == currentX + 1 && yPositions[i] == currentY) { bNotFound = false; direction++; } } if (bNotFound) { currentX += 1; bLocationAvailable = true; } } if (direction == 3) // left { bNotFound = true; for (int i = 0; i < xPositions.Count; i++) { if (xPositions[i] == currentX - 1 && yPositions[i] == currentY) { bNotFound = false; direction++; } } if (bNotFound) { currentX--; bLocationAvailable = true; } } if (direction > 3) // no space available { lastPosition--; if (lastPosition == 0) { bLocationAvailable = true; } currentX = xPositions[lastPosition]; currentY = yPositions[lastPosition]; } } } } // add target item to last position if (Story.getPlot().getModifier().ToLower() == "creature") { locations[locations.Count - 1].addNewCreature(Story.getTargetName(), null, null, 10); } else if (Story.getPlot().getModifier().ToLower() == "item") { locations[locations.Count - 1].addNewItem(Story.getTargetName(), null, null, 10); } // set positions x = 0; y = 0; // set player start currentLocation = locations[0]; player = new PlayerCharacter(Story.getMainCharacters()[0]); // update map updateMap(); }