JAVA 프로그래밍

문제

미로를 탐색해서 문을 찾아 탈출하는 문제입니다 이를 해결하는 다음 프로그램의 실행순서를 클릭하세요 
캐릭터 현재 위치의 줄 번호를 입력하세요: 3
캐릭터 현재 위치의 칸 번호를 입력하세요: 5
옷 문
옷문
옷
미로 맵 탈출 성공!

프로그램 코드

	import java.util.Scanner;
		
	public class MazeMove
	{
		private static int[][] map = {
		                 { 1, 1, 1, 1, 1, 1, 1 },
		                 { 1, 0, 0, 0, 1, 0, 1 },
		                 { 1, 0, 1, 0, 1, 1, 1 },
		                 { 1, 1, 1, 0, 1, 0, 1 },
		                 { 1, 0, 0, 0, 0, 0, 2 },
		                 { 1, 1, 1, 1, 1, 1, 1 }
		                };
		private static final int HEIGHT = 6, WIDTH = 7;
		
		private static int previousRow = -1, previousColumn = -1;
		private static void printMap( int row, int column ) {
			if ( ( row == previousRow ) && ( column == previousColumn ) )
				return;
		
			String[] symbol = { "  ", " \033[44m   \033[0m", " \033[34m문 \033[0m", "  " };
			for( int i = 0; i < HEIGHT; i++ ) {
				for( int j = 0; j < WIDTH; j++ ) {
					if( ( i == row ) && ( j == column ) )
						System.out.print( "옷" );
					else
						System.out.print( symbol[ map[i][j] ] );
				}
				System.out.println();
			}
		
			System.out.println();
			previousRow = row;
			previousColumn = column;
		}
		
		private static final int SUCCESS = 2;
		private static final int VISITED = 3;
		private static final int NOTVISITED = 0;
		
Fb		private static int move( int row, int column ) {
F1			if ( ( row < 0  ) || ( HEIGHT <= row ) || ( column < 0 ) || ( WIDTH <= column ) )
F2				return 0;
F3			else if ( map[row][column] == SUCCESS ) {
				printMap( row, column );
F4				return SUCCESS;
			}
F5			else if ( map[row][column] == NOTVISITED ) {
F6				map[row][column] = VISITED;
		
				printMap( row, column );
F7				if ( move( row + 1, column )
F8				                             == SUCCESS )
F9					return SUCCESS;
				printMap( row, column );
F10				if ( move( row, column + 1 )
F11				                             == SUCCESS )
F12					return SUCCESS;
				printMap( row, column );
F13				if ( move( row - 1, column )
F14				                             == SUCCESS )
F15					return SUCCESS;
				printMap( row, column );
F16				if ( move( row, column - 1 )
F17				                             == SUCCESS )
F18					return SUCCESS;
				printMap( row, column );
			}
		
F19			return 0;
Fe		}
1		public static void main( String[] args ) {
			Scanner scan = new Scanner( System.in );
			System.out.print( "캐릭터 현재 위치의 줄 번호를 입력하세요: " );
			int row = scan.nextInt();
			System.out.print( "캐릭터 현재 위치의 칸 번호를 입력하세요: " );
			int column = scan.nextInt();
		
2			if ( move( row, column )
3			                         == SUCCESS )
4				System.out.println( "\n미로 맵 탈출 성공!" );
5			else
6				System.out.println( "\n미로 맵 탈출 실패" );
			scan.close();
7		}
	}








 
실행 순서