1

我正在创建一个轮盘赌游戏,并且正在测试。

我有一个 Game 类,可以构建并准备好一切。它还构建了一个名为Passenger57 的测试播放器,它只下注黑色。

不知何故,我无法让 Game 类调用 Passenger57 并让它下注。该表返回一个空的投注列表!

我在看什么?

游戏

package Roulette;

import java.util.Iterator;
import java.util.ListIterator;
import java.util.TreeSet;

public class Game {

public static void main(String[] args) {
    Table table = new Table();
    BinBuilder bb = new BinBuilder();
    Passenger57 p57 = new Passenger57(table);
    p57.placeBets();    // <-- This guy is not doing much!
// ETC ETC//

乘客57

package Roulette;

public class Passenger57 {

public Table table;
public Outcome black;
public Bet bet;

public Passenger57(Table table){
    this.table = new Table();
    this.black = new Outcome("Black", 1);

}

void placeBets(){
    Bet bet = new Bet(100, black);
    table.placeBet(bet);
}

 void win(Bet bet){
    System.out.println("You've won: " + bet.winAmount());
}

 void lose(Bet bet){
     System.out.println("You lost!"+bet.loseAmount()+ ":/");

}


}

非常感谢您帮助初学者跌跌撞撞!

以防万一你需要它

桌子

package Roulette;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

public class Table {

public int limit = 1000;
public LinkedList<Bet> bets;

public Table(){
    bets = new LinkedList<Bet>();
}

public  boolean isValid(Bet bet){
    int sum = 0;
    for(Bet bett: bets){
        sum += bett.amountBet;
    }
    return (sum>limit);
}

public void placeBet(Bet bet){
        this.bets.add(bet);
}

ListIterator<Bet> iterator(){
    return bets.listIterator();

}
}
4

2 回答 2

8

在类Passenger57你应该改变

public Passenger57(Table table){
    this.table = new Table(); // <- here is your fault
    black = new Outcome("Black", 1); 
}

public Passenger57(Table table){
    this.table = table;
    black = new Outcome("Black", 1); 
}
于 2013-04-28T12:14:34.787 回答
2

代替

this.table = new Table()

经过

this.table = table in Passenger57(Table table)
于 2013-04-28T12:14:09.020 回答