作为初学者,我正在研究轮盘赌游戏,但我被卡住了。
我有一个选择的Bin对象
Bin(){
outcomes = new TreeSet<Outcome>();
}
我有一个Bet对象
public Bet(int amount, Outcome outcome){
this.outcome = outcome;
this.amountBet = amount;
}
包含一个Outcome对象。
public Outcome(String name, int odds){
this.name = name;
this.odds = odds;
}
目标 - 遍历 Bin 中的所有结果并将 Bin 中的 Outcome.name 与 bets.outcome.name 进行比较。如果我们有马赫,就会有胜利。如果没有,那就有损失。
所以,这是我的代码:
System.out.println(bin.toString());
System.out.println(table.bets.toString());
System.out.println(black.toString());
ListIterator<Bet> i = table.bets.listIterator();
Iterator<Outcome> b = bin.outcomes.iterator();
while(i.hasNext()) {
while(b.hasNext()){
if(i.next().outcome.equals(b.next())){
System.out.println("Win!");
}
else System.out.println("Win :/");
}
}
问题:即使输出显示为:
[8 (35:1)]['7, 71' (17:1)]['8, 81' (17:1)][5, 53 (17:1)][8, 83 (17:1)][7 (11:1)][4, 41,
43, 44 (8:1)][5, 51, 53, 54 (17:1)][7, 71, 73, 74 (8:1)][8, 81, 83, 84 (17:1)][4, 5,6,
7, 8, 9 (5:1)][7, 8,9, 10, 11, 12 (5:1)][1 (2:1)][11 (2:1)][Low (1:1)][Even (1:1)]
[Black (1:1)]
[10 on [Black (35:1)]]
Black (35:1)
No :/
Exception in thread "main" java.util.NoSuchElementException
at java.util.LinkedList$ListItr.next(Unknown Source)
at Roulette.Game.main(Game.java:37)
似乎它
a)不遍历 Bin 中的所有结果 b)当它找到匹配项时,它不会评估是否为真。
你能看到我做错了什么吗?
非常感谢你的帮助!!
如果文字太多或太少,我很抱歉。以防万一您需要查看其他课程中发生了什么,它们是:
游戏类 https://gist.github.com/anonymous/5473187
表类 https://gist.github.com/anonymous/5473188
投注类 https://gist.github.com/anonymous/5473189
结果类 https://gist.github.com/anonymous/5473191
Bin类 https://gist.github.com/anonymous/5473192
BinBuilder 类 https://gist.github.com/anonymous/5473197
车轮类 https://gist.github.com/anonymous/5473200
非随机类 https://gist.github.com/anonymous/5473202
乘客 57 类https://gist.github.com/anonymous/5473207
编辑:删除 System.out.println() 并更新了新结果。