Вопрос

I'm trying to make a random dungeon generator using this website as help but the code doesn't seem to work anymore so I'mtrying to fix it and now I'm getting a C# Identifier expected error

public Point PickRandomCellAndMarkItVisited()
{
   Random rnd = new Random();
   Point randomLocation = new Point(rnd.Next(1, 10), rnd.Next(1, 10));
   this.[randomLocation] = true;
   return randomLocation;
}
Это было полезно?

Решение

Based on your code and the tutorial, it looks like you're trying to mark a random cell as visited. I think you should try this instead:

public class Map
{

    private readonly bool[, ] cells;    
    public Point PickRandomCellAndMarkItVisited()
    {
       Random rnd = new Random();
       Point randomLocation = new Point(rnd.Next(1, 10), rnd.Next(1, 10));
       this.cells[randomLocation.X, randomLocation.Y] = true;
       return randomLocation;
    }
}

This will pick a random cell from the grid and mark the corresponding boolean value as true.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top