Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DiceGame {
- public static void displayIntro() {
- System.out.println("The Game of Lucky Chances");
- System.out.println("A board game with 4 players and 20 squares.");
- System.out.println("Rolling an even space will result in moving forward with the resulting number and rerolling.");
- System.out.println("Rolling an odd number will result in moving back with the resulting number and ending turn.");
- System.out.println("-------------------------------");
- }
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- int counter = 0; // counter for the rounds
- displayIntro();
- System.out.println("");
- // Creating player objects.
- BoardGameTest PlayerOne = new BoardGameTest(0, 'A');
- BoardGameTest PlayerTwo = new BoardGameTest(0, 'B');
- BoardGameTest PlayerThree = new BoardGameTest(0, 'C');
- BoardGameTest PlayerFour = new BoardGameTest(0, 'D');
- // Display all player's position at the end of each round
- do {
- PlayerOne.diceRoll();
- PlayerTwo.diceRoll();
- PlayerThree.diceRoll();
- PlayerFour.diceRoll();
- counter++;
- System.out.printf("\nPlayer %s is currently at position %d.\n", PlayerOne.name(), PlayerOne.getPosition());
- System.out.printf("Player %s is currently at position %d.\n", PlayerTwo.name(), PlayerTwo.getPosition());
- System.out.printf("Player %s is currently at position %d.\n", PlayerThree.name(), PlayerThree.getPosition());
- System.out.printf("Player %s is currently at position %d.\n", PlayerFour.name(), PlayerFour.getPosition());
- //System.out.printf("---------------End of Round %d Results---------------\n", counter);
- int n=0;
- while (n<20) {
- if (n==PlayerOne.getPosition())
- System.out.printf("%s",PlayerOne.name());
- if (n==PlayerTwo.getPosition())
- System.out.printf("%s",PlayerTwo.name());
- if (n==PlayerThree.getPosition())
- System.out.printf("%s",PlayerThree.name());
- if (n==PlayerFour.getPosition())
- System.out.printf("%s",PlayerFour.name());
- if (n!=PlayerOne.getPosition() && n!=PlayerTwo.getPosition() && n!=PlayerThree.getPosition() && n!=PlayerFour.getPosition())
- System.out.print("-");
- n++;
- }
- }while(PlayerOne.getPosition() < 20 && PlayerTwo.getPosition() < 20 && PlayerThree.getPosition() < 20 && PlayerFour.getPosition() < 20);
- //After someone has reached the end
- if( PlayerOne.getPosition() >= 20) {
- System.out.println("Player " +PlayerOne.name() + " has reached the end first!");
- }
- else if ( PlayerTwo.getPosition() >= 20) {
- System.out.println("Player " +PlayerTwo.name() + " has reached the end first!");
- }
- else if ( PlayerThree.getPosition() >= 20) {
- System.out.println("Player " +PlayerThree.name() + " has reached the end first!");
- }
- else if ( PlayerFour.getPosition() >= 20) {
- System.out.println("Player " +PlayerFour.name() + " has reached the end first!");
- }
- System.out.println("Thanks for playing! Bye.");
- kb.close();
- } //end of main
- } //end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement