Ejemplo n.º 1
0
 public static Block From(string blockDefinition)
 {
     var closed =
     (blockDefinition[0] == '(' ? Walls.Left : Walls.Nothing)
     + (blockDefinition[2] == ')' ? Walls.Right : Walls.Nothing)
     + (blockDefinition[1] == '_' ? Walls.Bottom : Walls.Nothing)
     + (blockDefinition[1] == '^' ? Walls.Top : Walls.Nothing)
     + (blockDefinition[1] == 'O' ? Walls.Top + Walls.Bottom : Walls.Nothing);
       var block = new Block { Closed = closed };
       Tools.Assert<ArgumentException>( block.ToString() == blockDefinition, "Unexpected block definition {0}", blockDefinition );
       return block;
 }
Ejemplo n.º 2
0
        public static Labyrinth From(string labyrinthDefinition)
        {
            var rows = labyrinthDefinition.Split('\n').ToList().FindAll(row => row.Length > 0);
              var height = rows.Count;
              var width = (rows[0].Length+1)/4;

              Tools.Assert<ArgumentException>( (width*4-1)*height == rows.Select(row => row.Length).Sum(), "Unexpected labyrinth definition {0}", labyrinthDefinition );

              var blocks = new Block[width,height];
              for(var y = 0; y < height; y++)
            for(var x = 0; x < width; x++)
              blocks[x,y] = Block.From(rows[y].Substring(x*4,3));

              return new Labyrinth { Width = width, Height = height, _block = blocks };
        }