lundi 28 mars 2016

action based on random number

I'm making a game of yahtzee and I want my code to propose the best choice based on the random numbers thrown. my question is how to make it that when I roll for example 5 one's that it proposes I select the yahtzee box.

this is my code for now

button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder sb = new StringBuilder("Rolled: ");

                for (int i=0; i<chosenDiceNumber; i++) {
                    sb.append(getNextValue()).append(", ");
                }
                sb.delete(sb.length()-2, sb.length());
                result.setText(sb.toString());
            }
        });
        add(result);




Aucun commentaire:

Enregistrer un commentaire