gpt4 book ai didi

java - 改变骰子的眼睛

转载 作者:行者123 更新时间:2023-12-02 01:55:10 24 4
gpt4 key购买 nike

学校给我布置了一个骰子游戏,用户可以改变骰子的眼睛,他们给我的唯一提示是使用 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

任何正确方向的提示或提示将不胜感激!

最佳答案

计算机没有附带将数字“4”转换为 ascii 绘图的代码。

你必须自己写这个。我建议把这些画在一张纸上。在您的 java 代码中,您可以有一堆 if/elseif 语句,每个语句对应 6 个面。每个 block 将打印 3 行。首先锁定用于眼睛的角色,然后努力使其成为用户稍后可以配置的内容。

以下是帮助您入门的部分内容:

if (dieRoll == 5) {
System.out.println("* *");
System.out.println(" * ");
System.out.println("* *");
} else if (dieRoll == 6) {
// you figure it out from here...

关于java - 改变骰子的眼睛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com