gambling.py

Created by stimorol

Created on October 12, 2022

4.93 KB

Jeu d’argent, faisant intervenir plusieurs types de jeux. Il est possible pour le joueur de modifier les paramètres graphiques, de faire des prêts, ou encore d’avoir un salaire.


from kandinsky import *
from random import *
from ion import *
from time import *

keyNums=[48,42,43,44,36,37,38,30,31,32,49]
red=(212,0,0)
green=(0,180,0)
txt=draw_string

def wait():
  while keydown(4):pass

def game(s,cash,color):
  fill_rect(0,0,322,222,color[1])
  draw_c(cash[0],color)
  num=eval(menu_nums([[""," > random()"],["[0, ","] == 0"],["[0, ","] == 0"]][s],35,cash,color,0,((s==0)*0.75)+((s==1)*1000)+((s==2)*100)))
  win_value=str(((s==0)*((1-num)+1))+((s==1)*num)+((s==2)*num*100))
  lost_value=str(-(s==0)*(1-num))+("-1"*(s!=0))
  txt("GAINS: x "+win_value,210,120,color[0],color[1],1)
  txt("PERTE: x "+lost_value,210,137,color[0],color[1],1)
  bet=eval(menu_nums(["Pari: "," $"],60,cash,color,0,cash[0]))
  win=False
  if s==0:win=num>random()
  elif s==1:win=0==randint(0,num)
  elif s==2:win=0==uniform(0,num)
  if win:
    bet*=eval(win_value)
    txt("WIN "+str(bet)+" $",50,128,color[0],green)
  else:
    bet*=eval(lost_value)
    txt("LOST "+str(bet)+" $",50,128,color[0],red)
  draw_c(cash[0]+bet,color)
  sleep(1)
  cash[0]+=bet
  cash[2]+=1
  cash[4]+=1
  while not keydown(4):pass
  game(s,cash,color)

def draw_c(cash,color):
  txt(str(round(cash,2))+" $",260,10,color[0],color[1],1)

def menu_nums(m,y,cash,color,min=0,max=100000):
  run=True
  while run:
    num=""
    fill_rect(0,y,320,19,color[1])
    txt(m[0]+num+m[1],40,y,color[0],color[1])
    while not kd(4):
      for i in keyNums:
        if_menu(cash,color)
        if kd(i):
          num+=str([0,1,2,3,4,5,6,7,8,9,"."][keyNums.index(i)])
          txt(m[0]+num+m[1],40,y,color[0],color[1])
      if min<float(num)<=max:run=False
  return num
  
def if_menu(cash,color):
  if kd(KEY_HOME):gambling(cash,color)

def kd(k):
  if keydown(k):
    while keydown(k):pass
    return True
  return False

def draw_menu(txt,s,color,y):
  fill_rect(0,y-2,321,18,color[2])
  fill_rect(2,y,316,14,color[1])
  for i in range(len(txt)):draw_string(txt[i],i*65,y,(color[0] if i!=s else color[2]) if color[3]==1 else color[0],(color[1] if i!=s else color[2]) if color[3]==0 else color[1],1)

def menu(txt,txt1,cash,color,s=0,s1=0):
  draw_menu(txt,s,color,2)
  draw_menu(txt1[s],s1,color,19)
  wait()
  while not keydown(KEY_OK):
    if_menu(cash,color)
    for i in [1,2]:
      if keydown(i):
        s+=([-1,1][[1,2].index(i)])
        s%=len(txt)
        draw_menu(txt,s,color,2)
        draw_menu(txt1[s],s1,color,19)
    for i in [0,3]:
      if keydown(i):
        s1+=([-1,1][[0,3].index(i)])
        s1%=len(txt1[s])
        draw_menu(txt1[s],s1,color,19)
    sleep(0.11)
  return s,s1

def cash(s,cash,color):
  fill_rect(0,0,321,222,color[1])
  wait()
  if s==0:
    txt("€ASH: "+str(cash[0]),110,75,color[0],color[1])
    txt("MEILLEUR: 158",100,90,color[0],color[1],1)
    txt("SALAIRE: "+str(cash[1]),105,120,color[0],color[1])
    while not keydown(4):
      if kd(6):print(cash)
  elif s==1:
    txt("  Voulez vous placer votre argent\n pour augmenter vos revenus de "+str(cash[0]/100)+".",0,40,color[0],color[1],1)
    while not keydown(4):if_menu(cash,color)
    cash[2]+=round(cash[0])
    cash[0]=0
  elif s==2:
    txt("Quel est le montant de votre pret\n  (interet 10 %) ?",10,30,color[0],color[1],1)
    cash[3]+=eval(menu_nums(["Emprunt: "," $"],75,cash,color,500))
    cash[0]+=cash[3]
  elif s==3:
    if cash[0]>=cash[3]:
      txt("REMBOURSER "+str(round(cash[3]*1.1))+"$ ?\n\n\n Argent emprunte: "+str(cash[3])+"\n Echeance du remboursement dans "+str(25-cash[4])+" parties.",100,40,color[0],color[1],1)
      while not keydown(4):
        if_menu(cash,color)
      cash[0]-=round(cash[3]*1.1)
      fill_rect(0,0,322,222,color[1])
      txt("REMBOURSE !\n\n\n Merci pour votr fidelite !",130,75,color[0],color[1],1)
      sleep(3)
    else:txt("  Vous ne pouvez pas rembourser votre\n pret.",0,25,color[0],color[1],1)
  gambling(cash,color)
  
def settings(s,cash,color):
  if s==0:
    themes=[["white","black","gray",0],[(150,150,150),"white",(0,0,180),1],["white",(175,175,175),(197,52,49),1],["black","white","orange",1],["white",'gray',(123,162,205),0]]
    color=themes[menu(["THEMES"],[["SOMBRE","€LAIR","OMEGA","NUMWORKS","UPSILON"]],cash,color)[1]]
  elif s==1:color[3]=(0==menu(["MODE DE SELE€TION"],[["TEXTE","FOND €ARA€TERE"]],cash,color)[1])
  gambling(cash,color)

function=[game,cash,settings]

def gambling(cash,color):
  fill_rect(0,0,321,222,color[1])
  txt("GAMBLING",120,60,"pink",color[1])
  txt("                     - by Armand Jamet\n\n CASH: "+str(cash[0])+" "*10+"PARTIES JOUEES: "+str(cash[2])+"\n REVENUS: "+str(cash[1])+" "*8+"PRET/E$HEAN$E: "+str(cash[2]),30,80,color[0],color[1],1)
  if cash[2]%10==0:
    txt("Un mois est passé !\n  Vous percevez vos revenus de "+str(cash[1])+"€ !",120,75,color[0],color[1],1)
    cash[0]+=cash[1]
  s,s1=menu(["GAMES","€ASH","SETTINGS"],[["RANDOM()","RANDINT()","UNIFORM()"],["€APITAL","BANK","PRET","REMBOURSEMENT"],["THEMES","MODE SELE$TION"]],cash,color)
  function[s](s1,cash,color)
          
gambling([158,50,1,0,1],["white","black","gray",0])

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.