diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/CS105-Proje.iml b/.idea/CS105-Proje.iml deleted file mode 100644 index d6ebd48..0000000 --- a/.idea/CS105-Proje.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/CS105-Projects.iml b/.idea/CS105-Projects.iml new file mode 100644 index 0000000..0c6566e --- /dev/null +++ b/.idea/CS105-Projects.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 31e1ebc..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index cc4c0d9..b30b4c8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..d76f289 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + { + "lastFilter": { + "state": "OPEN", + "assignee": "MelekCetinel" + } +} + { + "selectedUrlAndAccountId": { + "url": "https://github.com/AltEGE/CS105-Projects.git", + "accountId": "d39773c6-d642-4c52-88f8-f5fb265d4e6a" + } +} + + + { + "customColor": "", + "associatedIndex": 6 +} + + + + + + + + + + + + + + + + + + + + + + + + + 1734384650012 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rock_paper_scissors.java b/rock_paper_scissors.java deleted file mode 100644 index 50eb2ad..0000000 --- a/rock_paper_scissors.java +++ /dev/null @@ -1,78 +0,0 @@ -import java.util.Random; -import java.util.Scanner; - -public class rock_paper_scissors extends Game { - - public rock_paper_scissors(double muz_coin) { - super(muz_coin); - } - - - @Override - public String kurallari_yaz() { - return "Taş-Kağıt-Makas Oyunu Kuralları:\n" + - "1. Taş makası yener.\n" + - "2. Kağıt taşı yener.\n" + - "3. Makas kağıdı yener.\n" + - "4. Oyuncu ve bilgisayar aynı seçimi yaparsa oyun berabere biter."; - } - - - @Override - public void oyun_başlat() { - Scanner input = new Scanner(System.in); - Random random = new Random(); - String[] secenekler = {"Taş", "Kağıt", "Makas"}; - System.out.println(kurallari_yaz()); - System.out.println("---------------------------------"); - System.out.println("Muz coin'iniz : " + getMuz_coin()); - System.out.println("---------------------------------"); - - while (true) { - - System.out.println("---------------------------------"); - System.out.println("Muz coin'iniz : " + getMuz_coin()); - System.out.println("---------------------------------"); - - System.out.print("\nYatırmak istediğiniz miktarı girin: "); - double yatirilanMiktar = input.nextDouble(); - para_yatir(yatirilanMiktar); - - System.out.print("Seçiminizi yapın (1: Taş, 2: Kağıt, 3: Makas): "); - int oyuncuSecimi = input.nextInt(); - - if (oyuncuSecimi < 1 || oyuncuSecimi > 3) { - System.out.println("Geçersiz seçim! Lütfen 1, 2 veya 3 girin."); - continue; - } - - String oyuncuHamlesi = secenekler[oyuncuSecimi - 1]; - String bilgisayarHamlesi = secenekler[random.nextInt(3)]; - - System.out.println("Oyuncu seçimi: " + oyuncuHamlesi); - System.out.println("Bilgisayar seçimi: " + bilgisayarHamlesi); - - if (oyuncuHamlesi.equals(bilgisayarHamlesi)) { - System.out.println("Oyun berabere!"); - draw(); - } else if ((oyuncuHamlesi.equals("Taş") && bilgisayarHamlesi.equals("Makas")) || - (oyuncuHamlesi.equals("Kağıt") && bilgisayarHamlesi.equals("Taş")) || - (oyuncuHamlesi.equals("Makas") && bilgisayarHamlesi.equals("Kağıt"))) { - System.out.println("Kazandınız!"); - win(2.0); - } else { - System.out.println("Kaybettiniz!"); - } - - // input.nextLine() kullanarak önceki satırdaki boşluğu temizle - input.nextLine(); - - System.out.print("\nÇıkmak için 'q' tuşuna basın, yeni oyun için herhangi bir tuşa"); - String devam = input.nextLine(); - if (devam.equalsIgnoreCase("q")) { - System.out.println("Oyun sonlandırıldı."); - break; - } - } - } -} diff --git a/src/Clothes/Abstract_Clothes.java b/src/Clothes/Abstract_Clothes.java new file mode 100644 index 0000000..1d8540e --- /dev/null +++ b/src/Clothes/Abstract_Clothes.java @@ -0,0 +1,43 @@ +package src.Clothes; + +public abstract class Abstract_Clothes { + protected double price; + protected String color; + + protected String bodyPart; + protected String model; + + protected int ID; + + public Abstract_Clothes(double price, String color, int ID) { + this.price = price; + this.color = color; + this.ID = ID; + } + + public void getInfo(){ + System.out.println("ID : " + ID + "\n" + + "Your item is " + color + " " + model + "\n" + + "Model price is " + price ); + System.out.println("-------------------------------------"); + } + + + public double getPrice() { + return price; + } + public void setPrice(double price) {this.price = price;} + + public String getColor() {return color;} + public void setColor(String color) { + this.color = color; + } + + + public int getID() { + return ID; + } + public void setID(int ID) { + this.ID = ID; + } +} diff --git a/src/Clothes/Glasses.java b/src/Clothes/Glasses.java new file mode 100644 index 0000000..2adb97e --- /dev/null +++ b/src/Clothes/Glasses.java @@ -0,0 +1,15 @@ +package src.Clothes; + +public class Glasses extends Abstract_Clothes { + + public Glasses(double price, String color, int ID){ + super(price, color, ID); + this.bodyPart = "Head Body"; + this.model = "Glasses"; + + } + public String getModel(){ + return model; + } + public void setModel(){this.model = model;} +} diff --git a/src/Clothes/Glove.java b/src/Clothes/Glove.java new file mode 100644 index 0000000..518bd37 --- /dev/null +++ b/src/Clothes/Glove.java @@ -0,0 +1,14 @@ +package src.Clothes; + +public class Glove extends Abstract_Clothes { + public Glove (double price,String color, int ID) { + super(price, color, ID); + this.bodyPart = " Hand Part"; + this.model = "Glove"; + } + + public String getModel(){return model;} + public void setModel(String model){this.model = model;} + +} + diff --git a/src/Clothes/Hat.java b/src/Clothes/Hat.java new file mode 100644 index 0000000..b0df21f --- /dev/null +++ b/src/Clothes/Hat.java @@ -0,0 +1,12 @@ +package src.Clothes; + +public class Hat extends Abstract_Clothes { + public Hat (double price,String color, int ID) { + super(price, color, ID); + this.bodyPart = "Head Body"; + this.model = "Hat"; + } + public String getModel(){return model;} + public void setModel(String model){this.model = model;} + +} \ No newline at end of file diff --git a/src/Clothes/Pant.java b/src/Clothes/Pant.java new file mode 100644 index 0000000..0478d37 --- /dev/null +++ b/src/Clothes/Pant.java @@ -0,0 +1,12 @@ +package src.Clothes; + +public class Pant extends Abstract_Clothes { + public Pant(double price , String color , int ID){ + super(price, color, ID); + this.bodyPart = "Lower Body"; + this.model = "Jean"; + } + public String getModel(){return model;} + public void setModel(String model){this.model = model;} + +} diff --git a/src/Clothes/Shoe.java b/src/Clothes/Shoe.java new file mode 100644 index 0000000..b2d51ee --- /dev/null +++ b/src/Clothes/Shoe.java @@ -0,0 +1,12 @@ +package src.Clothes; + +public class Shoe extends Abstract_Clothes { + public Shoe(double price,String color, int ID) { + super(price, color, ID); + this.bodyPart = "Feet Part"; + this.model = "Shoe"; + } + + public String getModel(){return model;} + public void setModel(String model){this.model = model;} +} diff --git a/src/Clothes/Skirt.java b/src/Clothes/Skirt.java new file mode 100644 index 0000000..8f3dfd7 --- /dev/null +++ b/src/Clothes/Skirt.java @@ -0,0 +1,12 @@ +package src.Clothes; + +public class Skirt extends Abstract_Clothes { + public Skirt (double price,String color, int ID){ + super(price,color, ID); + this.bodyPart = "Lower Body"; + this.model = "Skirt"; + } + public String getModel(){return model;} + public void setModel(String model){this.model = model;} + +} diff --git a/src/Clothes/Store.java b/src/Clothes/Store.java new file mode 100644 index 0000000..97c3e5e --- /dev/null +++ b/src/Clothes/Store.java @@ -0,0 +1,78 @@ +package src.Clothes; + +import src.User.Profile; + +import java.util.ArrayList; +import java.util.NoSuchElementException; +import java.util.Scanner; + +public class Store { + + protected ArrayList clothesList = new ArrayList<>(); + + public void add_list (Abstract_Clothes c){ + clothesList.add(c); + } + public void remove_list (Abstract_Clothes c){clothesList.remove(c);} + + public void display_store_list(){ + for (Abstract_Clothes c : clothesList) { + c.getInfo(); + } + } + + public Abstract_Clothes find_clothes(int id){ + for (Abstract_Clothes c : clothesList) { + if (c.getID() == id) { + return c; + } + } + throw new NoSuchElementException("There is no clothes with that Id"); + } + + public void buy_clothes(Profile user, int id){ + try{ + Abstract_Clothes c = find_clothes(id); + if (user.getCoin() >= c.getPrice()) { + System.out.println("***************************************"); + System.out.println("You Buy : "); + c.getInfo(); + System.out.println("You have $" + c.getPrice()); + System.out.println("***************************************"); + this.clothesList.remove(c); + user.buy_clothes(c); + } else { + System.out.println("You don't have enough money to buy this cloth."); + } + } catch (NoSuchElementException e) { + System.out.println("Invalid ID"); + } + } + + public void visit_store(Profile user){ + Scanner scanner = new Scanner(System.in); + + System.out.println("Welcome to the Banana Store!"); + System.out.println("Your Current Budge : " + user.getCoin()); + System.out.println("You can select what you want to buy: "); + this.display_store_list(); + System.out.println("0 : for Nothing" ); + int chosen = scanner.nextInt(); + if (chosen == 0) { + System.out.println("Thank you for using Banana Store!"); + } else { + this.buy_clothes(user, chosen); + } + + } + public String toString(){ + String store_ids = ""; + for (Abstract_Clothes c : clothesList) { + store_ids = store_ids + c.getID() + "-"; + } + store_ids = store_ids.substring(0, store_ids.length() - 1); + return store_ids; + } + + +} diff --git a/src/Clothes/Tshirt.java b/src/Clothes/Tshirt.java new file mode 100644 index 0000000..8e2f64f --- /dev/null +++ b/src/Clothes/Tshirt.java @@ -0,0 +1,13 @@ +package src.Clothes; + +public class Tshirt extends Abstract_Clothes { + public Tshirt( double price , String color, int ID) { + super(price, color, ID); + this.bodyPart = "Upper Body"; + this.model = "Tshirt"; + } + public String getModel(){ + return model; + } + public void setModel(String model){this.model= model;} +} diff --git a/src/DataBases/DataLoader.java b/src/DataBases/DataLoader.java new file mode 100644 index 0000000..168b48e --- /dev/null +++ b/src/DataBases/DataLoader.java @@ -0,0 +1,80 @@ +package src.DataBases; +import src.Clothes.Store; +import src.User.Profile; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; + +public class DataLoader { + private Profile profile; + private ArrayList inventory_ids = new ArrayList(); + private ArrayList store_ids = new ArrayList(); + + private File profile_file; + private File store_file; + private Scanner scanner; + + public DataLoader(){} + + public void loadData(){ + this.readProfileFile(); + this.readStoreFile(); + } + + public ArrayList converter(String[] stringNumbers){ + ArrayList intList = new ArrayList<>(); + + for (String numStr : stringNumbers) { + intList.add(Integer.parseInt(numStr.trim())); // String'i integer'a çevir ve listeye ekle + } + return intList; + } + + public void readProfileFile() { + String line = null; + try { + this.profile_file = new File("src/DataBases/profiles.txt"); + scanner = new Scanner(profile_file); + line = scanner.nextLine(); + } catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + + String[] profile_infos = line.split(","); + + this.profile = new Profile(profile_infos[0], profile_infos[1],Double.parseDouble(profile_infos[2])); + if (profile_infos.length >= 3){ + + String[] tmp_prifile_infos = profile_infos[3].split("-"); + this.inventory_ids = converter(tmp_prifile_infos); + } + } + + public void readStoreFile() { + String line = null; + try { + this.store_file = new File("src/DataBases/store.txt"); + scanner = new Scanner(store_file); + line = scanner.nextLine(); + }catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + String[] store_infos = line.split("-"); + + this.store_ids = converter(store_infos); + } + + public Profile getProfile(){ + return this.profile; + } + public ArrayList getInventoryIds() { + return this.inventory_ids; + } + public ArrayList getStoreIds() { + return this.store_ids; + } +} diff --git a/src/DataBases/DataSaver.java b/src/DataBases/DataSaver.java new file mode 100644 index 0000000..469af2b --- /dev/null +++ b/src/DataBases/DataSaver.java @@ -0,0 +1,34 @@ +package src.DataBases; +import src.User.Profile; +import src.Clothes.Store; + +import java.io.FileWriter; +import java.io.IOException; + +public class DataSaver { + + public void save(Profile profile) { + String profile_info = profile.toString(); + try{ + FileWriter file = new FileWriter("src/DataBases/profiles.txt"); + file.write(profile_info); + file.close(); + } catch (IOException e){ + System.out.println("An error occurred."); + e.printStackTrace(); + } + } + + public void save(Store store) { + String store_info = store.toString(); + try{ + FileWriter file = new FileWriter("src/DataBases/store.txt"); + file.write(store_info); + file.close(); + } catch (IOException e){ + System.out.println("An error occurred."); + e.printStackTrace(); + } + } + +} diff --git a/src/DataBases/GameBuilder.java b/src/DataBases/GameBuilder.java new file mode 100644 index 0000000..289589b --- /dev/null +++ b/src/DataBases/GameBuilder.java @@ -0,0 +1,72 @@ +package src.DataBases; + +import src.Clothes.*; +import src.User.Profile; + +import java.io.File; +import java.util.ArrayList; +import java.util.Scanner; + +public class GameBuilder { + DataLoader dataLoader = new DataLoader(); + Scanner scanner = new Scanner(System.in); + + ArrayList all_game_clothes = new ArrayList<>(); + + Hat hat = new Hat(35, "Red" , 1); + Skirt skirt = new Skirt (80, "Pink", 2); + Pant pant = new Pant (85, "Blue", 3); + Tshirt tshirt = new Tshirt (75, "Yellow", 4); + Glasses glasses = new Glasses(35,"Black" , 5); + Shoe shoe = new Shoe (100, "Green", 6); + Glove glove = new Glove (30, "Orange", 7); + + + private Store store = new Store(); + private Profile profile; + private ArrayList inventory_ids; + + public GameBuilder(){ + all_game_clothes.add(hat); + all_game_clothes.add(skirt); + all_game_clothes.add(pant); + all_game_clothes.add(tshirt); + all_game_clothes.add(glasses); + all_game_clothes.add(shoe); + all_game_clothes.add(glove); + + File f = new File("src/DataBases/profiles.txt"); + + if(f.exists()){ + dataLoader.loadData(); + this.profile = dataLoader.getProfile(); + this.inventory_ids = dataLoader.getInventoryIds(); + } else { + System.out.print("Nickname : "); + String nickname = scanner.nextLine(); + + System.out.print("Gender (male or female): "); + String gender = scanner.nextLine(); + + System.out.println("Welcome " + nickname + "\n" + + "You have earned 100 coins as a welcome gift"); + System.out.println("-------------------------------------"); + this.profile = new Profile(nickname, gender, 100); + this.inventory_ids = profile.getInventory().get_inventory_ids(); + } + + + for (Abstract_Clothes c : all_game_clothes){ + if (inventory_ids.contains(c.getID())){ + this.profile.add_clothes(c); + } else { + this.store.add_list(c); + } + } + + } + + public Store getStore() {return this.store;} + public Profile getProfile() {return this.profile;} + +} diff --git a/src/DataBases/profiles.txt b/src/DataBases/profiles.txt new file mode 100644 index 0000000..5931655 --- /dev/null +++ b/src/DataBases/profiles.txt @@ -0,0 +1 @@ +melo,female,500.0,1-2 \ No newline at end of file diff --git a/src/DataBases/store.txt b/src/DataBases/store.txt new file mode 100644 index 0000000..97a231d --- /dev/null +++ b/src/DataBases/store.txt @@ -0,0 +1 @@ +3-4-5-6-7 \ No newline at end of file diff --git a/src/Games/Blackjack.java b/src/Games/Blackjack.java new file mode 100644 index 0000000..10ec6e3 --- /dev/null +++ b/src/Games/Blackjack.java @@ -0,0 +1,130 @@ +package src.Games; + +import java.util.Random; +import src.User.Profile; +import java.util.Scanner; +import src.Games.Deck; +public class Blackjack implements Games { + + private Profile gamer; + private Deck deck = new Deck(); + private Scanner scanner = new Scanner(System.in); + + // Constructor + public Blackjack(Profile gamer) { + this.gamer = gamer; + } + + @Override + public String write_rules() { + return "Blackjack Rules:\n" + + "1. Your goal is to have a card total closest to 21 without exceeding it.\n" + + "2. Card values: 2-10 as face value, J/Q/K as 10 points, and A as 1 or 11.\n" + + "3. Choose 'Hit' to draw a card or 'Stand' to stop drawing.\n" + + "4. Dealer draws cards until reaching 17 or higher.\n" + + "5. A Blackjack (21) pays 3x your bet."; + } + + @Override + public int MuzJoeTax(int bet) { + System.out.println("No tax is applied in Blackjack."); + System.out.println("Regards to Banana Joe"); + return bet; + } + + @Override + public void play() { + System.out.println("Welcome to Blackjack!"); + System.out.println(write_rules()); + deck.shuffleDeck(); + + while (true) { + System.out.println("---------------------------------"); + System.out.println("Your current balance: " + gamer.getCoin()); + System.out.println("---------------------------------"); + + // Get the bet amount + System.out.print("Enter your bet amount: "); + int bet = scanner.nextInt(); + scanner.nextLine(); // Consume the newline + + if (bet < 0 || bet > gamer.getCoin()) { + System.out.println("Invalid bet amount. Try again."); + continue; + } + + bet = MuzJoeTax(bet); + + // Initial card dealing + deck.dealCard(deck.getPlayer()); + deck.dealCard(deck.getPlayer()); + deck.dealCard(deck.getDealer()); + deck.dealCard(deck.getDealer()); + + deck.showCards(); + + while (deck.calculateHandValue(deck.getPlayer()) < 21) { + System.out.println("1. Hit (Draw a card)\n2. Stand (Stop drawing)"); + int choice = scanner.nextInt(); + scanner.nextLine(); + + if (choice == 1) { + deck.dealCard(deck.getPlayer()); + deck.calculateValue(); + deck.showCards(); + + if (deck.calculateHandValue(deck.getPlayer()) > 21) { + System.out.println("Bust! You exceeded 21. The dealer wins."); + gamer.lose_bet(bet); + break; + } + } else if (choice == 2) { + break; + } else { + System.out.println("Invalid choice! Please select 1 or 2."); + } + } + + if (deck.calculateHandValue(deck.getPlayer()) <= 21) { + System.out.println("Revealing the dealer's cards:"); + deck.showFinalCards(); + + while (deck.calculateHandValue(deck.getDealer()) < 17) { + deck.dealCard(deck.getDealer()); + deck.calculateValue(); + deck.showFinalCards(); + } + + // Determine the outcome + int playerValue = deck.calculateHandValue(deck.getPlayer()); + int dealerValue = deck.calculateHandValue(deck.getDealer()); + + if (playerValue == 21 && dealerValue != 21) { + System.out.println("Blackjack! You win."); + gamer.win_bet(bet * 3); + } else if (dealerValue > 21 || playerValue > dealerValue) { + System.out.println("You win!"); + gamer.win_bet(bet * 2); + } else if (playerValue == dealerValue) { + System.out.println("It's a draw! Your bet is returned."); + } else { + System.out.println("The dealer wins!"); + gamer.lose_bet(bet); + } + } + + // Ask if the player wants to play again + System.out.print("\nPress 'q' to quit, or any other key to play again: "); + String continueGame = scanner.nextLine().trim(); + if (continueGame.equalsIgnoreCase("q")) { + System.out.println("Thank you for playing Blackjack! Goodbye."); + break; + } + + if (deck.hasSufficientCards()) { + System.out.println("Shuffling the deck."); + deck.shuffleDeck(); + } + } + } +} diff --git a/src/Games/Deck.java b/src/Games/Deck.java new file mode 100644 index 0000000..44f1629 --- /dev/null +++ b/src/Games/Deck.java @@ -0,0 +1,255 @@ +package src.Games; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + +public class Deck{ + + private ArrayList deck = new ArrayList<>(); + private ArrayList shuffledDeck = new ArrayList<>(); + private ArrayList player = new ArrayList<>(); + private ArrayList splitPlayer = new ArrayList<>(); + private ArrayList dealer = new ArrayList<>(); + private int playerValue; + private int splitPlayerValue; + private int dealerValue; + private boolean sufficientCards; + private String[] suits = {"Diamonds", "Spades", "Clubs", "Hearts"}; + private String[] cards = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}; + private boolean cardsEqual; + + // Constructor: Create and fill the deck + public Deck() { + for (String suit : suits) { + for (String card : cards) { + deck.add(suit + " " + card); + } + } + } + + public void shuffleDeck() { + this.shuffledDeck = new ArrayList<>(deck); + Collections.shuffle(this.shuffledDeck); + this.sufficientCards = false; + } + + public void calculateValue() { + this.playerValue = calculateHandValue(this.player); + this.dealerValue = calculateHandValue(this.dealer); + + if (!splitPlayer.isEmpty()) { + this.splitPlayerValue = calculateHandValue(this.splitPlayer); + } + } + + int calculateHandValue(ArrayList hand) { + int total = 0; + int aceCount = 0; + + for (String card : hand) { + String cardValue = card.split(" ")[1]; + + if (cardValue.equals("J") || cardValue.equals("Q") || cardValue.equals("K")) { + total += 10; + } else if (cardValue.equals("A")) { + aceCount++; + total += 11; + } else { + total += Integer.parseInt(cardValue); + } + } + + while (total > 21 && aceCount > 0) { + total -= 10; + aceCount--; + } + + return total; + } + + public boolean hasSufficientCards() { + return this.sufficientCards; + } + + public void dealCard(ArrayList hand) { + Random rand = new Random(); + int index = rand.nextInt(shuffledDeck.size()); + String card = shuffledDeck.remove(index); + hand.add(card); + + if (shuffledDeck.size() <= 12) { + this.sufficientCards = true; + } + } + + public void splitCard(ArrayList hand) { + String lastCard = hand.get(hand.size() - 1); + String secondLastCard = hand.get(hand.size() - 2); + + String lastCardValue = lastCard.split(" ")[1]; + String secondLastCardValue = secondLastCard.split(" ")[1]; + + if (lastCardValue.equals(secondLastCardValue)) { + hand.remove(hand.size() - 1); + String temp = hand.get(hand.size() - 1); + splitPlayer.add(temp); + } + } + + public void checkCardsEqual(ArrayList hand) { + String lastCard = hand.get(hand.size() - 1); + String secondLastCard = hand.get(hand.size() - 2); + + String lastCardValue = lastCard.split(" ")[1]; + String secondLastCardValue = secondLastCard.split(" ")[1]; + + if (lastCardValue.equals(secondLastCardValue)) { + this.cardsEqual = true; + } else { + this.cardsEqual = false; + } + } + + public ArrayList getDeck() { + return deck; + } + + public void setDeck(ArrayList deck) { + this.deck = deck; + } + + public ArrayList getShuffledDeck() { + return shuffledDeck; + } + + public void setShuffledDeck(ArrayList shuffledDeck) { + this.shuffledDeck = shuffledDeck; + } + + public ArrayList getPlayer() { + return player; + } + + public void setPlayer(ArrayList player) { + this.player = player; + } + + public ArrayList getSplitPlayer() { + return splitPlayer; + } + + public void setSplitPlayer(ArrayList splitPlayer) { + this.splitPlayer = splitPlayer; + } + + public ArrayList getDealer() { + return dealer; + } + + public void setDealer(ArrayList dealer) { + this.dealer = dealer; + } + + public int getPlayerValue() { + return playerValue; + } + + public void setPlayerValue(int playerValue) { + this.playerValue = playerValue; + } + + public int getSplitPlayerValue() { + return splitPlayerValue; + } + + public void setSplitPlayerValue(int splitPlayerValue) { + this.splitPlayerValue = splitPlayerValue; + } + + public int getDealerValue() { + return dealerValue; + } + + public void setDealerValue(int dealerValue) { + this.dealerValue = dealerValue; + } + + public String[] getSuits() { + return suits; + } + + public void setSuits(String[] suits) { + this.suits = suits; + } + + public String[] getCards() { + return cards; + } + + public void setCards(String[] cards) { + this.cards = cards; + } + + public void showCards() { + System.out.print("Dealer's Cards: "); + System.out.print(dealer.get(0) + "--"); + System.out.print("X"); + System.out.println("\n-------------------------\n"); + + System.out.print("Player's Cards: "); + for (String card : player) { + System.out.print(card + " "); + } + + if (!splitPlayer.isEmpty()) { + System.out.print("\nPlayer's Split Cards: "); + for (String card : splitPlayer) { + System.out.print(card + " "); + } + } + System.out.println("\n-------------------------\n"); + } + + public void showFinalCards() { + System.out.print("Dealer's Cards: "); + for (String card : dealer) { + System.out.print(card + "--"); + } + System.out.println("\n-------------------------\n"); + + System.out.print("Player's Cards: "); + for (String card : player) { + System.out.print(card + " "); + } + + if (!splitPlayer.isEmpty()) { + System.out.print("\nPlayer's Split Cards: "); + for (String card : splitPlayer) { + System.out.print(card + " "); + } + } + System.out.println("\n-------------------------\n"); + } + + public void reset() { + player.clear(); + splitPlayer.clear(); + dealer.clear(); + + playerValue = 0; + splitPlayerValue = 0; + dealerValue = 0; + sufficientCards = false; + cardsEqual = false; + } + + public boolean areCardsEqual() { + return cardsEqual; + } + + public void setCardsEqual(boolean cardsEqual) { + this.cardsEqual = cardsEqual; + } +} diff --git a/src/Games/Follow_the_lady.java b/src/Games/Follow_the_lady.java new file mode 100644 index 0000000..750449f --- /dev/null +++ b/src/Games/Follow_the_lady.java @@ -0,0 +1,107 @@ +package src.Games; + +import java.util.Random; +import src.User.Profile; +import java.util.Scanner; + +public class Follow_the_lady implements Games { + + private Profile gamer; + private Scanner scanner = new Scanner(System.in); + private Random random = new Random(); + + + public Follow_the_lady(Profile gamer) { + this.gamer = gamer; + } + + @Override + public String write_rules() { + return "Follow the Lady Game Rules:\n" + + "1. Try to find the 'Lady' card among three cards.\n" + + "2. The cards are shuffled, and you are asked to guess the position of the 'Lady' card.\n" + + "3. If you guess correctly, you win 2 times your bet.\n" + + "4. If you guess incorrectly, you lose your bet."; + } + + @Override + public int MuzJoeTax(int bet) { + double number = Math.random(); // Generates a random number between 0 and 1 + + if (number < 0.035) { + System.out.println("Banana Joe demands a tax"); + int randomNumber1 = random.nextInt(100) + 1; + + int tax = (int) Math.round(randomNumber1 * (bet / 100.0)); + int remaining = bet - tax; + + System.out.println("Tax taken from your deposited money: " + tax); + System.out.println("Remaining deposited money: " + remaining); + + return remaining; + } else { + System.out.println("Banana Joe spared you, no tax this time"); + return bet; + } + } + + @Override + public void play() { + System.out.println("Welcome to Follow the Lady!"); + + boolean playAgain = true; + + while (playAgain) { + System.out.println(write_rules()); + System.out.println("Your current balance: " + gamer.getCoin()); + + // Get the bet amount + int bet; + while (true) { + System.out.println("Enter your bet amount: "); + bet = scanner.nextInt(); + scanner.nextLine(); // Consume the newline + + if (bet > 0 && bet <= gamer.getCoin()) { + break; + } else { + System.out.println("Invalid bet amount! Make sure it's positive and within your balance."); + } + } + + bet = MuzJoeTax(bet); + + int ladyPosition = random.nextInt(3) + 1; // Random position between 1 and 3 + + System.out.println("Shuffling the cards..."); + System.out.println("1-2-3"); // + System.out.print("Which position do you think the 'Lady' card is in? (1/2/3): "); + int guess = scanner.nextInt(); + + if (guess == ladyPosition) { + System.out.println("Congratulations! You guessed correctly. The 'Lady' card was in position " + ladyPosition + "."); + gamer.win_bet(bet * 2); + } else { + System.out.println("Sorry! Wrong guess. The 'Lady' card was in position " + ladyPosition + "."); + gamer.lose_bet(bet); + } + + scanner.nextLine(); + System.out.println("Do you want to play again? (yes/no): "); + String playAgainInput = scanner.nextLine().trim(); + + while (true) { + if (playAgainInput.equalsIgnoreCase("no")) { + playAgain = false; + System.out.println("Thank you for playing Follow the Lady! Goodbye."); + break; + } else if (playAgainInput.equalsIgnoreCase("yes")) { + break; + } else { + System.out.println("Please enter 'yes' or 'no':"); + playAgainInput = scanner.nextLine().trim(); + } + } + } + } +} diff --git a/src/Games/Games.java b/src/Games/Games.java new file mode 100644 index 0000000..5cfb0cf --- /dev/null +++ b/src/Games/Games.java @@ -0,0 +1,15 @@ +package src.Games; + +import src.User.Profile; + +public interface Games { + + public void play(); + + public String write_rules(); + + public int MuzJoeTax(int bet); + + + +} diff --git a/src/Games/Heads_or_tails.java b/src/Games/Heads_or_tails.java new file mode 100644 index 0000000..d284578 --- /dev/null +++ b/src/Games/Heads_or_tails.java @@ -0,0 +1,136 @@ +package src.Games; + +import java.util.Random; +import src.User.Profile; +import java.util.Scanner; + +public class Heads_or_tails implements Games { + + private Profile gamer; + private Scanner scanner = new Scanner(System.in); + private Random random = new Random(); + + + public Heads_or_tails(Profile gamer) { + this.gamer = gamer; + } + + @Override + public String write_rules() { + return "Heads or Tails Game Rules:\n" + + "1. Choose the amount you want to bet.\n" + + "2. Predict heads or tails.\n" + + "3. If your prediction is correct, you win double your bet.\n" + + "4. If your prediction is wrong, you lose your bet."; + } + + @Override + public int MuzJoeTax(int bet) { + double number = Math.random(); + + if (number < 0.035) { + System.out.println("Banana Joe demands a tax"); + int randomNumber1 = random.nextInt(100) + 1; + + int tax = (int) Math.round(randomNumber1 * (bet / 100.0)); + int remaining = bet - tax; + + System.out.println("Tax taken from your deposited money: " + tax); + System.out.println("Remaining deposited money: " + remaining); + + return remaining; + } else { + System.out.println("Banana Joe spared you, no tax this time"); + return bet; + } + } + + @Override + public void play() { + System.out.println("Welcome to Heads or Tails!"); + + boolean playAgain = true; + + while (playAgain) { + System.out.println(write_rules()); + System.out.println("Your current balance: " + gamer.getCoin()); + + // Get the bet amount + int bet; + while (true) { + System.out.println("Enter your bet amount: "); + bet = scanner.nextInt(); + scanner.nextLine(); // Consume the newline + + if (bet > 0 && bet <= gamer.getCoin()) { + break; + } else { + System.out.println("Invalid bet amount! Make sure it's positive and within your balance."); + } + } + + bet = MuzJoeTax(bet); + + System.out.print("Make your prediction (1 for Heads, 2 for Tails): "); + int prediction = scanner.nextInt(); + + if (prediction != 1 && prediction != 2) { + System.out.println("Invalid choice! Please choose 1 (Heads) or 2 (Tails). Restarting the round."); + continue; + } + + double number = Math.random(); + String result; + + if (number <= 48){ + result="Heads"; + + } + + else if (number >= 48 && number <= 96) { + result = "Tails"; + } + + else{ + System.out.println("Secret Status Upright Arrived !!!!"); + result = "Upright"; + } + + + System.out.println("Result: " + result); + + if ((prediction == 1 && result.equals("Heads")) || (prediction == 2 && result.equals("Tails"))) { + System.out.println("Congratulations! You guessed correctly. You win double your bet."); + gamer.win_bet(bet * 2); + } + + else if (result.equals("Upright")) { + System.out.println("You have won 3 times your bet"); + gamer.win_bet(bet * 3); + + } + else { + System.out.println("Sorry, your guess was wrong. You lose your bet."); + gamer.lose_bet(bet); + } + + scanner.nextLine(); + System.out.println("Do you want to play again? (yes/no): "); + String playAgainInput = scanner.nextLine().trim(); + + while (true) { + if (playAgainInput.equalsIgnoreCase("no")) { + playAgain = false; + System.out.println("Thank you for playing Heads or Tails! Goodbye."); + break; + } else if (playAgainInput.equalsIgnoreCase("yes")) { + break; + } else { + System.out.println("Please enter 'yes' or 'no':"); + playAgainInput = scanner.nextLine().trim(); + } + } + } + } +} + diff --git a/src/Games/HighDice.java b/src/Games/HighDice.java new file mode 100644 index 0000000..4424ff7 --- /dev/null +++ b/src/Games/HighDice.java @@ -0,0 +1,113 @@ +package src.Games; + +import java.util.Random; +import src.User.Profile; +import java.util.Scanner; + +public class HighDice implements Games { + + private Profile gamer; + private Scanner scanner = new Scanner(System.in); + private Random random = new Random(); + + + public HighDice(Profile gamer) { + this.gamer = gamer; + } + + @Override + public String write_rules() { + return "High Dice Game Rules:\n" + + "1. The player and the computer roll the dice.\n" + + "2. The highest roll wins.\n" + + "3. In case of a tie, the game is replayed.\n" + + "4. If you win, you earn double the amount you bet."; + } + + @Override + public int MuzJoeTax(int bet) { + double number = Math.random(); // Generates a random number between 0 and 1 + + if (number < 0.035) { + System.out.println("Banana Joe demands a tax"); + int randomNumber1 = random.nextInt(100) + 1; + + int tax = (int) Math.round(randomNumber1 * (bet / 100.0)); + int remaining = bet - tax; + + System.out.println("Tax taken from your deposited money: " + tax); + System.out.println("Remaining deposited money: " + remaining); + + return remaining; + } else { + System.out.println("Banana Joe spared you, no tax this time"); + return bet; + } + } + + @Override + public void play() { + System.out.println("Welcome to High Dice!"); + + boolean playAgain = true; + + while (playAgain) { + System.out.println(write_rules()); + System.out.println("Your current balance: " + gamer.getCoin()); + + // Get the bet amount + int bet; + while (true) { + System.out.println("Enter your bet amount: "); + bet = scanner.nextInt(); + scanner.nextLine(); // Consume the newline + + if (bet > 0 && bet <= gamer.getCoin()) { + break; + } else { + System.out.println("Invalid bet amount! Make sure it's positive and within your balance."); + } + } + + // Apply Banana Joe's tax + bet = MuzJoeTax(bet); + + // Roll the dice + int playerRoll = random.nextInt(6) + 1; // Dice roll between 1-6 + int computerRoll = random.nextInt(6) + 1; + + System.out.println("You rolled: " + playerRoll); + System.out.println("Computer rolled: " + computerRoll); + + // Determine the winner + if (playerRoll > computerRoll) { + System.out.println("You win!"); + gamer.win_bet(bet * 2); + } else if (playerRoll < computerRoll) { + System.out.println("You lose!"); + gamer.lose_bet(bet); + } else { + System.out.println("It's a tie! No one wins or loses. Play again."); + continue; // Replay the game in case of a tie + } + + // Ask if the player wants to play again + System.out.println("Do you want to play again? (yes/no): "); + String playAgainInput = scanner.nextLine().trim(); + + while (true) { + if (playAgainInput.equalsIgnoreCase("no")) { + playAgain = false; + System.out.println("Thank you for playing High Dice! Goodbye."); + break; + } else if (playAgainInput.equalsIgnoreCase("yes")) { + break; + } else { + System.out.println("Please enter 'yes' or 'no':"); + playAgainInput = scanner.nextLine().trim(); + } + } + + } + } +} diff --git a/src/Games/RockPaperScissors.java b/src/Games/RockPaperScissors.java new file mode 100644 index 0000000..df5010b --- /dev/null +++ b/src/Games/RockPaperScissors.java @@ -0,0 +1,125 @@ +package src.Games; + +import src.User.Profile; +import java.util.Random; +import java.util.Scanner; + +public class RockPaperScissors implements Games { + private Profile gamer; + + private final Scanner scanner = new Scanner(System.in); + private final Random random = new Random(); + + private final String[] options = {"Rock", "Paper", "Scissors"}; + boolean playAgain = true; + + public RockPaperScissors(Profile gamer) { + this.gamer = gamer; + } + + public void winChecker(int bet, String playerChoice, String computerChoice) { + if (playerChoice.equalsIgnoreCase(computerChoice)) { + System.out.println("It's a tie!"); + } else if ((playerChoice.equalsIgnoreCase("Rock") && computerChoice.equals("Scissors")) || + (playerChoice.equalsIgnoreCase("Paper") && computerChoice.equals("Rock")) || + (playerChoice.equalsIgnoreCase("Scissors") && computerChoice.equals("Paper"))) { + gamer.win_bet(bet * 3); + System.out.println("You win!"); + } else { + System.out.println("You lose!"); + gamer.lose_bet(bet); + } + } + + @Override + public String write_rules() { + return "Rock-Paper-Scissors Game Rules:\n" + + "1. Rock beats scissors.\n" + + "2. Paper beats rock.\n" + + "3. Scissors beats paper.\n" + + "4. If the player and the computer make the same choice, the game ends in a draw."; + } + + public int MuzJoeTax(int bet) { + double number = Math.random(); + + if (number < 0.035) { + System.out.println("Banana Joe demands a tax"); + int randomNumber1 = random.nextInt(100) + 1; + + + int tax = (int) Math.round(randomNumber1 * (bet / 100.0)); + int remaining = bet - tax; + + System.out.println("Tax taken from your deposited money: " + tax); + System.out.println("Remaining deposited money: " + remaining); + + return remaining; + } else { + System.out.println("Banana Joe spared you, no tax this time"); + return bet; + } + } + + + @Override + public void play() { + System.out.println("Welcome to RockPaperScissors!"); + + while (playAgain) { + System.out.println(write_rules()); + boolean betCheck = true; + int bet = 0; + while (betCheck) { + System.out.println("Your current budget: "+gamer.getCoin()); + System.out.println("Enter your bet: "); + bet = scanner.nextInt(); + scanner.nextLine(); + if (bet <= gamer.getCoin()) { + betCheck = false; + } else { + System.out.println("Your coin is not enough for that bet !!!"); + } + } + bet = MuzJoeTax(bet); + System.out.println("Enter your choice (Rock, Paper, Scissors): "); + String playerChoice = scanner.nextLine().trim(); + System.out.println("Your choice" + playerChoice); + + // Validate input + if (!playerChoice.equalsIgnoreCase("Rock") && + !playerChoice.equalsIgnoreCase("Paper") && + !playerChoice.equalsIgnoreCase("Scissors")) { + System.out.println("Invalid choice. Please choose Rock, Paper, or Scissors."); + continue; + } + + // Computer choice + String computerChoice = options[random.nextInt(3)]; + System.out.println("Computer chose: " + computerChoice); + + // Determine winner + this.winChecker(bet, playerChoice, computerChoice); + + // Play again? + System.out.println("Do you want to play again? (yes/no): "); + String playAgainInput = scanner.nextLine().trim(); + + while (true) { + if (playAgainInput.equalsIgnoreCase("no")) { + playAgain = false; + System.out.println("Thank you for playing High Dice! Goodbye."); + break; + } else if (playAgainInput.equalsIgnoreCase("yes")) { + break; + } else { + System.out.println("Please enter 'yes' or 'no':"); + playAgainInput = scanner.nextLine().trim(); + } + } + } + + //scanner.close(); + } + +} diff --git a/src/Games/Roulette.java b/src/Games/Roulette.java new file mode 100644 index 0000000..7ba9559 --- /dev/null +++ b/src/Games/Roulette.java @@ -0,0 +1,149 @@ +package src.Games; + +import java.util.ArrayList; +import java.util.Random; +import src.User.Profile; +import java.util.Scanner; + +public class Roulette implements Games { + + private Profile gamer; + private ArrayList bets = new ArrayList<>(); + private ArrayList amounts = new ArrayList<>(); + private String color; + private String result; + private String range; + private int totalBet; + private int totalWin; + private Scanner scanner = new Scanner(System.in); + private Random random = new Random(); + + public Roulette(Profile gamer) { + this.gamer = gamer; + } + + @Override + public String write_rules() { + return "Roulette Game Rules:\n" + + "1. Place a bet on a number (0-36), color (Red/Black/Green), or range (1-12, 13-24, 25-36).\n" + + "2. If your color guess is correct, you win 2x your bet.\n" + + "3. If your range guess is correct, you win 3x your bet.\n" + + "4. If your number guess is correct, you win 36x your bet."; + } + + private void spin_wheel() { + int number = random.nextInt(37); // Random number between 0 and 36 + + // Determine the color + if (number == 0) { + this.color = "Green"; + } else if (number % 2 == 0) { + this.color = "Red"; + } else { + this.color = "Black"; + } + + this.result = String.valueOf(number); + + // Determine the range + if (number >= 1 && number <= 12) { + this.range = "1-12"; + } else if (number >= 13 && number <= 24) { + this.range = "13-24"; + } else if (number >= 25 && number <= 36) { + this.range = "25-36"; + } else { + this.range = "0"; + } + + System.out.println("Wheel result: " + result + " (" + color + "), Range: " + range); + } + + @Override + public int MuzJoeTax(int bet) { + System.out.println("No tax is applied in Roulette."); + System.out.println("Regards to Banana Joe"); + return bet; + } + + @Override + public void play() { + System.out.println("Welcome to Roulette!"); + + boolean playAgain = true; + + while (playAgain) { + System.out.println(write_rules()); + + bets.clear(); + amounts.clear(); + totalBet = 0; + totalWin = 0; + + System.out.println("---------------------------------"); + System.out.println("Your current balance: " + gamer.getCoin()); + System.out.println("---------------------------------"); + + while(true){ + + System.out.print("Please choose where to place your bet (Number/Color/Range): "); + String bet = scanner.nextLine(); + System.out.print("Enter your bet amount: "); + int betAmount = scanner.nextInt(); + + if (betAmount > gamer.getCoin()){ + System.out.println("Your coin is not enough for that bet !!!"); + continue; + } + + + scanner.nextLine(); + + bets.add(bet); + amounts.add((int) betAmount); + totalBet += betAmount; + + System.out.print("Enter 'y' to place another bet, or any other key to spin the wheel: "); + String moreBets = scanner.nextLine(); + if (!moreBets.equalsIgnoreCase("y")) { + break; + } + } + + System.out.println("\nLet the game begin!"); + spin_wheel(); + + for (int i = 0; i < bets.size(); i++) { + String bet = bets.get(i); + int betAmount = amounts.get(i); + + if (bet.equalsIgnoreCase(color)) { + totalWin += betAmount * 2; + } + + if (bet.equalsIgnoreCase(range)) { + totalWin += betAmount * 3; + } + + if (bet.equals(result)) { + totalWin += betAmount * 36; + gamer.win_bet(betAmount* 36); + } + } + + System.out.println(); + + if (totalWin > 0) { + System.out.println("Congratulations! You won " + totalWin + "!"); + gamer.win_bet(totalWin); + } else { + System.out.println("Sorry, no winnings this time."); + } + + + + } + + + } +} diff --git a/src/Games/Wheel.java b/src/Games/Wheel.java new file mode 100644 index 0000000..4ec3f3c --- /dev/null +++ b/src/Games/Wheel.java @@ -0,0 +1,138 @@ +package src.Games; + +import java.util.Random; +import src.User.Profile; +import java.util.Scanner; + +public class Wheel implements Games { + + private Profile gamer; + private Scanner scanner = new Scanner(System.in); + private Random random = new Random(); + + private double[] cak_guvenli = {1, 2, 2, 3, 3, 1, 1, 0, 0, 0}; + private double[] cak_orta = {0, 0, 1, 1, 1, 0, 2, 0, 4, 5}; + private double[] cak_riskli = {0, 0, 2, 0, 21, 0, 1, 0, 0, 13}; + + // Constructor + public Wheel(Profile gamer) { + this.gamer = gamer; + } + + @Override + public String write_rules() { + return "Wheel Game Rules:\n" + + "1. Choose the amount of money to bet.\n" + + "2. Select a wheel based on risk level (Safe, Medium, or Risky).\n" + + "3. Spin the wheel and see your results!"; + } + + @Override + public int MuzJoeTax(int bet) { + double number = Math.random(); + + if (number < 0.035) { + System.out.println("Banana Joe demands a tax"); + int randomNumber1 = random.nextInt(100) + 1; + + int tax = (int) Math.round(randomNumber1 * (bet / 100.0)); + int remaining = bet - tax; + + System.out.println("Tax taken from your deposited money: " + tax); + System.out.println("Remaining deposited money: " + remaining); + + return remaining; + } else { + System.out.println("Banana Joe spared you, no tax this time"); + return bet; + } + } + + @Override + public void play() { + System.out.println("Welcome to the Wheel Game!"); + + boolean playAgain = true; + + while (playAgain) { + System.out.println(write_rules()); + System.out.println("Your current balance: " + gamer.getCoin()); + + // Get the bet amount + int bet; + while (true) { + System.out.println("Enter your bet amount: "); + bet = scanner.nextInt(); + scanner.nextLine(); // Consume the newline + + if (bet > 0 && bet <= gamer.getCoin()) { + break; + } else { + System.out.println("Invalid bet amount! Make sure it's positive and within your balance."); + } + } + + // Apply Banana Joe's tax + bet = MuzJoeTax(bet); + + // Select the wheel + System.out.println("1. Safe Wheel\n2. Medium Wheel\n3. Risky Wheel"); + System.out.print("Choose a wheel (1 for Safe, 2 for Medium, 3 for Risky): "); + int choice = scanner.nextInt(); + scanner.nextLine(); // Consume the newline + + double[] selectedWheel; + switch (choice) { + case 1: + selectedWheel = cak_guvenli; + break; + case 2: + selectedWheel = cak_orta; + break; + case 3: + selectedWheel = cak_riskli; + break; + default: + System.out.println("Invalid choice, defaulting to Safe Wheel."); + selectedWheel = cak_guvenli; + break; + } + + // Spin the wheel + int index = random.nextInt(selectedWheel.length); + double result = selectedWheel[index]; + + System.out.println("Wheel result: " + result); + + if (result > 1) { + System.out.println("You win: " + (bet * result) + "!"); + gamer.win_bet((int) (bet * result)); + } + + else if (result == 1) { + System.out.println("You got what you gave. Good luck."); + + } else { + System.out.println("You lose your bet."); + gamer.lose_bet(bet); + } + + // Ask if the player wants to play again + System.out.println("Do you want to play again? (yes/no): "); + String playAgainInput = scanner.nextLine().trim(); + + while (true) { + if (playAgainInput.equalsIgnoreCase("no")) { + playAgain = false; + System.out.println("Thank you for playing the Wheel Game! Goodbye."); + break; + } else if (playAgainInput.equalsIgnoreCase("yes")) { + break; + } else { + System.out.println("Please enter 'yes' or 'no':"); + playAgainInput = scanner.nextLine().trim(); + } + } + } + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..87110a4 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,119 @@ +package src; + +import src.Clothes.*; +import src.DataBases.DataLoader; +import src.DataBases.DataSaver; +import src.DataBases.GameBuilder; +import src.Games.*; +import src.User.Profile; + +import java.security.cert.CertStoreSpi; +import java.util.Scanner; + +public class Main { + public static void exit() { + System.out.println("Goodbye!"); + System.exit(0); + } + + public static void playGameMenu(Scanner scanner, Profile profile){ + System.out.println("Game Menu : \n" + + " 1 - Rock Paper Scissors\n" + + "2 - Heads or Tails\n" + + "3 -High Dice\n" + + "4....Roulette\n" + + "5....Wheel\n" + + "6....Find the Lady\n" + + "7....Blackjack\n" + + " 0 - Back Main Menu\n" + ); + + int option = scanner.nextInt(); + switch(option){ + case 1: + Games game = new RockPaperScissors(profile); + game.play(); + break; + case 2: + game = new Heads_or_tails(profile); + game.play(); + break; + case 3: + game = new HighDice(profile); + game.play(); + break; + case 4: + game = new Roulette(profile); + game.play(); + break; + case 5: + game = new Wheel(profile); + game.play(); + break; + case 6: + game = new Follow_the_lady(profile); + game.play(); + break; + case 7: + game = new Blackjack(profile); + game.play(); + break; + case 0: + System.out.println("Returning to the main menu..."); + return; + default: + System.out.println("Invalid option. Please select a valid option."); + } + } + public static void mainMenu(Scanner scanner, Profile profile, Store store){ + System.out.println("Main Menu : \n" + + "1 - Visit Inventory\n" + + "2 - Visit Store\n" + + "3 - Change Clothes\n" + + "4 - Play Game\n" + + "0 - Exit\n" + ); + + int option = scanner.nextInt(); + switch(option){ + case 0: + DataSaver data_saver = new DataSaver(); + data_saver.save(profile); + data_saver.save(store); + exit(); + break; + case 1: + profile.display_clothes(); + break; + case 2: + store.visit_store(profile); + break; + case 3: + profile.wear_clothes(); + break; + case 4: + playGameMenu(scanner, profile); + break; + } + } + + public static void main(String[] args) { + + DataSaver data_saver = new DataSaver(); + GameBuilder game_builder = new GameBuilder(); + + Profile profile = game_builder.getProfile(); + Store store = game_builder.getStore(); + + Scanner scanner = new Scanner(System.in); + + System.out.println("Welcome to Banana Republic"); + while(true){ + mainMenu(scanner, profile, store); + } + + + + } + +} \ No newline at end of file diff --git a/src/User/Inventory.java b/src/User/Inventory.java new file mode 100644 index 0000000..54f76b8 --- /dev/null +++ b/src/User/Inventory.java @@ -0,0 +1,46 @@ +package src.User; + +import src.Clothes.Abstract_Clothes; + +import java.util.ArrayList; +import java.util.NoSuchElementException; + +public class Inventory { + + protected ArrayList clothesList = new ArrayList<>(); + + public void add_clothes (Abstract_Clothes c){ + clothesList.add(c); + } + public void display_inventory(){ + for (Abstract_Clothes c : clothesList) { + c.getInfo(); + } + } + + public ArrayList get_inventory_ids(){ + ArrayList inventory_ids = new ArrayList(); + for (Abstract_Clothes c : clothesList) { + inventory_ids.add(c.getID()); + } + return inventory_ids; + } + + public Abstract_Clothes get_clothes(int id){ + for (Abstract_Clothes c : clothesList) { + if (c.getID() == id) { + return c; + } + } + throw new NoSuchElementException("There is no clothes with that Id"); + } + + public String toString(){ + String inventory_ids = ""; + for (Abstract_Clothes c : clothesList) { + inventory_ids = inventory_ids + c.getID() + "-"; + } + inventory_ids = inventory_ids.substring(0, inventory_ids.length() - 1); + return inventory_ids; + } +} diff --git a/src/User/Profile.java b/src/User/Profile.java new file mode 100644 index 0000000..1e9c428 --- /dev/null +++ b/src/User/Profile.java @@ -0,0 +1,82 @@ +package src.User; + +import src.Clothes.Abstract_Clothes; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Profile { + Scanner input = new Scanner(System.in); + + private String nickname; + private String gender; + private double coin; + private Abstract_Clothes clothes; + + private Inventory inventory = new Inventory(); + + public Profile(String nickname, String gender, double coin){ + this.nickname = nickname; + this.gender = gender; + this.coin = coin; + + } + + public void add_clothes(Abstract_Clothes c){inventory.add_clothes(c);} + public void buy_clothes(Abstract_Clothes c){ + this.coin -= c.getPrice(); + inventory.add_clothes(c); + } + public void display_clothes(){ + if (clothes != null){ + System.out.println("You are wearing : "); + clothes.getInfo(); + } + + System.out.println("Clothes in your Inventory: "); + inventory.display_inventory(); + } + + public void wear_clothes(){ + System.out.println("Clothes in your Inventory: "); + inventory.display_inventory(); + ArrayList inventory_ids = inventory.get_inventory_ids(); + + System.out.println("Select one of them : "); + int option = input.nextInt(); + + if(inventory_ids.contains(option)){ + System.out.println("You are wearing : "); + Abstract_Clothes c = inventory.get_clothes(option); + this.clothes = c; + this.clothes.getInfo(); + + } else { + System.out.println("Invalid ID"); + System.out.println("-------------------------------------"); + } + } + + public void setClothes(Abstract_Clothes c){ + this.clothes = c; + } + + public double getCoin(){return this.coin;} + public void setCoin(double coin){this.coin = coin;} + + public Inventory getInventory(){return this.inventory;} + + public void win_bet(int bet){ + this.coin += bet; + } + + public void lose_bet(int bet){ + this.coin -= bet; + } + + public String toString(){ + return nickname + "," + gender + "," + coin + "," + inventory.toString(); + } + +} +