private void Form1_Load(object sender, EventArgs e) { prev = new MyRect(); trail = new Node(0, 0, Sides.Back); prev.Width = tileSize; dt = new System.Diagnostics.Stopwatch(); Text = currMethod.ToString(); blackPen = new Pen(Color.Black); greenPen = new Pen(Color.Green); bluePen = new Pen(Color.Blue); lightGreenPen = new Pen(Color.LightGreen); whitePen = new Pen(Color.White); graphics = CreateGraphics(); mapData = File.ReadAllLines("../../maps/Map (6).txt"); //mapData = File.ReadAllLines("../../Drew.txt"); //mapData = File.ReadAllLines("../../Новый текстовый документ.txt"); mapGraphics = new MyRect[mapData.Length][]; for (int i = 0; i < mapData.Length; i++) { mapData[i] = mapData[i].Replace(" ", ""); mapGraphics[i] = new MyRect[mapData[i].Length]; for (int j = 0; j < mapData[i].Length; j++) { mapGraphics[i][j] = new MyRect(xOffset + j * tileSize, yOffset + i * tileSize, tileSize - 5, mapData[i][j]); if (mapData[i][j] == 'A') { mapGraphics[i][j].Fill(graphics, blackPen, blackPen.Brush); } else { mapGraphics[i][j].Draw(graphics, blackPen); numOfFloorTiles++; } if (i == 21 && j == 29) { mapGraphics[i][j].Fill(graphics, blackPen, bluePen.Brush); cube = new Cube(i, j); cube.RedSidePos = Sides.Front; start = new Node(cube.X, cube.Y, cube.RedSidePos); numOfFloorTiles++; } //else if (mapData[i][j] == '4') //{ // graphics.FillMyRect(lightGreenPen.Brush, mapGraphics[i][j]); // numOfFloorTiles++; //} if (i == 1 && j == 14) { numOfFloorTiles++; target = new Node(i, j, Sides.Bottom); mapGraphics[i][j].Fill(graphics, blackPen, greenPen.Brush); } } } OpenNodes = new Priority_Queue.StablePriorityQueue <Node>(mapData.Length * mapData[0].Length * 6); cube = new Cube(start.X, start.Y); cube.RedSidePos = Sides.Front; cube.DrawCube(graphics); }
private void Map_Reload(int mapID) { start = null; graphics.Clear(Color.White); OpenNodes.Clear(); ClosedNodes.Clear(); resultMoves.Clear(); nodesMax = 0; numOfFloorTiles = 0; nodesVisited = 1; GC.Collect(); string path = $"../../maps/Map ({mapChosen}).txt"; mapData = File.ReadAllLines(path); Map_Modifier(); mapGraphics = new MyRect[mapData.Length][]; for (int i = 0; i < mapData.Length; i++) { mapGraphics[i] = new MyRect[mapData[i].Length]; for (int j = 0; j < mapData[i].Length; j++) { mapGraphics[i][j] = new MyRect(xOffset + j * tileSize, yOffset + i * tileSize, tileSize - 5, mapData[i][j]); if (mapData[i][j] == 'A') { mapGraphics[i][j].Fill(graphics, blackPen, blackPen.Brush); } else { mapGraphics[i][j].Draw(graphics, blackPen); numOfFloorTiles++; } if (i == 1 && j == 1) { mapGraphics[i][j].Fill(graphics, blackPen, bluePen.Brush); cube = new Cube(i, j); cube.RedSidePos = Sides.Front; start = new Node(cube.X, cube.Y, cube.RedSidePos); numOfFloorTiles++; } //else if (mapData[i][j] == '4') //{ // graphics.FillMyRect(lightGreenPen.Brush, mapGraphics[i][j]); // numOfFloorTiles++; //} if (i == 15 && j == 15) { numOfFloorTiles++; target = new Node(i, j, Sides.Bottom); mapGraphics[i][j].Fill(graphics, blackPen, greenPen.Brush); } } } File.WriteAllLines(path, mapData); OpenNodes = new Priority_Queue.StablePriorityQueue <Node>(mapData.Length * mapData[0].Length * 6); if (start == null) { cube = new Cube(21, 29); cube.RedSidePos = Sides.Front; start = new Node(cube.X, cube.Y, cube.RedSidePos); } cube.DrawCube(graphics); }