14 July 2025 and some saved old ones added.

This commit is contained in:
Halhadus 2025-07-14 12:07:12 +03:00
parent 62df64cead
commit 4812591cef
7 changed files with 233 additions and 0 deletions

111
14july2025/Game.java Normal file
View file

@ -0,0 +1,111 @@
import java.util.*;
import java.util.function.Function;
public class Game {
private Wallet kullanici;
public Game(Wallet kullanici) {
this.setKullanici(kullanici);
}
public void baslat() {
System.out.println(this.kullanici.getIsim());
while (true) {
if (this.getKullanici().getPara() <= 0) {
System.out.println("İflas!");
break;
}
System.out.println("Mevcut bakiye:" + this.getKullanici().getPara());
this.bj();
}
}
public void bj() {
System.out.println("Kullanmak istediğiniz miktarı giriniz:");
Scanner scanner = new Scanner(System.in);
Double miktar = scanner.nextDouble();
scanner.nextLine();
if (this.kullanici.paraGuncelleme(miktar * -1)) {
List<String> masa = new ArrayList<>();
String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
for (int i = 0; i < 4; i++) {
for (String rank : ranks) {
masa.add(rank);
}
}
Collections.shuffle(masa);
List<String> kullaniciEli = new ArrayList<>();
List<String> kurpiyerEli = new ArrayList<>();
kullaniciEli.add(masa.remove(0));
kurpiyerEli.add(masa.remove(0));
kullaniciEli.add(masa.remove(0));
kurpiyerEli.add(masa.remove(0));
Function<List<String>, Integer> degerHesapla = hand -> {
int total = 0;
int aces = 0;
for (String card : hand) {
switch (card) {
case "A": total += 11; aces++; break;
case "K": case "Q": case "J": case "10": total += 10; break;
default: total += Integer.parseInt(card);
}
}
while (total > 21 && aces > 0) {
total -= 10;
aces--;
}
return total;
};
System.out.println("Kullanıcı Eli: " + kullaniciEli + " (" + degerHesapla.apply(kullaniciEli) + ")");
System.out.println("Kurpiyer Eli: [" + kurpiyerEli.get(0) + ", ?]");
int kullaniciDeger = degerHesapla.apply(kullaniciEli);
boolean kullaniciPatladi = false;
while (kullaniciDeger < 21) {
System.out.println("Tamam mı devam mı?? (t/d)");
String tamamdevam = scanner.nextLine().trim().toLowerCase();
if (!tamamdevam.equals("d")) break;
kullaniciEli.add(masa.remove(0));
kullaniciDeger = degerHesapla.apply(kullaniciEli);
System.out.println("Kullanıcı eli: " + kullaniciEli + " (" + kullaniciDeger + ")");
if (kullaniciDeger > 21) {
System.out.println("Patladın!");
kullaniciPatladi = true;
break;
}
}
if (!kullaniciPatladi) {
int kurpiyerDeger = degerHesapla.apply(kurpiyerEli);
System.out.println("Kurpiyer Eli: " + kurpiyerEli + " (" + kurpiyerDeger + ")");
while (kurpiyerDeger < 17) {
kurpiyerEli.add(masa.remove(0));
kurpiyerDeger = degerHesapla.apply(kurpiyerEli);
System.out.println("Kurpiyer çekti: " + kurpiyerEli + " (" + kurpiyerDeger + ")");
}
if (kurpiyerDeger > 21 || kullaniciDeger > kurpiyerDeger) {
System.out.println("Kazandın!");
kullanici.paraGuncelleme(2 * miktar);
} else if (kullaniciDeger < kurpiyerDeger) {
System.out.println("Adam kazandı...");
} else {
System.out.println("Dostluk kazandı, para iade edildi.");
kullanici.paraGuncelleme(miktar);
}
}
}
}
public Wallet getKullanici() {
return this.kullanici;
}
public void setKullanici(Wallet kullanici) {
this.kullanici = kullanici;
}
}