Advertisement
niratic

ex12

Nov 7th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.80 KB | None | 0 0
  1. package TurtleGraphics;
  2.  
  3. import java.util.Random;
  4.  
  5. public class ex12v8 {
  6.     //Joe Masson
  7.     static Random gen = new Random();
  8.     static int[][] board = new int[5][5];
  9.     static int[] tossed = new int[10];
  10.     public static void main(String[] args) {
  11.         populateBoard();
  12.         printTable();
  13.         tossCoins();
  14.         printFinal();
  15.     }
  16.     private static void printFinal() {
  17.         int doll=0, poster=0, ball=0, game=0, puzzle=0;
  18.         for(int q=0; q<10; q++) {
  19.             int pull=tossed[q];
  20.             //find the peg to correct
  21.             int line, peg;
  22.             line=pull/5;
  23.             peg=pull%5;
  24.             if(line==5)
  25.                 line--;
  26.             if(board[line][peg]==1)
  27.                 doll++;    
  28.             if(board[line][peg]==2)
  29.                 poster++;
  30.             if(board[line][peg]==3)
  31.                 ball++;
  32.             if(board[line][peg]==4)
  33.                 game++;
  34.             if(board[line][peg]==5)
  35.                 puzzle++;
  36.             board[line][peg]=6;
  37.         }
  38.         for(int i=0; i<5; i++) {
  39.             System.out.println("------------------------------------");
  40.             for(int z=0; z<5; z++) {
  41.                 System.out.print("|");
  42.                 if(board[i][z]==0) {
  43.                     System.out.print("      ");
  44.                 }
  45.                 if(board[i][z]==1) {
  46.                     System.out.print(" Doll ");
  47.                 }
  48.                 if(board[i][z]==2) {
  49.                     System.out.print("Poster");
  50.                 }
  51.                 if(board[i][z]==3) {
  52.                     System.out.print(" Ball ");
  53.                 }
  54.                 if(board[i][z]==4) {
  55.                     System.out.print(" Game ");
  56.                 }
  57.                 if(board[i][z]==5) {
  58.                     System.out.print("Puzzle");
  59.                 }
  60.                 if(board[i][z]==6) {
  61.                     System.out.print("XXXXXX");
  62.                 }
  63.                 if(z==4) {
  64.                     System.out.print("|");
  65.                 }
  66.             }
  67.             System.out.println();
  68.         }
  69.         System.out.println("------------------------------------");
  70.         System.out.println("You won");
  71.         if(doll==3)
  72.             System.out.println("Doll");
  73.         if(poster==3)
  74.             System.out.println("Poster");
  75.         if(ball==3)
  76.             System.out.println("ball");
  77.         if(game==3)
  78.             System.out.println("game");
  79.         if(puzzle==3)
  80.             System.out.println("puzzle");
  81.         if(doll<3&&poster<3&&ball<3&&game<3&&puzzle<3)
  82.             System.out.println("nothing");
  83.     }
  84.     private static void tossCoins() {
  85.         int ran=0;
  86.         while(ran<10) {
  87.             int genned=gen.nextInt(25)+1;
  88.             tossed[ran]=genned;
  89.             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]) {
  90.                 genned=gen.nextInt(25)+1;
  91.             }
  92.             tossed[ran]=genned;
  93.             ran++;
  94.         }
  95.     }
  96.     private static void populateBoard() {
  97.         int doll=0, poster=0, ball=0, game=0, puzzle=0, generated=0;
  98.         while(generated<15) {
  99.             int num=gen.nextInt(5);
  100.             int line=gen.nextInt(5);
  101.             int peg=gen.nextInt(5);
  102.             while(board[line][peg]>0) {
  103.                 line=gen.nextInt(5);
  104.                 peg=gen.nextInt(5);
  105.             }
  106.             if((num==0)&&(doll<3)) {
  107.                 board[line][peg]=1;
  108.                 doll++;
  109.                 generated++;
  110.             }
  111.             if((num==1)&&(poster<3)) {
  112.                 board[line][peg]=2;
  113.                 poster++;
  114.                 generated++;
  115.             }
  116.             if((num==2)&&(ball<3)) {
  117.                 board[line][peg]=3;
  118.                 ball++;
  119.                 generated++;
  120.             }
  121.             if((num==3)&&(game<3)) {
  122.                 board[line][peg]=4;
  123.                 game++;
  124.                 generated++;
  125.             }
  126.             if((num==4)&&(puzzle<3)) {
  127.                 board[line][peg]=5;
  128.                 puzzle++;
  129.                 generated++;
  130.             }
  131.         }
  132.  
  133.     }
  134.     private static void printTable() {
  135.         for(int i=0; i<5; i++) {
  136.             System.out.println("------------------------------------");
  137.             for(int z=0; z<5; z++) {
  138.                 System.out.print("|");
  139.                 if(board[i][z]==0) {
  140.                     System.out.print("      ");
  141.                 }
  142.                 if(board[i][z]==1) {
  143.                     System.out.print(" Doll ");
  144.                 }
  145.                 if(board[i][z]==2) {
  146.                     System.out.print("Poster");
  147.                 }
  148.                 if(board[i][z]==3) {
  149.                     System.out.print(" Ball ");
  150.                 }
  151.                 if(board[i][z]==4) {
  152.                     System.out.print(" Game ");
  153.                 }
  154.                 if(board[i][z]==5) {
  155.                     System.out.print("Puzzle");
  156.                 }
  157.                 if(z==4) {
  158.                     System.out.print("|");
  159.                 }
  160.             }
  161.             System.out.println();
  162.         }
  163.         System.out.println("------------------------------------");
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement