-4
모든 메서드가 올바르게 작동하지만 남은 추측 수를 출력하고 행맨을 기본 메서드에 인쇄하는 방법에 대해 혼란 스럽습니다. 나는 printHangman
하지만행맨 (Hangman) 메서드 호출
public class Hangman2
{
public static void main(String[] args)
{
System.out.println("Welcome to HangMan Player 1, Please enter a word. Player 2, Please close your eyes: ");
Scanner stdin = new Scanner(System.in);
String secretWord = stdin.next();
for (int x = 1; x <= 100; x++)
{
System.out.println(" ");
}
System.out.println("Clearing Screen");
System.out.println("The current partial word is: ");
String initialWord = createPartialWord(secretWord);
System.out.println("");
System.out.println("The current hangman picture is: ");
}
public static String createPartialWord(String secretWord)
{
String newsecretWord = "";
int wordLength = secretWord.length();
while (wordLength > 0)
{
newsecretWord = newsecretWord + "-";
System.out.print("-");
wordLength--;
}
return newsecretWord;
}
public static String replaceChar(String word, char c, int i)
{
if(0 < i && i < word.length())
{
return word.substring(0, i) + c + word.substring(i + 1);
}
return word;
}
public static String updatePartialWord(String partial, String secret, char c)
{
for (int i = 0; i <= secret.length(); i++)
{
if (secret.charAt(i) == c)
{
return replaceChar(partial, c , i);
}
}
return partial;
}
public static void printHangman(int guessLeft)
{
String HEAD = " ";
String BODY = " ";
String LEGS = " ";
String LEFTARM = " ";
String RIGHTARM = " ";
System.out.println("_____");
System.out.println("| |");
if (guessLeft < 6)
{
HEAD = "()";
}
System.out.println("| " + HEAD);
if (guessLeft < 5)
{
BODY = "||";
}
if (guessLeft < 4)
{
LEFTARM = "\\";
}
if (guessLeft < 3)
{
RIGHTARM = "/";
}
System.out.println("| " + LEFTARM + BODY + RIGHTARM);
if (guessLeft < 2)
{
LEGS = "/";
}
if (guessLeft < 1)
{
LEGS += "\\";
}
System.out.println("| " + LEGS);
System.out.println("|_____\n\n\n\n");
}
}
''모든 메소드가 올바르게 작동합니다. '''실제로 메소드를 호출 * 할 수 없다면 어떻게 알 수 있습니까? ''추측 카운터없이 호출하는 방법을 모르겠습니다. ''- Java에서 모든 메서드를 호출하는 것과 같은 방식입니다. 메서드가'int'를 필요로한다면'int'를 주어야합니다. 사용자가 시도한 추측 수 (및 재생중인 게임에 대한 잠재적 인 정보)를 추적해야합니다. – David
다른 메서드는 내가 호출했기 때문에 작동하지만'printHangman'을 호출 할 수 없었지만 코드가 교수로부터 제공 되었기 때문에 작동한다는 것을 알았습니다. 그리고 네,'main()'에서 시도한 추측을 어떻게 추적합니까? – MikeG
실제로 그것을 호출하는 방법을 알아 냈습니다 ... 추측 추적기가 필요합니다. – MikeG