Ejemplo n.º 1
0
        ///Public Static Methods
        //ASCIIDisplay method will convert grid data into a Console ASCII visualisation.
        public static void ASCIIDisplay(IGrid _grid)
        {
            //Create the header.
            string output = "+" + new string(Enumerable.Range(0, _grid.cols).SelectMany(x => "---+").ToArray()) + "\n";

            //Loop through grid and add values.
            foreach (List <Cell> row in _grid.grid)
            {
                //Begin the display row.
                string top = "|", bottom = "+";

                //Add each cell to the display row.
                foreach (Cell cell in row)
                {
                    //Top of cell.
                    string body = _grid.CellContents(cell);
                    if (cell.IsLinked(cell.neighbours[(int)DIRECTION.EAST]))
                    {
                        top += body + " ";
                    }
                    else
                    {
                        top += body + "|";
                    }

                    //Bottom of cell.
                    if (cell.IsLinked(cell.neighbours[(int)DIRECTION.SOUTH]))
                    {
                        bottom += "   +";
                    }
                    else
                    {
                        bottom += "---+";
                    }
                }

                //Add row to the output.
                output += top + "\n" + bottom + "\n";
            }

            //Output the result.
            Console.WriteLine(output);
        }