public static void Main(string[] args) { GameStart: ThisMap = new Map(@"C:\Users\brgoz\Documents\GitHub\Sokoban\Sokoban.Console\maps\map1"); while (!ThisMap.IsWon) { System.Console.Clear(); System.Console.WriteLine("{0},{1}", ThisMap.PlayerTile.X, ThisMap.PlayerTile.Y); System.Console.Write(ThisMap.Render()); var key = System.Console.ReadKey(); switch (key.Key) { case ConsoleKey.LeftArrow: if (!Move(Directions.Left)) System.Console.Beep(); break; case ConsoleKey.UpArrow: if (!Move(Directions.Up)) System.Console.Beep(); break; case ConsoleKey.RightArrow: if (!Move(Directions.Right)) System.Console.Beep(); break; case ConsoleKey.DownArrow: if (!Move(Directions.Down)) System.Console.Beep(); break; } } System.Console.WriteLine("YOU WIN!!!!! Play again (y/n)?"); if (System.Console.ReadKey().Key == System.ConsoleKey.Y) goto GameStart; }
private static List<Tile> LoadFromFile(string filename, Map thisMap) { List<Tile> result = new List<Tile>(); List<string> lines = System.IO.File.ReadLines(filename).ToList(); thisMap.Width = lines.Max(x => x.Length); thisMap.Height = lines.Count; for (int y = 0; y < thisMap.Height; y++) { for (int x = 0; x < thisMap.Width; x++) { char tileChar = lines[y][x]; result.Add(new Tile(x, y, tileChar)); } } return result; }