1

実際のゲームプレイ以外はすべてコード化されています。ロジックのコーディング方法が思いつきません。私はクラップスのルールを知っていますが、それをコーディングする方法を (一生) 思いつきません。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 + ".";
        }


    }

}
4

0 に答える 0