14 July 2025 and some saved old ones added.
This commit is contained in:
parent
62df64cead
commit
4812591cef
7 changed files with 233 additions and 0 deletions
111
14july2025/Game.java
Normal file
111
14july2025/Game.java
Normal 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;
|
||||
}
|
||||
}
|
8
14july2025/Main.java
Normal file
8
14july2025/Main.java
Normal file
|
@ -0,0 +1,8 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Java BlackJack");
|
||||
Wallet kullanici = new Wallet("Mahmut Tuncer", "1000");
|
||||
Game oyun = new Game(kullanici);
|
||||
oyun.baslat();
|
||||
}
|
||||
}
|
40
14july2025/Wallet.java
Normal file
40
14july2025/Wallet.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
public class Wallet {
|
||||
private String isim;
|
||||
private Double para;
|
||||
|
||||
public Wallet(String isim, String para) {
|
||||
this.isim = isim;
|
||||
Double paraDouble = Double.valueOf(para);
|
||||
if (((paraDouble > -Double.MAX_VALUE) && (paraDouble < Double.MAX_VALUE)) && !paraDouble.isInfinite()) {
|
||||
this.para = paraDouble;
|
||||
} else {
|
||||
System.out.println("O kadar paran var hala buralarda geziyorsun. Kaybol!");
|
||||
this.para= 1d;
|
||||
}
|
||||
}
|
||||
|
||||
public String getIsim() {
|
||||
return this.isim;
|
||||
}
|
||||
|
||||
public Double getPara() {
|
||||
return this.para;
|
||||
}
|
||||
|
||||
public Boolean paraGuncelleme(Double para) {
|
||||
if (((this.getPara() > -Double.MAX_VALUE) && (this.getPara() < Double.MAX_VALUE)) && !this.getPara().isInfinite()) {
|
||||
if ((this.getPara() + para) < 0) {
|
||||
System.out.println("Yetersiz bakiye. Şu anki bakiye:" + this.getPara());
|
||||
return false;
|
||||
} else {
|
||||
this.para += para;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("O kadar paran var hala buralarda mı geziyorsun?");
|
||||
this.para = 1d;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
14july2025/old1/Baba.java
Normal file
11
14july2025/old1/Baba.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
public class Baba extends Buyukbaba{
|
||||
public Baba(String a) {
|
||||
super(a);
|
||||
super.setA(a);
|
||||
}
|
||||
|
||||
public String getA() {
|
||||
System.out.println("Bababa?");
|
||||
return super.getA();
|
||||
}
|
||||
}
|
15
14july2025/old1/Buyukbaba.java
Normal file
15
14july2025/old1/Buyukbaba.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
public class Buyukbaba {
|
||||
private String a = "Hebele";
|
||||
|
||||
public Buyukbaba(String a) {
|
||||
System.out.println(a);
|
||||
}
|
||||
|
||||
public String getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(String a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
7
14july2025/old1/Main.java
Normal file
7
14july2025/old1/Main.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Buyukbaba buyukbaba = new Buyukbaba("babababa");
|
||||
Baba baba = new Baba("bababa");
|
||||
System.out.println(baba.getA());
|
||||
}
|
||||
}
|
41
14july2025/old2/Main.java
Normal file
41
14july2025/old2/Main.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Hebele hebele1 = new Hebele();
|
||||
Hebele hebele2 = new Hebele();
|
||||
Hubele hubele1 = new Hubele();
|
||||
Hebele hebele3 = new Hubele();
|
||||
hebele1.setA("A");
|
||||
hebele2.setA(123);
|
||||
hubele1.setA(42d);
|
||||
hebele3.setA(456);
|
||||
System.out.println(hebele1.getA());
|
||||
System.out.println(hebele2.getA());
|
||||
System.out.println(hubele1.getA());
|
||||
System.out.println(hebele3.getA());
|
||||
List<Object> liste = List.of("a","b", 1);
|
||||
System.out.println(liste);
|
||||
// System.out.println("a" instanceof Object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Hebele {
|
||||
private Object a;
|
||||
|
||||
public Object getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public void setA(Object a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
||||
class Hubele extends Hebele {
|
||||
public Object getA() {
|
||||
System.out.println("???");
|
||||
return super.getA();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue