学校给我的任务是制作一个骰子游戏,用户可以在其中改变骰子的眼睛,他们给我的唯一提示是使用 ASCII 表。
到目前为止,这是我的代码,我正在碰壁,因为我如何使数字成为用户的输入(我不是很有创意):
System.out.println("Which character should be used as the eye of the dice:");
char eyeDice = input.next().charAt(0);
System.out.println(eyeDice);
int Dice;
Dice = (int)(Math.random()* 6 + 1);
while (Dice < 6) {
Dice = (int)(Math.random()* 6 + 1);
System.out.println(Dice);
}
代码的输出如下所示:
Which character should be used as the eye of the dice:
$
$
1
4
1
1
1
1
4
1
2
2
6
Process finished with exit code 0
这就是它最终的样子:
Which character should be used as the eye of the dice:
#
#
#
# #
#
# #
# #
# #
# #
# #
Process finished with exit code 0
任何正确方向的提示或提示将不胜感激!
倚天杖
12345678_0001
慕少森
相关分类