Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Menu menu = new Menu();
- Game game = new Game();
- int option;
- boolean x = false;
- do {
- try {
- menu.printMenu();
- Scanner scanner = new Scanner(System.in);
- option = scanner.nextInt();
- switch (option) {
- case 1: //dodawanie graczy
- if (game.playerList.size() > 1) {
- menu.clearScreen();
- System.out.println("Dodałeś już graczy.");
- } else {
- menu.clearScreen();
- for (int i = 0; i < 3; i++) {
- System.out.println("Podaj imie gracza nr: " + (i + 1));
- game.addPlayer(scanner.next());
- }
- menu.clearScreen();
- System.out.println("Gracze to:");
- for (int j = 0; j < 3; j++) {
- game.showPlayers(j);
- }
- }
- break;
- case 2: //start
- boolean z = true;
- menu.clearScreen();
- if (game.playerList.size() < 1) {
- System.out.println("Dodaj graczy!");
- }
- else {
- boolean y = true;
- while (y && z) {
- try {
- menu.printMenu2();
- Scanner scanner1 = new Scanner(System.in);
- int option1 = scanner1.nextInt();
- switch (option1) {
- case 1:
- menu.clearScreen();
- game.gra(); //własciwa gra -- przerobic z obracaniem koła
- break;
- case 2:
- menu.clearScreen();
- game.gra2(); //Kup Samogłoskę
- break;
- case 3: //Odgaduje haslo
- game.test123();
- break;
- case 0:
- menu.clearScreen();
- z = false;
- break;
- default:
- menu.clearScreen();
- System.out.println("Nie ma takiej opcji spróbuj jeszcze raz: ");
- }
- } catch (Exception e) {
- System.out.println("Nie ma takie opcji. Spróbuj jeszcze raz.");
- }
- } while (!y);
- }
- break;
- case 3: //ranking
- menu.clearScreen();
- if (game.playerList.size() < 1) {
- System.out.println("Dodaj graczy!");
- } else {
- for (int i = 0; i < game.playerList.size(); i++) {
- System.out.println(game.playerList.get(i).getName() + " " + game.playerList.get(i).getPoints() + " złotych.");
- }
- }
- break;
- case 0: //koniec
- menu.clearScreen();
- System.exit(0);
- default:
- menu.clearScreen();
- System.out.println("Nie ma takiej opcji spróbuj jeszcze raz.");
- }
- } catch (Exception e) {
- System.out.println("Nie ma takie opcji. Spróbuj jeszcze raz.");
- }
- } while (!x);
- }
- }
- class Players {
- private String name;
- private int points;
- void setName(String x) {
- name = x;
- }
- public String getName() {
- return name;
- }
- public int getPoints() {
- return points;
- }
- void addPoints(int a) {
- points = points + a;
- }
- void clearPoints() {
- points = 0;
- }
- void subPoints(int a) {
- points = points - a;
- }
- }
- public class Menu {
- void printMenu() {
- System.out.print("\n...:::KOŁO FORTUNY:::...\n1. Podaj graczy \n2. Start \n3. Ranking \n0. Koniec \n\nWybierz: ");
- }
- void printMenu2() {
- System.out.print("\n...:::KOŁO FORTUNY:::...\n1. Zakręć Kołem \n2. Kup Samogłoskę \n3. Odgaduje Hasło \n0. Wróć \n\nWybierz: ");
- }
- public static void clearScreen() {
- System.out.print("\033[H\033[2J");
- System.out.flush();
- }
- }
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.*;
- public class Game{
- Scanner scanner = new Scanner(System.in);
- BufferedReader bufread = new BufferedReader(new InputStreamReader(System.in));
- Rand rand = new Rand();
- Round round = new Round();
- Menu menu = new Menu();
- int randomPrice;
- boolean flag = true;
- ArrayList<Players> playerList = new ArrayList<>(); //tworzenie listy graczy z klasy
- String haslo1 = rand.randomSport();
- String haslo2 = haslo1.replaceAll("[a-z]", "#");
- String haslo4 = haslo2.replaceAll("[ą,ć,ę,ł,ń,ś,ó,ż,ź]", "#");
- StringBuilder haslo3 = new StringBuilder(haslo4); //doczytac co to jest
- public void addPlayer(String name){
- Players player = new Players();
- player.setName(name);
- playerList.add(player);
- }
- public void showPlayers(int z){
- System.out.println(playerList.get(z).getName() + " " + playerList.get(z).getPoints());
- }
- public boolean checkPuzzle(String check) { //sprawdzic z metoda sting matches
- if (check.contains(haslo1)){
- return true;
- }
- else {
- return false;
- }
- }
- public boolean checkRandomPrice(int z) {
- if (z == 0){
- System.out.println("BANKRUT!!!");
- playerList.get(round.getPlayer()).clearPoints();
- round.nextPlayer();
- return false;
- }
- else {
- return true;
- }
- }
- public boolean checkPts(int points) {
- if (points >= 200) {
- return true;
- }
- else {
- System.out.println("Masz za mało pieniędzy.");
- flag = false;
- return false;
- }
- }
- public boolean checkVowel(char vowel) {
- for(int j = 0; j < vowel ; j++)
- switch(vowel) {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
- case 'ó':
- return true;
- }
- return false;
- }
- public boolean checkConsonant(char consonant) {
- for(int k = 0; k < consonant ; k++)
- switch(consonant) {
- case 'b':
- case 'c':
- case 'ć':
- case 'd':
- case 'f':
- case 'g':
- case 'h':
- case 'j':
- case 'k':
- case 'l':
- case 'm':
- case 'n':
- case 'p':
- case 'r':
- case 's':
- case 't':
- case 'w':
- case 'y':
- case 'z':
- case 'ż':
- case 'ź':
- return true;
- }
- return false;
- }
- public void test123(){
- menu.clearScreen();
- try {
- System.out.print("Podaj Hasło: ");
- String checkP = bufread.readLine();
- if (checkPuzzle(checkP) == true) {
- 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.");
- } else {
- System.out.println("Podane hasło jest nieprawidłowe.");
- round.nextPlayer();
- }
- } catch (IOException ex){
- ex.printStackTrace();
- }
- }
- public void gra() {
- menu.clearScreen();
- round.checkPlayer(round.getPlayer());
- randomPrice = rand.randomPrice();
- if (checkRandomPrice(randomPrice)) {
- System.out.println("Kręci: " + playerList.get(round.getPlayer()).getName());
- System.out.println("Wylosowałes kwote: " + randomPrice);
- System.out.println("Stan portfela: " + playerList.get(round.getPlayer()).getPoints());
- System.out.println("Kategoria: SPORT \nHasło: " + haslo3.toString().toUpperCase());
- System.out.print("Podaj Spółgłoskę: ");
- puzzle(scanner.next().charAt(0)); //odkrywanie literek
- }
- }
- public void gra2(){
- flag = true;
- menu.clearScreen();
- round.checkPlayer(round.getPlayer());
- while (flag) {
- System.out.println("Kupuje: " + playerList.get(round.getPlayer()).getName());
- System.out.println("Stan portfela: " + playerList.get(round.getPlayer()).getPoints());
- if (checkPts(playerList.get(round.getPlayer()).getPoints())) {
- System.out.println("Kategoria: SPORT \nHasło: " + haslo3.toString().toUpperCase());
- System.out.print("Podaj Samogłoskę (Koszt 200zł): ");
- puzzle2(scanner.next().charAt(0)); //odkrywanie literek
- }
- }
- }
- public void puzzle2(char litera) {
- if (checkVowel(litera)) {
- if(haslo1.indexOf(litera)!=-1){
- for (int i = 0; i < haslo1.length(); i++){
- if (litera == haslo1.charAt(i)){
- haslo3.setCharAt(i, haslo1.charAt(i)); //zastap index w haslo3
- }
- }
- playerList.get(round.getPlayer()).subPoints(200);
- }
- else {
- System.out.println("Hasło nie zawiera samogłoski: " + litera);
- round.nextPlayer(); //sprawdzic
- flag = !flag;
- }
- System.out.println("\nHasło: " + haslo3.toString().toUpperCase());
- flag = !flag;
- }
- else {
- System.out.println("Wprowadziłeś " + litera + ". Musisz podać samogłoskę. Spróbuj jeszcze raz");
- }
- }
- public void puzzle(char litera) {
- if (checkConsonant(litera)) {
- if(haslo1.indexOf(litera)!=-1){
- for (int i = 0; i < haslo1.length(); i++){
- if (litera == haslo1.charAt(i)){
- haslo3.setCharAt(i, haslo1.charAt(i)); //zastap index w haslo3
- playerList.get(round.getPlayer()).addPoints(randomPrice);
- }
- }
- }
- else {
- System.out.println("Hasło nie zawiera spółgłoski: " + litera);
- round.nextPlayer();
- randomPrice = 0;
- }
- System.out.println("\nHasło: " + haslo3.toString().toUpperCase());
- randomPrice = 0;
- }
- else {
- System.out.println("Wprowadziłeś " + litera + ". Spróbuj jeszcze raz.");
- }
- }
- }
- import java.util.Random;
- public class Rand {
- 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};
- //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"};
- 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"};
- private String[] Cities = {"WARSZAWA", "WROCŁAW", "RIO DE JANERIO", "HONG KONG", "LOS ANGELES"};
- public int randomPrice() {
- int index = new Random().nextInt(Price.length);
- int x = (Price[index]);
- return x;
- }
- public String randomSport() {
- int index = new Random().nextInt(Sport.length);
- String x = (Sport[index]);
- return x;
- }
- public String randomCities() {
- int index = new Random().nextInt(Cities.length);
- String x = (Cities[index]);
- return x;
- }
- }
- public class Round {
- private int whichPlayer = 0;
- void setPlayer(int i) {
- whichPlayer = i;
- }
- public int getPlayer() {
- return whichPlayer;
- }
- void checkPlayer(int i) {
- if (i > 2) {
- whichPlayer = 0;
- }
- }
- void nextPlayer() {
- whichPlayer++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment