除了实际的游戏编码之外,我拥有一切。我想不出如何编写逻辑。我知道掷骰子的规则,但我(对于我的一生)想不出如何编码。我会使用 switch 语句,还是应该只使用 if 语句?如果您有任何很棒的示例(似乎通过剖析其他人的代码可以更好地学习)。另外,如果您确实发现任何错误,请告诉我。
private class PlayButtonHandler implements ActionListener
{
    public int rollDice()
    {
        int iDie = (int)(Math.random()*6) +1;
        return (iDie);
    }
    public void writeMessage(String sOutput)
    {
        jtaGame.append(sOutput);
    }
    public void actionPerformed(ActionEvent e)
    {
        rollDice();
        int iDie1 = new rollDice();
        int iDie2 = new rollDice();
        int iSum = iDie1 + iDie2;
        String sRoll = "You rolled " + iDie1 + "+" + iDie2 + "=" + iSum + ".\n";
        String sOutput = "";
        int iPoint = 0;
        switch(iSum)
        {
            case 7:
            case 11:
                    sOutput = sRoll + "You win because you got a natural :)";
                    break;
            case 2:
            case 3:
            case 12:
                    sOutput = sRoll + "You lost because you got a crap out :(";
            default:
                    sOutput = sRoll + "Point is: " + iSum + ".";
        }
    }
}