java简单赋值_简单的Java Hangman赋值

我被困在一个

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 + "\"");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值