JAVA 프로그래밍

문제

WASD키를 이용하여 캐릭터를 상하좌우로 이동시키는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요 

프로그램의 실행순서 및 실행상태

1  public static void main( String[] args ) {  

2   int row = 0, column = 9;

 ■■■■■■■■■■■

3   while( ++row < 8 )
                            main()
scan  (Scanner) 
      row 0
   column  9 

4    System.out.print( "\n \033[44m   \033[0m              \033[44m   \033[0m" );
 ■                  ■

3   while( ++row < 8 )
                            main()
scan  (Scanner) 
      row
   column  9 

4    System.out.print( "\n \033[44m   \033[0m              \033[44m   \033[0m" );
 ■                  ■
 
       ...                        

 ■■■■■■■■■■■

5   char direction = 'w';

6   do {

 ■■■■■■■■■■■
■ ■
■ ■
■ ■
■ ■
■ ■
■ ■
■ ■
■■■■■■■■■■■

7    switch( direction ) {

8     case 'w': case 'W': 

9      row = ( row <= 2 ) ? 2 : row - 1;
                            main()
scan  (Scanner) 
      row 8
   column  9 
direction  'w' 

10      break;

 ■■■■■■■■■■■
■ ■
■ ■
■ ■
■ ■
■ ■
■ 옷 ■
■ ■
■■■■■■■■■■■
WASD와 [Enter]를 입력하세요: a

20   } while( ( direction == 'W' ) || ( direction == 'A' ) || ( direction == 'S' ) || ( direction == 'D' )

6   do {

 ■■■■■■■■■■■
■ ■
■ ■
■ ■
■ ■
■ ■
■ ■
■ ■
■■■■■■■■■■■

7    switch( direction ) {

8     case 'w': case 'W': 

11     case 'a': case 'A': 

12      column = ( column <= 3 ) ? 3 : column - 1;
                            main()
scan  (Scanner) 
      row  7 
   column 9
direction  'a' 

13      break;

 ■■■■■■■■■■■
■ ■
■ ■
■ ■
■ ■
■ ■
■ 옷 ■
■ ■
■■■■■■■■■■■
WASD와 [Enter]를 입력하세요: q

20   } while( ( direction == 'W' ) || ( direction == 'A' ) || ( direction == 'S' ) || ( direction == 'D' )

21  }


프로그램 코드

	import java.util.Scanner;
		
	public class CharacterMovement
	{
1		public static void main( String[] args ) { 	
			Scanner scan = new Scanner( System.in );
2			int row = 0, column = 9;
			System.out.print( " \033[44m                  \033[0m" );
3			while( ++row < 8 )
4				System.out.print( "\n \033[44m   \033[0m              \033[44m   \033[0m" );
			System.out.print( "\n \033[44m                  \033[0m" );
			
5			char direction = 'w';
6			do {
				System.out.print( " \033[" + row + ";" + column + "f  " );
7				switch( direction ) {
8					case 'w': case 'W': 
9						row = ( row <= 2 ) ? 2 : row - 1;
10						break;
11					case 'a': case 'A': 
12						column = ( column <= 3 ) ? 3 : column - 1;
13						break;
14					case 's': case 'S': 
15						row = ( 8 <= row ) ? 8 : row + 1;
16						break;
17					case 'd': case 'D': 
18						column = ( 14 <= column ) ? 14 : column + 1;
19						break;
				}
				System.out.print( " \033[" + row + ";" + column + "f옷" );
		
				System.out.print( " \033[10;1f \033[2KWASD와 [Enter]를 입력하세요: " );
				direction = scan.nextLine().charAt(0);
20			} while( ( direction == 'W' ) || ( direction == 'A' ) || ( direction == 'S' ) || ( direction == 'D' )
			        || ( direction == 'w' ) || ( direction == 'a' ) || ( direction == 's' ) || ( direction == 'd' ) );
			scan.close();
21		}
	}