Advertisement
pol9na

Untitled

Mar 23rd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApp6
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             char[,] map = ReadMap("map1");
  15.  
  16.         }
  17.         static void DrawMap(char[,] map)
  18.         {
  19.             for (int i = 0; i < map.GetLength(0); i++)
  20.             {
  21.                 for (int j = 0; j < map.GetLength(1); j++)
  22.                 {
  23.                     Console.Write(map[i, j]);
  24.                 }
  25.                 Console.WriteLine();
  26.  
  27.             }
  28.         }
  29.  
  30.             static char[,] ReadMap(string mapName)
  31.             {
  32.                 string[] newFile = File.ReadAllLines($"Maps/{mapName}.txt");
  33.                 char[,] map = new char[newFile.Length, newFile[0].Length];
  34.  
  35.                 for (int i = 0; i < map.GetLength(0); i++)
  36.                 {
  37.                     for (int j = 0; j < map.GetLength(1); j++)
  38.                     {
  39.                         map[i, j] = newFile[i][j];
  40.                     }
  41.                    
  42.                 }
  43.             return map;
  44.         }
  45.  
  46.         }
  47.  
  48.     }
  49. /*
  50. Необработанное исключение: System.IndexOutOfRangeException: Индекс находился вне границ массива.
  51.    в System.String.get_Chars(Int32 index)
  52.    в ConsoleApp6.Program.ReadMap(String mapName) в C:\Users\User\source\repos\ConsoleApp6\ConsoleApp6\Program.cs:строка 39
  53.    в ConsoleApp6.Program.Main(String[] args) в C:\Users\User\source\repos\ConsoleApp6\ConsoleApp6\Program.cs:строка 14*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement