- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个轮盘游戏,我为插槽创建了一个数组列表,它们已在有序列表中定义,共有 38 个插槽,其位置(0-37)、颜色和数字。
在“旋转方法”中,我尝试从轮子集合/列表中选择一个随机起始插槽,然后根据延迟功能旋转一些插槽。
如何从我的集合中选择一个随机槽来开始此过程?
我的 Collection
List<Slot> wheel = new ArrayList<Slot>();
GameEngine gameEngine;
public GameEngineImpl() {
Color colorArray[] = new Color[] { Color.GREEN00, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.GREEN0, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED,
Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED, Color.BLACK, Color.RED };
int numberArray[] = new int[] { 00, 27, 10, 25, 29, 12, 8, 19, 31, 18, 6, 21, 33, 16, 4, 23, 35, 14, 2, 0, 28,
9, 26, 30, 11, 7, 20, 32, 17, 5, 22, 34, 15, 3, 24, 36, 13, 1 };
for (int position = 0; position < 38; position++) {
wheel.add(new SlotImpl(position, colorArray[position], numberArray[position]));
}
}
旋转方法
@Override
public void spin(int initialDelay, int finalDelay, int delayIncrement) {
Slot slot;
while (initialDelay < finalDelay) {
// TODO selecting a random starting slot on the wheel
}
}
// Delay function
delay(delayIncrement);
// Increase increment
initialDelay += delayIncrement;
}
}
// Method to delay spinning
private void delay(int delay) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
最佳答案
您可以使用Random::nextInt
用于生成随机整数:
int random = new java.util.Random().nextInt(38);
//nextInt: int value between 0 (inclusive) and the specified value (exclusive)
要迭代元素,您可以使用流或 for 循环。以下是流的示例:
wheel.subList(random, 37).stream().forEach(e -> {
// e is the element
});
for
循环:
for(int i = random; i < 38; i++) {
var e = wheel.get(i); // e is the element
}
关于java - 如何从有序列表中选择随机起始位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55555446/
我在尝试生成具有“价格”轴和“量”轴的图表时遇到问题,类似于 example given 中的图表。在 Highstock 网站上。它可以很好地显示成交量轴,但不能显示价格。 在尝试确定问题的原因时,
起始 - HTML
在我的 HTML 项目中,我试图提及 标签。但是,VS Code 将其解释为实际的 标签,它会导致奇怪的事情发生。有人有办法解决这个问题吗?预先感谢您! 最佳答案 使用<代替 . 顺便说一下,使
起始 - HTML
在我的 HTML 项目中,我试图提及 标签。但是,VS Code 将其解释为实际的 标签,它会导致奇怪的事情发生。有人有办法解决这个问题吗?预先感谢您! 最佳答案 使用<代替 . 顺便说一下,使
The allocation function attempts to allocate the requested amount of storage. If it is successful, i
这是我的Program.cs: public static void Main(string[] args) { var host = new WebHostBuilder()
我希望我的应用程序独立于操作系统。因此,我的 config.properties 和日志文件存储在资源文件夹中,我通过相对路径获取这些资源。这是我的项目结构。 这是我的 AppConfig 类: pu
(前言:这是我在 Stack Overflow 上提出的第一个与音频相关的问题,因此我会尽力用最好的措辞来表达。欢迎编辑。) 我正在创建一个允许用户循环播放音乐的应用程序。目前,我们的原型(proto
我有一个 Pandas DataFrame,我想将其用作 Scrapy Start URL,函数 get_links 打开一个到 DataFrame 的 xlsx,其中有一个我想在其上运行蜘蛛的 Co
我有几个大的 DTD 文件。我用过 trang将它们转换为 XSD 文件,这样我就可以轻松地从 JAXB 和其他实用程序中使用它。但是,生成的 XSD 文件的所有声明元素都位于顶层。这意味着任何元素都
是否有任何工具可以将文件从给定的起始偏移量复制到给定的(结束)偏移量。我还想通过运行 md5sum 确认该工具已正确复制指定的字节。像这样的东西 1) Copy source file star
所以,我有一个程序,我可以使用 Path2D 对象将形状添加到 JPanel,然后我可以单击并拖动它们。我想要做的是能够找到药物后形状的最终 X 和 Y 坐标。坐标必须是左上角坐标。有什么想法吗? /
我是一名优秀的程序员,十分优秀!