pw_

Wheel of Fortune v 1.0

pw_
Oct 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Menu menu = new Menu();
  8.         Game game = new Game();
  9.         int option;
  10.         boolean x = false;
  11.  
  12.  
  13.         do {
  14.             try {
  15.                 menu.printMenu();
  16.                 Scanner scanner = new Scanner(System.in);
  17.                 option = scanner.nextInt();
  18.                 switch (option) {
  19.                     case 1: //dodawanie graczy
  20.                         if (game.playerList.size() > 1) {
  21.                             menu.clearScreen();
  22.                             System.out.println("Dodałeś już graczy.");
  23.                         } else {
  24.                             menu.clearScreen();
  25.                             for (int i = 0; i < 3; i++) {
  26.                                 System.out.println("Podaj imie gracza nr: " + (i + 1));
  27.                                 game.addPlayer(scanner.next());
  28.                             }
  29.                             menu.clearScreen();
  30.                             System.out.println("Gracze to:");
  31.                             for (int j = 0; j < 3; j++) {
  32.                                 game.showPlayers(j);
  33.                             }
  34.                         }
  35.                         break;
  36.                     case 2: //start
  37.                         boolean z = true;
  38.                         menu.clearScreen();
  39.                         if (game.playerList.size() < 1) {
  40.                             System.out.println("Dodaj graczy!");
  41.                         }
  42.                         else {
  43.                             boolean y = true;
  44.                             while (y && z) {
  45.                                 try {
  46.                                     menu.printMenu2();
  47.                                     Scanner scanner1 = new Scanner(System.in);
  48.                                     int option1 = scanner1.nextInt();
  49.                                     switch (option1) {
  50.                                         case 1:
  51.                                             menu.clearScreen();
  52.                                             game.gra(); //własciwa gra  --  przerobic z obracaniem koła
  53.                                             break;
  54.                                         case 2:
  55.                                             menu.clearScreen();
  56.                                             game.gra2(); //Kup Samogłoskę
  57.                                             break;
  58.                                         case 3: //Odgaduje haslo
  59.                                             game.test123();
  60.                                             break;
  61.                                         case 0:
  62.                                             menu.clearScreen();
  63.                                             z = false;
  64.                                             break;
  65.                                         default:
  66.                                             menu.clearScreen();
  67.                                             System.out.println("Nie ma takiej opcji spróbuj jeszcze raz: ");
  68.                                     }
  69.                                 } catch (Exception e) {
  70.                                     System.out.println("Nie ma takie opcji. Spróbuj jeszcze raz.");
  71.                                 }
  72.                             } while (!y);
  73.                         }
  74.                         break;
  75.                     case 3:  //ranking
  76.                         menu.clearScreen();
  77.                         if (game.playerList.size() < 1) {
  78.                             System.out.println("Dodaj graczy!");
  79.                         } else {
  80.                             for (int i = 0; i < game.playerList.size(); i++) {
  81.                                 System.out.println(game.playerList.get(i).getName() + " " + game.playerList.get(i).getPoints() + " złotych.");
  82.                             }
  83.                         }
  84.                         break;
  85.                     case 0:  //koniec
  86.                         menu.clearScreen();
  87.                         System.exit(0);
  88.                     default:
  89.                         menu.clearScreen();
  90.                         System.out.println("Nie ma takiej opcji spróbuj jeszcze raz.");
  91.                 }
  92.             } catch (Exception e) {
  93.                 System.out.println("Nie ma takie opcji. Spróbuj jeszcze raz.");
  94.             }
  95.         } while (!x);
  96.     }
  97.  
  98. }
  99.  
  100. class Players {
  101.  
  102.     private String name;
  103.     private int points;
  104.  
  105.     void setName(String x) {
  106.         name = x;
  107.     }
  108.     public String getName() {
  109.         return name;
  110.     }
  111.     public int getPoints() {
  112.         return points;
  113.     }
  114.     void addPoints(int a) {
  115.         points = points + a;
  116.     }
  117.     void clearPoints() {
  118.         points = 0;
  119.     }
  120.     void subPoints(int a) {
  121.         points = points - a;
  122.     }
  123. }
  124.  
  125. public class Menu {
  126.  
  127.     void printMenu() {
  128.         System.out.print("\n...:::KOŁO FORTUNY:::...\n1. Podaj graczy \n2. Start \n3. Ranking \n0. Koniec \n\nWybierz: ");
  129.     }
  130.     void printMenu2() {
  131.         System.out.print("\n...:::KOŁO FORTUNY:::...\n1. Zakręć Kołem \n2. Kup Samogłoskę \n3. Odgaduje Hasło \n0. Wróć \n\nWybierz: ");
  132.     }
  133.     public static void clearScreen() {
  134.         System.out.print("\033[H\033[2J");
  135.         System.out.flush();
  136.     }
  137. }
  138.  
  139. import java.util.ArrayList;
  140. import java.util.Scanner;
  141. import java.io.*;
  142.  
  143. public class Game{
  144.  
  145.     Scanner scanner = new Scanner(System.in);
  146.     BufferedReader bufread = new BufferedReader(new InputStreamReader(System.in));
  147.     Rand rand = new Rand();
  148.     Round round = new Round();
  149.     Menu menu = new Menu();
  150.     int randomPrice;
  151.     boolean flag = true;
  152.  
  153.     ArrayList<Players> playerList = new ArrayList<>();  //tworzenie listy graczy z klasy
  154.     String haslo1 = rand.randomSport();
  155.     String haslo2 = haslo1.replaceAll("[a-z]", "#");
  156.     String haslo4 = haslo2.replaceAll("[ą,ć,ę,ł,ń,ś,ó,ż,ź]", "#");
  157.     StringBuilder haslo3 = new StringBuilder(haslo4);  //doczytac co to jest
  158.  
  159.     public void addPlayer(String name){
  160.         Players player = new Players();
  161.         player.setName(name);
  162.         playerList.add(player);
  163.     }
  164.     public void showPlayers(int z){
  165.         System.out.println(playerList.get(z).getName() + " " + playerList.get(z).getPoints());
  166.     }
  167.  
  168.     public boolean checkPuzzle(String check) {  //sprawdzic z metoda sting matches
  169.         if (check.contains(haslo1)){
  170.             return true;
  171.         }
  172.         else {
  173.             return false;
  174.         }
  175.     }
  176.     public boolean checkRandomPrice(int z) {
  177.         if (z == 0){
  178.             System.out.println("BANKRUT!!!");
  179.             playerList.get(round.getPlayer()).clearPoints();
  180.             round.nextPlayer();
  181.             return false;
  182.         }
  183.         else {
  184.             return true;
  185.         }
  186.     }
  187.  
  188.     public boolean checkPts(int points) {
  189.         if (points >= 200) {
  190.             return true;
  191.         }
  192.         else {
  193.             System.out.println("Masz za mało pieniędzy.");
  194.             flag = false;
  195.             return false;
  196.         }
  197.     }
  198.  
  199.     public boolean checkVowel(char vowel) {
  200.         for(int j = 0; j < vowel ; j++)
  201.             switch(vowel) {
  202.                 case 'a':
  203.                 case 'e':
  204.                 case 'i':
  205.                 case 'o':
  206.                 case 'u':
  207.                 case 'ó':
  208.                     return true;
  209.             }
  210.         return false;
  211.     }
  212.  
  213.     public boolean checkConsonant(char consonant) {
  214.         for(int k = 0; k < consonant ; k++)
  215.             switch(consonant) {
  216.                 case 'b':
  217.                 case 'c':
  218.                 case 'ć':
  219.                 case 'd':
  220.                 case 'f':
  221.                 case 'g':
  222.                 case 'h':
  223.                 case 'j':
  224.                 case 'k':
  225.                 case 'l':
  226.                 case 'm':
  227.                 case 'n':
  228.                 case 'p':
  229.                 case 'r':
  230.                 case 's':
  231.                 case 't':
  232.                 case 'w':
  233.                 case 'y':
  234.                 case 'z':
  235.                 case 'ż':
  236.                 case 'ź':
  237.                     return true;
  238.             }
  239.         return false;
  240.     }
  241.  
  242.     public void test123(){
  243.         menu.clearScreen();
  244.         try {
  245.             System.out.print("Podaj Hasło: ");
  246.             String checkP = bufread.readLine();
  247.             if (checkPuzzle(checkP) == true) {
  248.                 System.out.println("Brawo! Wygrał(a): " + playerList.get(round.getPlayer()).getName() + " Hasło to: " + checkP.toUpperCase() + " wygrałeś " + playerList.get(round.getPlayer()).getPoints() + " złotych.");
  249.             } else {
  250.                 System.out.println("Podane hasło jest nieprawidłowe.");
  251.                 round.nextPlayer();
  252.             }
  253.         } catch (IOException ex){
  254.             ex.printStackTrace();
  255.         }
  256.     }
  257.  
  258.     public void gra() {
  259.         menu.clearScreen();
  260.         round.checkPlayer(round.getPlayer());
  261.         randomPrice = rand.randomPrice();
  262.         if (checkRandomPrice(randomPrice)) {
  263.             System.out.println("Kręci: " + playerList.get(round.getPlayer()).getName());
  264.             System.out.println("Wylosowałes kwote: " + randomPrice);
  265.             System.out.println("Stan portfela: " + playerList.get(round.getPlayer()).getPoints());
  266.             System.out.println("Kategoria: SPORT \nHasło: " + haslo3.toString().toUpperCase());
  267.             System.out.print("Podaj Spółgłoskę: ");
  268.             puzzle(scanner.next().charAt(0));  //odkrywanie literek
  269.         }
  270.     }
  271.  
  272.     public void gra2(){
  273.         flag = true;
  274.         menu.clearScreen();
  275.         round.checkPlayer(round.getPlayer());
  276.         while (flag) {
  277.             System.out.println("Kupuje: " + playerList.get(round.getPlayer()).getName());
  278.             System.out.println("Stan portfela: " + playerList.get(round.getPlayer()).getPoints());
  279.             if (checkPts(playerList.get(round.getPlayer()).getPoints())) {
  280.                 System.out.println("Kategoria: SPORT \nHasło: " + haslo3.toString().toUpperCase());
  281.                 System.out.print("Podaj Samogłoskę (Koszt 200zł): ");
  282.                 puzzle2(scanner.next().charAt(0));  //odkrywanie literek
  283.             }
  284.         }
  285.  
  286.     }
  287.  
  288.     public void puzzle2(char litera) {
  289.         if (checkVowel(litera)) {
  290.             if(haslo1.indexOf(litera)!=-1){
  291.                 for (int i = 0; i < haslo1.length(); i++){
  292.                     if (litera == haslo1.charAt(i)){
  293.                         haslo3.setCharAt(i, haslo1.charAt(i));  //zastap index w haslo3
  294.                     }
  295.                 }
  296.                 playerList.get(round.getPlayer()).subPoints(200);
  297.             }
  298.             else {
  299.                 System.out.println("Hasło nie zawiera samogłoski: " + litera);
  300.                 round.nextPlayer(); //sprawdzic
  301.                 flag = !flag;
  302.             }
  303.             System.out.println("\nHasło: " + haslo3.toString().toUpperCase());
  304.             flag = !flag;
  305.         }
  306.         else {
  307.             System.out.println("Wprowadziłeś " + litera + ". Musisz podać samogłoskę. Spróbuj jeszcze raz");
  308.         }
  309.     }
  310.  
  311.     public void puzzle(char litera) {
  312.         if (checkConsonant(litera)) {
  313.             if(haslo1.indexOf(litera)!=-1){
  314.                 for (int i = 0; i < haslo1.length(); i++){
  315.                     if (litera == haslo1.charAt(i)){
  316.                         haslo3.setCharAt(i, haslo1.charAt(i));  //zastap index w haslo3
  317.                         playerList.get(round.getPlayer()).addPoints(randomPrice);
  318.                     }
  319.                 }
  320.             }
  321.             else {
  322.                 System.out.println("Hasło nie zawiera spółgłoski: " + litera);
  323.                 round.nextPlayer();
  324.                 randomPrice = 0;
  325.             }
  326.             System.out.println("\nHasło: " + haslo3.toString().toUpperCase());
  327.             randomPrice = 0;
  328.         }
  329.         else {
  330.             System.out.println("Wprowadziłeś " + litera + ". Spróbuj jeszcze raz.");
  331.         }
  332.     }
  333. }
  334.  
  335. import java.util.Random;
  336.  
  337. public class Rand {
  338.  
  339.     private int[] Price = {0, 50, 50, 50, 50, 50, 100, 100, 100, 100, 150, 150, 150, 200, 200, 250, 0, 250, 500, 750, 1000, 1500, 2000, 3000, 5000};
  340.     //private String[] Sport = {"MANCHESTER UNITED", "LEKKOATLETYKA", "SIATKÓWKA", "CRISTIANO RONALDO", "PIŁKA NOŻNA", "TOMASZ HAJTO", "SKOK O TYCZCE", "RZUT OSZCZEPEM", "MISTRZOSTWA ŚWIATA W PIŁCE NOŻNEJ"};
  341.     private String[] Sport = {"manchester united", "lekkoatletyka", "siatkówka", "cristiano ronaldo", "piłka nożna", "tomasz hajto", "skok o tyczce", "rzut oszczepem", "mistrzostwa świata w piłce noznej"};
  342.     private String[] Cities = {"WARSZAWA", "WROCŁAW", "RIO DE JANERIO", "HONG KONG", "LOS ANGELES"};
  343.  
  344.  
  345.     public int randomPrice() {
  346.         int index = new Random().nextInt(Price.length);
  347.         int x = (Price[index]);
  348.         return x;
  349.     }
  350.  
  351.     public String randomSport() {
  352.         int index = new Random().nextInt(Sport.length);
  353.         String x = (Sport[index]);
  354.         return x;
  355.     }
  356.  
  357.     public String randomCities() {
  358.         int index = new Random().nextInt(Cities.length);
  359.         String x = (Cities[index]);
  360.         return x;
  361.  
  362.     }
  363. }
  364.  
  365. public class Round {
  366.     private int whichPlayer = 0;
  367.  
  368.     void setPlayer(int i) {
  369.         whichPlayer = i;
  370.     }
  371.     public int getPlayer() {
  372.         return whichPlayer;
  373.     }
  374.     void checkPlayer(int i) {
  375.         if (i > 2) {
  376.             whichPlayer = 0;
  377.         }
  378.     }
  379.     void nextPlayer() {
  380.         whichPlayer++;
  381.     }
  382. }
Advertisement
Add Comment
Please, Sign In to add comment