Kiytirik da olsa bir oyun yazmaya calisiyorum.
Bu oyunun amaci:
Player(kullanici)
Bot1
Bot2
Olmak uzere 3 oyuncu var
Her oyuncuda 3 tane kart olacak.
Her oyuncu birinden kart alip istedigi karti digerine atacak(player —>bot1 bot1---->bot2 ,bot2—>player 'e kart atacak sekilde.Yani bot1,playerden kart alip bot2 ye kart atacak sekilde
Elinde 3 tane ayni karti olan oyuncu oyunu kazanir.
Himbilin bir versiyonu diyebiliriz.
Asagidaki kodlari derleyince hata almiyorum.Ancak bu oyunda her oyuncu icin bir deste olusturmasi gerekirken desteyi olusturmuyor.Asagida da goreceginiz gibi kullanici bir deger girdigi zaman(A gibi) uygulamayi kapatiyor.Kisacasi ben bu uygulamada oyuncularin destesini dagitamiyorum(yapamadigim projelerden biri☺).Bu sorunu cozebilirseniz memmun olurum.
Insallah bu sorunumu guzel anlatabilmisimdir.
import random
class oyun():
def __init__(self,toplam_deste):
self.oyuncu_deste = []
self.toplam_deste = toplam_deste
@property
def deste_olustur(self):
return self.oyuncu_deste
@deste_olustur.setter
def deste_olustur(self):
for i in range(3):
kart = random.randrange(len(self.toplam_deste)-1)
del self.toplam_deste[kart]
a = self.toplam_deste[kart]
self.oyuncu_deste.append(a)
return self.oyuncu_deste
def kart_at(self):
print(self.oyuncu_deste)
secilen = input("Atmak istediginiz kart:")
if not secilen:
print("Oyundan cikiliyor...")
quit()
elif len(secilen) == 1 and secilen in self.deste_olustur:
self.oyuncu_deste.remove(secilen)
return secilen
else:
print("Sahtekarlik yaptiniz!")
quit()
player = oyun(["A","A","A","B","B","B","C","C","C"])
player.deste_olustur
bot1 = oyun(player.toplam_deste)
bot1.deste_olustur
bot2 = oyun(bot1.toplam_deste)
bot2.deste_olustur
ad = input("Adiniz nedir efendim?")
while "a"=="a":
if player.oyuncu_deste.count("A") == 3:
print("Bu oyunu {} kazandi!".format(ad))
quit()
if player.oyuncu_deste.count("B") == 3:
print("Bu oyunu {} kazandi!".format(ad))
quit()
if player.oyuncu_deste.count("C") == 3:
print("Bu oyunu {} kazandi!".format(ad))
quit()
for i in player.deste_olustur:
print(i,end=" ")
bot1.deste_olustur.append(player.kart_at())
if player.oyuncu_deste.count("A") == 3:
print("Bu oyunu player kazandi!".format(ad))
quit()
if player.oyuncu_deste.count("B") == 3:
print("Bu oyunu {} kazandi!".format(ad))
quit()
if player.oyuncu_deste.count("C") == 3:
print("Bu oyunu {} kazandi!".format(ad))
quit()
#player icin
if bot1.oyuncu_deste.count("A") == 3:
print("Bu oyunu bot1 kazandi!")
quit()
if bot1.oyuncu_deste.count("B") == 3:
print("Bu oyunu bot1 kazandi!")
quit()
if bot1.oyuncu_deste.count("C") == 3:
print("Bu oyunu bot1 kazandi!")
quit()
sayilar = []
a_sayi = bot1.oyuncu_deste.count("A")
b_sayi = bot1.oyuncu_deste.count("B")
c_sayi = bot1.oyuncu_deste.count("C")
sayilar.extend([a_sayi,b_sayi,c_sayi])
if min(sayilar) == a_sayi:
bot1.deste_olustur.remove("A")
bot2.deste_olustur.append("A")
if min(sayilar) == b_sayi:
bot1.deste_olustur.remove("B")
bot2.deste_olustur.append("B")
if min(sayilar) == c_sayi:
bot1.deste_olustur.remove("C")
bot2.deste_olustur.append("C")
if bot1.oyuncu_deste.count("A") == 3:
print("Bu oyunu bot1 kazandi!")
quit()
if bot1.oyuncu_deste.count("B") == 3:
print("Bu oyunu bot1 kazandi!")
quit()
if bot1.oyuncu_deste.count("C") == 3:
print("Bu oyunu bot1 kazandi!")
quit()
#bot1 icin
if bot2.oyuncu_deste.count("A") == 3:
print("Bu oyunu bot2 kazandi!")
quit()
if bot2.oyuncu_deste.count("B") == 3:
print("Bu oyunu bot2 kazandi!")
quit()
if bot2.oyuncu_deste.count("C") == 3:
print("Bu oyunu bot2 kazandi!")
quit()
sayilar = []
a_sayi = bot2.oyuncu_deste.count("A")
b_sayi = bot2.oyuncu_deste.count("B")
c_sayi = bot2.oyuncu_deste.count("C")
sayilar.extend([a_sayi,b_sayi,c_sayi])
if min(sayilar) == a_sayi:
bot2.deste_olustur.remove("A")
player.deste_olustur.append("A")
if min(sayilar) == b_sayi:
bot2.deste_olustur.remove("B")
player.deste_olustur.append("B")
if min(sayilar) == c_sayi:
bot2.deste_olustur.remove("C")
player.deste_olustur.append("C")
if bot2.oyuncu_deste.count("A") == 3:
print("Bu oyunu bot2 kazandi!")
quit()
if bot2.oyuncu_deste.count("B") == 3:
print("Bu oyunu bot2 kazandi!")
quit()
if bot2.oyuncu_deste.count("C") == 3:
print("Bu oyunu bot2 kazandi!")
quit()