Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.dorbird;
- import java.util.Random;
- public class Dice {
- enum Color {RED,BLUE}
- Color owner = Color.RED;
- DiceFace frontSide = DiceFace.ONE;
- DiceFace backSide = DiceFace.SIX;
- DiceFace upSide = DiceFace.TWO;
- DiceFace downSide = DiceFace.FIVE;
- DiceFace rightSide = DiceFace.FOUR;
- DiceFace leftSide = DiceFace.THREE;
- public String[] display(){
- String[] out = new String[5];
- out[0] = String.format("\u2591\u2502%s\u2502\u2591", upSide.ordinal());
- out[1] = "\u2500\u253C\u2500\u253C\u2500";
- out[2] = String.format("%s\u2502%s\u2502%s", leftSide.ordinal(), frontSide.ordinal(), rightSide.ordinal());
- out[3] = "\u2500\u253C\u2500\u253C\u2500";
- out[4] = String.format("\u2591\u2502%s\u2502%s", downSide.ordinal(),backSide.ordinal());
- return out;
- }
- public void print(){
- String[] sa = display();
- for (String s : sa) {
- System.out.println(s);
- }
- }
- public Dice roll(){
- Random r = new Random();
- int frontSide = r.nextInt(6) + 1;
- int upSide;
- do {
- upSide = r.nextInt(6) + 1;
- }while (upSide == frontSide || upSide == 7-frontSide);
- return this;
- }
- public Dice rotateXCW() {
- DiceFace tmp = upSide;
- upSide = frontSide;
- frontSide = downSide;
- downSide = backSide;
- backSide = tmp;
- return this;
- }
- public Dice rotateXACW() {
- DiceFace tmp = upSide;
- upSide = backSide;
- backSide = downSide;
- downSide = frontSide;
- frontSide = tmp;
- return this;
- }
- public Dice rotateYCW() {
- DiceFace tmp = frontSide;
- frontSide = rightSide;
- rightSide = backSide;
- backSide = leftSide;
- leftSide = tmp;
- return this;
- }
- public Dice rotateYACW() {
- DiceFace tmp = frontSide;
- frontSide = leftSide;
- leftSide = backSide;
- backSide = rightSide;
- rightSide = tmp;
- return this;
- }
- public Dice rotateZCW() {
- DiceFace tmp = upSide;
- upSide = leftSide;
- leftSide = downSide;
- downSide = rightSide;
- rightSide = tmp;
- return this;
- }
- public Dice rotateZACW() {
- DiceFace tmp = upSide;
- upSide = rightSide;
- rightSide = downSide;
- downSide = leftSide;
- leftSide = tmp;
- return this;
- }
- }
- /////////////////////////////////////////////////////
- package de.dorbird;
- public enum DiceFace {
- BLANK, ONE ,TWO, THREE,FOUR, FIVE, SIX;
- public static DiceFace getOppositeSide(DiceFace df){
- return byInt(7 - df.ordinal());
- }
- public static DiceFace byInt(int n){
- switch (n){
- case 1:return ONE;
- case 2:return TWO;
- case 3:return THREE;
- case 4:return FOUR;
- case 5:return FIVE;
- case 6:return SIX;
- }
- return BLANK;
- }
- }
Add Comment
Please, Sign In to add comment