Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package nea;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author 9400
- */
- public class NEA {
- /**
- * @param args the command line arguments
- */
- static int player1 = 0;
- static int player2 = 0;
- static Random rand = new Random();
- static String x;
- static String y;
- static Scanner s = new Scanner(System.in);
- static char User1;
- static char User2;
- public class General{
- int Hiscores;
- String username, password;
- General(int Hiscores, String username, String password){
- this.Hiscores = Hiscores;
- this.username = username;
- this.password = password;
- }
- }
- public static void main(String[] args) {
- // TODO code application logic here
- fileReader();
- int choice;
- do {
- System.out.println("Dice Game!");
- System.out.println("____________________");
- System.out.println("Main Menu: ");
- System.out.println("1 > Register");
- System.out.println("2 > Log-in & Play");
- System.out.println("3 > Hi-Scores");
- System.out.println("4 > Exit Game");
- System.out.println("____________________");
- System.out.println("Choose an option: 1-4");
- System.out.println("");
- choice = s.nextInt();
- s.skip("\n");
- switch (choice) {
- case 1:
- register();
- break;
- case 2:
- login();
- break;
- case 3:
- hiscores();
- break;
- case 4:
- System.out.println("Goodbye");
- fileWriter();
- System.exit(0);
- break;
- default:
- System.out.println("Invalid Option. Try Again");
- System.out.println("");
- break;
- }
- } while (choice != 4);
- }
- private static void register() {
- System.out.println("Create Username: ");
- System.out.println("Create Password: ");
- System.out.println("");
- }
- private static void login() {
- System.out.println("Enter Username: ");
- System.out.println("Enter Password: ");
- System.out.println("");
- for (int r = 1; r < 6; r++) {
- System.out.println("-------------Round " + r + "-------------");
- System.out.println("");
- System.out.println("Player 1: Enter any key to roll the dice");
- x = s.nextLine();
- int dice1 = Dice();
- System.out.println("Dice one: " + dice1);
- int dice2 = Dice();
- System.out.println("Dice two: " + dice2);
- int dice3 = 0;
- if (dice1 == dice2) {
- dice3 = Dice();
- System.out.println("Dice three: " + dice3);
- }
- int total = dice1 + dice2 + dice3;
- player1 = total + player1;
- if (player1 % 2 == 1) {
- player1 = player1 - 5;
- System.out.println("Player 1 TOTAL: " + player1);
- if (player1 < 0) {
- player1 = 0;
- System.out.println("Player 1 TOTAL: " + player1);
- }
- } else {
- player1 = player1 + 10;
- System.out.println("Player 1 TOTAL: " + player1);
- }
- System.out.println("-------------------X-------------------");
- System.out.println("Player 2: Enter any key to roll the dice");
- y = s.nextLine();
- dice1 = Dice();
- System.out.println("Dice one: " + dice1);
- dice2 = Dice();
- System.out.println("Dice two: " + dice2);
- dice3 = 0;
- if (dice1 == dice2) {
- dice3 = Dice();
- System.out.println("Dice three: " + dice3);
- }
- total = dice1 + dice2 + dice3;
- player2 = total + player2;
- if (player2 % 2 == 1) {
- player2 = player2 - 5;
- System.out.println("Player 2 TOTAL: " + player2);
- if (player2 < 0) {
- player2 = 0;
- System.out.println("Player 2 TOTAL: " + player2);
- }
- } else {
- player2 = player2 + 10;
- System.out.println("Player 2 TOTAL: " + player2);
- }
- }
- System.out.println("--------------------------------------");
- System.out.println("| Player 1 score = " + player1 + " |");
- System.out.println("--------------------------------------");
- System.out.println("| Player 2 score = " + player2 + " |");
- if (player1 > player2) {
- System.out.println("");
- System.out.println("THE WINNER IS: PLAYER 1");
- System.out.println("");
- } else {
- System.out.println("");
- System.out.println("THE WINNER IS: PLAYER 2");
- System.out.println("");
- }
- System.out.println("");
- if (player1 == player2) {
- sudden();
- }
- }
- private static void hiscores() {
- System.out.println("Hi-Scores: ");
- System.out.println("");
- System.out.println("1. ");
- System.out.println("2. ");
- System.out.println("3. ");
- System.out.println("4. ");
- System.out.println("5. ");
- System.out.println("");
- }
- private static void exit() {
- }
- private static int Dice() {
- return (rand.nextInt(6) + 1);
- }
- private static void sudden() {
- System.out.println("------------!Sudden Death!------------");
- while (player1 == player2) {
- System.out.println("Player 1: Enter any key to roll the dice");
- x = s.nextLine();
- int dice4 = Dice();
- System.out.println("Player 1 Score: " + dice4);
- System.out.println("--------------------------------------");
- System.out.println("Player 2: Enter any key to roll the dice");
- y = s.nextLine();
- dice4 = Dice();
- System.out.println("Player 2 Score: " + dice4);
- if (player1 >= player2) {
- System.out.println("The Winner is: Player 1");
- } else {
- System.out.println("The Winner is: Player 2");
- }
- }
- }
- private static void fileReader() {
- try {
- BufferedReader br = new BufferedReader((new FileReader("N:/data.txt")));
- String a;
- while ((a = br.readLine()) != null) {
- String[] s = a.split(";");
- System.out.println(Arrays.toString(s));
- int hiscore = Integer.parseInt(s[2]);
- }
- System.out.println("Data Loaded Successfully");
- System.out.println("");
- br.close();
- } catch (IOException e) {
- System.out.println("Error: " + e.getMessage());
- }
- }
- private static void fileWriter() {
- try {
- FileWriter fw = new FileWriter("N:/newFile.txt");
- fw.write("This is some data.");
- fw.close();
- System.out.println("Data File Saved Successfully");
- System.out.println("");
- } catch (IOException e) {
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement