Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TurtleGraphics;
- import java.util.Random;
- public class ex12v8 {
- //Joe Masson
- static Random gen = new Random();
- static int[][] board = new int[5][5];
- static int[] tossed = new int[10];
- public static void main(String[] args) {
- populateBoard();
- printTable();
- tossCoins();
- printFinal();
- }
- private static void printFinal() {
- int doll=0, poster=0, ball=0, game=0, puzzle=0;
- for(int q=0; q<10; q++) {
- int pull=tossed[q];
- //find the peg to correct
- int line, peg;
- line=pull/5;
- peg=pull%5;
- if(line==5)
- line--;
- if(board[line][peg]==1)
- doll++;
- if(board[line][peg]==2)
- poster++;
- if(board[line][peg]==3)
- ball++;
- if(board[line][peg]==4)
- game++;
- if(board[line][peg]==5)
- puzzle++;
- board[line][peg]=6;
- }
- for(int i=0; i<5; i++) {
- System.out.println("------------------------------------");
- for(int z=0; z<5; z++) {
- System.out.print("|");
- if(board[i][z]==0) {
- System.out.print(" ");
- }
- if(board[i][z]==1) {
- System.out.print(" Doll ");
- }
- if(board[i][z]==2) {
- System.out.print("Poster");
- }
- if(board[i][z]==3) {
- System.out.print(" Ball ");
- }
- if(board[i][z]==4) {
- System.out.print(" Game ");
- }
- if(board[i][z]==5) {
- System.out.print("Puzzle");
- }
- if(board[i][z]==6) {
- System.out.print("XXXXXX");
- }
- if(z==4) {
- System.out.print("|");
- }
- }
- System.out.println();
- }
- System.out.println("------------------------------------");
- System.out.println("You won");
- if(doll==3)
- System.out.println("Doll");
- if(poster==3)
- System.out.println("Poster");
- if(ball==3)
- System.out.println("ball");
- if(game==3)
- System.out.println("game");
- if(puzzle==3)
- System.out.println("puzzle");
- if(doll<3&&poster<3&&ball<3&&game<3&&puzzle<3)
- System.out.println("nothing");
- }
- private static void tossCoins() {
- int ran=0;
- while(ran<10) {
- int genned=gen.nextInt(25)+1;
- tossed[ran]=genned;
- while(genned==tossed[0]||genned==tossed[1]||genned==tossed[2]||genned==tossed[3]||genned==tossed[4]||genned==tossed[5]||genned==tossed[6]||genned==tossed[7]||genned==tossed[8]||genned==tossed[9]) {
- genned=gen.nextInt(25)+1;
- }
- tossed[ran]=genned;
- ran++;
- }
- }
- private static void populateBoard() {
- int doll=0, poster=0, ball=0, game=0, puzzle=0, generated=0;
- while(generated<15) {
- int num=gen.nextInt(5);
- int line=gen.nextInt(5);
- int peg=gen.nextInt(5);
- while(board[line][peg]>0) {
- line=gen.nextInt(5);
- peg=gen.nextInt(5);
- }
- if((num==0)&&(doll<3)) {
- board[line][peg]=1;
- doll++;
- generated++;
- }
- if((num==1)&&(poster<3)) {
- board[line][peg]=2;
- poster++;
- generated++;
- }
- if((num==2)&&(ball<3)) {
- board[line][peg]=3;
- ball++;
- generated++;
- }
- if((num==3)&&(game<3)) {
- board[line][peg]=4;
- game++;
- generated++;
- }
- if((num==4)&&(puzzle<3)) {
- board[line][peg]=5;
- puzzle++;
- generated++;
- }
- }
- }
- private static void printTable() {
- for(int i=0; i<5; i++) {
- System.out.println("------------------------------------");
- for(int z=0; z<5; z++) {
- System.out.print("|");
- if(board[i][z]==0) {
- System.out.print(" ");
- }
- if(board[i][z]==1) {
- System.out.print(" Doll ");
- }
- if(board[i][z]==2) {
- System.out.print("Poster");
- }
- if(board[i][z]==3) {
- System.out.print(" Ball ");
- }
- if(board[i][z]==4) {
- System.out.print(" Game ");
- }
- if(board[i][z]==5) {
- System.out.print("Puzzle");
- }
- if(z==4) {
- System.out.print("|");
- }
- }
- System.out.println();
- }
- System.out.println("------------------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement