Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dicegame;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author Zaki
- */
- public class DiceGame {
- static Scanner L = new Scanner(System.in);
- static int diceroll;
- static Random rand = new Random();
- static int diceroll2;
- static int p1Score;
- static int p2Score;
- static int roundScore;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int option;
- System.out.println("Welcome to the Dice Game!");
- do {
- System.out.println("______________________________");
- System.out.println("Main Menu");
- System.out.println("Choose from the following options: \n 1 Register to play \n 2 Log in to play \n 3 Hi-Scores \n 4 End game");
- System.out.println("Enter the preferred number");
- option = L.nextInt();
- switch (option) {
- case 1:
- Register();
- break;
- case 2:
- LogIn();
- break;
- case 3:
- HiScore();
- break;
- case 4:
- EndGame();
- break;
- default:
- System.out.println("Invalid Option");
- break;
- }
- } while (option > 4 || option <= 3);
- }
- private static void Register() {
- System.out.println("_______________________________");
- System.out.println("Register to play \n Please enter your Username:");
- System.out.println("Please enter your Password");
- }
- private static void LogIn() {
- System.out.println("Player 1 enter your username:");
- System.out.println("Player 2 enter your password:");
- System.out.println("Player 1 enter your username:");
- System.out.println("Player 2 enter your password:");
- game();
- }
- private static void HiScore() {
- System.out.println("INSERT TABLE HERE BRO");
- }
- private static void EndGame() {
- System.out.println("Thank you for playing the Dice Game!");
- }
- private static void game() {
- System.out.println("Lets play! \n Player 1 Press X to roll the dice");
- L.skip("\n");
- int dice1, dice2;
- char roll = L.nextLine().charAt(0);
- if (roll == 'x') {
- dice1 = diceRoll();
- dice2 = diceRoll();
- p1Score = dice1 + dice2;
- System.out.println("You rolled a " + dice1 + " and a " + dice2);
- p1Score = oddEven(p1Score);
- System.out.println("Your score is: " + p1Score);
- }
- System.out.println("Player 2 turn \n Press x");
- char roll2 = L.nextLine().charAt(0);
- if (roll == 'x') {
- dice1 = diceRoll();
- dice2 = diceRoll();
- p2Score = dice1 + dice2;
- System.out.println("You rolled a " + dice1 + " and a " + dice2);
- p2Score = oddEven(p2Score);
- System.out.println("Your score is: " + p2Score);
- }
- }
- public static int diceRoll() {
- return diceroll = rand.nextInt(6) + 1;
- }
- private static int oddEven(int Score) {
- if (Score % 2 == 0) {
- Score = Score + 10;
- } else {
- Score = Score - 5;
- }
- System.out.println(Score);
- return Score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement