public bool keyPointSearch(StartForm startForm) { while (true) { Thread.Sleep(sleepTime); // 경로 == List<Tile> 형식 --> path[i].X : 행 , path[i].Y : 열 <-- 이렇게 접근 가능 rotation(startForm); if (!avoidingHazard(startForm)) // 위험지역 나오면 다시 로테이션부터 시작 { if (MapManager.CreatePath() == 1) { return(false); } continue; } detectingColorBlob(); // 오작동 했다면 bool moveCorrect = simInterface.moveForward(); set_cur(); startForm.display(); MapManager.getPath().RemoveAt(0); // 제대로 움직였으니 첫번째 패스 삭제 if (!moveCorrect) { if (!compensateMotion()) // 경로 재설정 { return(false); } } // 스팟에 도착했는지 검사 if (MapManager.getCurrent().First == MapManager.getSpot()[0].First && MapManager.getCurrent().Second == MapManager.getSpot()[0].Second) { // 스팟 지나가면 깃발 바꾸기 MapManager.getMap()[MapManager.getSpot()[0].First, MapManager.getSpot()[0].Second] = 5; MapManager.getSpot().RemoveAt(0); // 끝났으면 if (VerifyEnd()) { Console.WriteLine("Successed!!!"); break; } else { MapManager.CreatePath(); } } } return(true); }
public void rotation(StartForm startForm) { if (MapManager.getPath().Count == 0) { Console.WriteLine("path 0 err"); Application.ExitThread(); Environment.Exit(0); } int x = MapManager.getCurrent().First - MapManager.getPath()[0].X; int y = MapManager.getPath()[0].Y - MapManager.getCurrent().Second; int forward = 0; // 진행할 방향 if (x == 1 && y == 0) { forward = 0; } else if (x == 0 && y == 1) { forward = 1; } else if (x == -1 && y == 0) { forward = 2; } else if (x == 0 && y == -1) { forward = 3; } // 진행할 방향으로 헤드 돌리기 while (head != forward) { head = (head + 1) % 4; simInterface.rotation(); set_head(); // StartForm에 회전 디스플레이 띄우기 startForm.display(); Thread.Sleep(sleepTime); } }
private void MapPictureBox_Paint(object sender, PaintEventArgs e) { System.Drawing.Bitmap spot = new Bitmap(@"..\..\image\flag.png"); System.Drawing.Bitmap hazard = new Bitmap(@"..\..\image\hazard.png"); System.Drawing.Bitmap colorblob1 = new Bitmap(@"..\..\image\closed_box.png"); System.Drawing.Bitmap colorblob2 = new Bitmap(@"..\..\image\coin.png"); System.Drawing.Bitmap robot0 = new Bitmap(@"..\..\image\sion0.png"); System.Drawing.Bitmap robot1 = new Bitmap(@"..\..\image\sion1.png"); System.Drawing.Bitmap robot2 = new Bitmap(@"..\..\image\sion2.png"); System.Drawing.Bitmap robot3 = new Bitmap(@"..\..\image\sion3.png"); System.Drawing.Bitmap flag2 = new Bitmap(@"..\..\image\flag2.png"); int width = (mapPictureBox.Size.Width - 10) / MapManager.getMap().GetLength(1); int height = (mapPictureBox.Size.Height - 10) / MapManager.getMap().GetLength(0); // 맵 그리기 Rectangle Region; for (int i = 0; i < MapManager.getMap().GetLength(0); i++) { for (int j = 0; j < MapManager.getMap().GetLength(1); j++) { // 아무것도 없으면 : 0 위험지역 : 1 탐색 지점 : 2 입력 받은 컬러블럽 : 3 지나간 컬러블럽 : 4 지나간 탐색지점 : 5 switch (MapManager.getMap()[i, j]) { case 0: Region = new Rectangle(new Point(j * width, i * height), new Size(width, height)); e.Graphics.FillRectangle(new SolidBrush(Color.White), Region); e.Graphics.DrawRectangle(new Pen(Color.DarkGray), Region); break; case 1: Region = new Rectangle(new Point(j * width, i * height), new Size(width, height)); e.Graphics.DrawImage(hazard, Region); break; case 2: Region = new Rectangle(new Point(j * width, i * height), new Size(width, height)); e.Graphics.DrawImage(spot, Region); break; case 3: Region = new Rectangle(new Point(j * width, i * height), new Size(width, height)); e.Graphics.DrawImage(colorblob1, Region); break; case 4: Region = new Rectangle(new Point(j * width, i * height), new Size(width, height)); e.Graphics.DrawImage(colorblob2, Region); break; case 5: Region = new Rectangle(new Point(j * width, i * height), new Size(width, height)); e.Graphics.DrawImage(flag2, Region); break; } } } // 로봇 현재 위치 Region = new Rectangle(new Point(MapManager.getCurrent().Second *width, MapManager.getCurrent().First *height), new Size(width, height)); e.Graphics.DrawImage(robot0, Region); // 화살표 표시 switch (MapManager.getHead()) { case 0: e.Graphics.DrawImage(robot0, Region); break; case 3: e.Graphics.DrawImage(robot3, Region); break; case 2: e.Graphics.DrawImage(robot2, Region); break; case 1: e.Graphics.DrawImage(robot1, Region); break; } }