求哪位DL能帮忙把这个代码以面向对象的形式写出来呀
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class hangman4 {
public static void main(String[] args) throws FileNotFoundException {
Scanner keyboard = new Scanner(System.in);
System.out.println("Player 1, please enter your word:");
String word;
word = keyboard.nextLine();
List playerGuesses = new ArrayList<>();
Integer wrongCount = 0;
while (true) {
printHangedMan(wrongCount);
if (wrongCount >= 6) {
System.out.println("you lose");
System.out.println("The word was: " + word);
break;
}
printWordState(word, playerGuesses);
if (!getPlayerGuess(keyboard, word, playerGuesses)) {
wrongCount++;
}
if (printWordState(word, playerGuesses)) {
System.out.println("You win!");
break;
}
}
}
private static void printHangedMan(Integer wrongCount) {
System.out.println("-------");
if (wrongCount >= 1) {
System.out.println(" o");
}
if (wrongCount >= 2) {
System.out.print("\\");
if (wrongCount >= 3) {
System.out.println(" /");
} else {
System.out.print("");
}
}
if (wrongCount >= 4) {
System.out.println(" |");
}
if (wrongCount >= 5) {
System.out.print("/");
if (wrongCount >= 6) {
System.out.println(" \\");
} else {
System.out.print(" ");
}
}
System.out.println("");
System.out.println("");
}
private static boolean getPlayerGuess(Scanner keyboard, String word, List playerGuesses) {
System.out.println("please guess a letter");
String letterGuess = keyboard.nextLine();
playerGuesses.add(letterGuess.charAt(0));
return word.contains(letterGuess);
}
private static boolean printWordState(String word, List playerGuesses) {
int correctCount = 0;
for (int i = 0; i < word.length(); i++) {
if (playerGuesses.contains(word.charAt(i))) {
System.out.println(word.charAt(i));
correctCount++;
} else {
System.out.print("-");
}
}
System.out.println();
return (word.length() == correctCount);
}
}