Jeu du 21.

Contenu du snippet

Le but du jeu est de se rapprocher le plus possible de 21 en lancant un dé,
vous vous arrêtez quand vous le voulez en cliquant sur "arrêter" et la vous passez
la main a la machine qui essayera de faire mieux. La partie se termine
quand vous ou l'ordianteur a atteint un total de 10 points, bonne chance ...

Bon je ne suis pas tres fort en interface graphique si vous avez des conseils je suis preneur :D .

Source / Exemple :


# -*- coding: cp1252 -*-
#---- Jeu de 21 by Bouceka ----

#---- Appel de module ----
from Tkinter import *
from random import randrange

#---- Variable utilisé ----
player,machine = 0,0
i,cumulm,cumulp = 0,0,0
scorem ,scorep = 0,0
deci = ''

#---- Fonctions ----

def Jeu():
    global cumulm ,cumulp
    player = randrange(1,7)
    machine = randrange(1,7)
    cumulp = cumulp + player
    cumulm = cumulm + machine

    tex2['text'] = "Nombre:",player
    tex3['text'] = "Player:",cumulp

    

def Arret():
    global cumulm,cumulp,scorem,scorep
    tex4['text'] = "Machine:",cumulm
    if(abs(21 - cumulm) < abs(21 - cumulp)):
         scorem = scorem + 1
         tex7['text'] = "Machine point:",scorem

    elif(abs(21 - cumulm) > abs(21 - cumulp)):
        scorep = scorep + 1
        tex6['text'] = "Player point:",scorep

    elif(abs(21 - cumulm) == abs(21 - cumulp)):
        scorep = scorep + 1
        scorem = scorem + 1
    
        tex6['text'] = "Player point:",scorep
        tex7['text'] = "Machine point:",scorem

    if(scorep == 10):
        tex5['text'] = "Tu as gagné !"

    elif(scorem == 10):
        tex5['text'] = "Tu as perdu..."

    cumulp,cumulm = 0 , 0  
  
def rejouer():
    global cumulm,cumulp,scorem,scorep
    cumulm,cumulp,scorem,scorep = 0,0,0,0

    tex2['text'] = "Nombre: 0"
    tex3['text'] = "Player: 0"
    tex4['text'] = "Machine: 0"
    tex5['text'] = ""
    tex6['text'] = "Player point: 0"
    tex7['text'] = "Machine point: 0"
    

#---- Interface Graphique ----

fen = Tk()
fen.title("Jeu de 21 by Bouceka")

Button(fen,text ="  Go ! ",command =Jeu).grid(row =1,column =1)

Button(fen,text ="Arrêter",command =Arret).grid(row =2,column =1)

Button(fen,text ="Rejouer",command =rejouer).grid(row = 3,column =1)

tex2 = Label(fen,text ="Nombre: 0")
tex2.grid(row =2,column =2,sticky =W)

Label(fen,text =" |->Lancé du dé<- |",fg ='blue').grid(row =1,column =2)

Label(fen,text="|->Evolution du joueur<-|",fg ='blue').grid(row =1,column =3,)

tex3 = Label(fen,text ="Player: 0")
tex3.grid(row =2,column =3,sticky =W)

tex4 = Label(fen,text ="Machine: 0")
tex4.grid(row =3,column =3,sticky = W) 

Label(fen,text="<->->->->->Score des joueurs<-<-<-<-<->",fg ='blue').grid(row =6,column =1,columnspan =3)

tex5 = Label(fen,text="")
tex5.grid(row = 7,column =3)

tex6 = Label(fen,text="Player point: 0")
tex6.grid(row =7,column=1,columnspan =2)

tex7 = Label(fen,text="Machine point: 0")
tex7.grid(row =8,column=1,columnspan =2)

fen.mainloop()

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.