2013-11-15 3 views
0

나는 나의 미로를 가지고 북동쪽의 서쪽으로 갈 수 있지만 어떻게 ne 또는 sw으로 움직일 수 있습니까? 가능한 경우 내 코드를 사용하여 예제를 제공 할 수 있습니까? 덕분에 그 4x4 배열.대각선 방향으로 2 차원 배열로 이동

//Begin user dialog 
    System.out.println("Welcome"); 
    input =""; 
    while(!input.equals("quit")) 
    { 
     System.out.println(map.rooms[row][col].name); 
     System.out.print(">"); 
     input = scan.nextLine().toLowerCase(); 

     switch (input) { 
      case "n": 
       if(map.rooms[row][col].isValidExit("n")) 
        row--; 
       else 
        System.out.println("You cant go that way"); 
       break; 
      case "s": 
       if(map.rooms[row][col].isValidExit("s")) 
        row++; 
       else 
        System.out.println("You cant go that way"); 
       break; 
      case "w": 
       if(map.rooms[row][col].isValidExit("w")) 
        col--; 
       else 
        System.out.println("You cant go that way"); 
       break; 
      case "e": 
       if(map.rooms[row][col].isValidExit("e")) 
        col++; 
       else 
        System.out.println("You cant go that way"); 
       break; 

답변

1

당신이해야 할 사용자 인터페이스 귀하의 의견

while(!input.equals("quit")) 
{ 
    System.out.println(map.rooms[row][col].name); 
    System.out.print(">"); 
    input = scan.nextLine().toLowerCase(); 
    char[] inputArray = input.toCharArray(); 

    for(char c : inputArray){ 

    switch (input) { 
     case "n": 
      if(map.rooms[row][col].isValidExit("n")) 
       row--; 
      else 
       System.out.println("You cant go that way"); 
      break; 
     case "s": 
      if(map.rooms[row][col].isValidExit("s")) 
       row++; 
      else 
       System.out.println("You cant go that way"); 
      break; 
     case "w": 
      if(map.rooms[row][col].isValidExit("w")) 
       col--; 
      else 
       System.out.println("You cant go that way"); 
      break; 
     case "e": 
      if(map.rooms[row][col].isValidExit("e")) 
       col++; 
      else 
       System.out.println("You cant go that way"); 
      break; 
+0

죄송 새. 그것을 볼 것입니다하지만 간단한 대답도 도움이됩니다. – user2995304

+0

더 간단 할 수는 없지만 코드에 두 줄을 추가했습니다. P – pedrito

+0

하지만 내 질문은 무엇을 의미합니까? 문자열을 char로 변환하는 것으로부터 찾고 있습니다. 나에게 코드 줄을 주셔서 감사하지만 나는 이것을 이해하고 메신저로 배우고 싶다. :). 내 코드에 char을 넣은 것처럼? – user2995304

0

예 북동쪽를 숯불 분석 : 숯불 구문 분석 무엇 자바에

case "ne": 
     if(map.rooms[row][col].isValidExit("ne")) { 
      col++; 
      row--; 
     } 
     else { 
      System.out.println("You cant go that way"); 
     } 
     break; 
+0

다음과 같은 경우 중괄호가 필요합니다. case "ne": if (map.rooms [row] [col] .isValidExit ("ne")) ** {** col ++; 행 -; **} ** else System.out.println ("그럴 수 없어요"); 휴식; – Melquiades

+0

죄송합니다. 깜빡했습니다. – kai

관련 문제