我被困在一个
java作业中,我们需要制作一个Hangman游戏但是一个真正的基础游戏(它是
Java类的介绍).基本上我有一个人输入的单词,而另一个人必须猜测这个单词,但是他们没有看到这个单词,所以它就像这样显示它(如果这个单词是aardvark)
* * * * * * * *
然后用户输入一个字母,如果它的部分单词然后显示那些字母,例如:
输入字母:a
a * * * a * *
输入字母:k
a * * * a * k
输入字母:r
a a r * * a r k
所以…所以是的,我已经被困在这一段时间了,我真的需要帮助
谢谢
P.S:这是一个介绍类,所以我所知道的是循环(for,while,do while etc),if,if / else,switch语句等.
import java.util.Scanner;
public class ass_2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// public static final Comparator CASE_INSENSITIVE_ORDER;
int attempts = 10;
int wordLength;
boolean solved;
Scanner userInput = new Scanner(System.in);
System.out.println("OK Guessing Player ... turn around, while your friend enters the word to guess!\n");
System.out.println("Other Player ‐ Enter your word (letters only, no repeated letters and not case sensitive):");
String secretWord = userInput.next();
// 20 blank spaces WITH a for loop, we're smart!
for(int i = 1; i <= 20; i++)
System.out.print("\n");
Scanner userLetter = new Scanner(System.in);
String letter;
System.out.print("Word to date: ");
for (int i = 0; i < secretWord.length(); i++)
{
System.out.print("*");
}
while (attempts <= 10 && attempts > 0)
{
System.out.println("\nAttempts left: " + attempts);
System.out.print("Enter letter: ");
attempts--;
}
System.out.println("\n---------------------------");
System.out.println("Sorry you didn't find the mystery word!");
System.out.println("It was \"" + secretWord + "\"");
}
}