Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- /**
- * Write a description of class Dice here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Dice
- {
- // instance variables - replace the example below with your own
- private Random mDice;
- private int mSides;
- /**
- * Constructor for objects of class Dice
- */
- public Dice()
- {
- mDice = new Random();
- }
- public Dice(int sides)
- {
- mSides = sides;
- }
- public int rollDice()
- {
- if(mSides <= 0) {
- // Om mSides inte har något lagrat värde eller om du anger siffran
- // 0 eller ett negativt tal, så får tärningen automatiskt 6 sidor.
- return mDice.nextInt(6) + 1;
- }
- else {
- // Plocka in värdet från mSides;
- return mDice.nextInt(mSides) + 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement