lunes, 12 de noviembre de 2018

Juego de alex



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from Tkinter import *
from random import *
import random
import tkMessageBox

intentos =0
aux=0

def inicio_jugar():

    arr = [1, 2, 3, 4, 5]
    global intentos
    intentos = random.choice(arr)
    global num
    num = randint(1, 5)
    nom=entrada1.get()

    et1=Label(contenedor,text="Hola "+nom+" estoy pensando en un numero entre 1 y 5, crees poder adivinarlo?",font=("Times New Roman",15)).place(x=0,y=147)
    et2=Label(contenedor,text="La suerte va a decir el numero de intentos que tienes",font=("Times New Roman",15)).place(x=0,y=207)

    et3=Label(contenedor,text="Tienes "+str(intentos)+" intentos",font=("Times New Roman",15)).place(x=90,y=267)
    parte_2()

def parte_2():
    et4 = Label(contenedor, text="Intenta adivinar: ", font=("Times New Roman", 15)).place(x=90, y=337)
    global entrada2
    entrada2= StringVar()
    objentrada2 = Entry(contenedor, textvariable=entrada2).place(x=242, y=342)

    b2 = StringVar()
    b2.set("Verificar respuesta")
    bgame2 = Button(contenedor, textvariable=b2, command=verificar).place(x=380, y=340)

def verificar():
    global aux
    while aux<intentos:
        est = int(entrada2.get())

        if est<num:
            tkMessageBox.showinfo("Alerta","Tu estimacion es muy baja")
            aux+=1
            break

        elif est>num:
            tkMessageBox.showinfo("Alerta", "Tu estimacion es muy alta")
            aux+=1
            break

        if num==est:
            accion = tkMessageBox.askyesno("Atencion","Haz ganado el juego\n Quieres volver a jugar?")
            imagen3 = PhotoImage(file='ganaste.gif')
            lblusuario = Label(ventana, image=imagen3).place(x=500, y=500)
            if accion == False:
                ventana.destroy()
                break
            else:
                aux = 0
                inicio_jugar()
                break

    if intentos==aux:
        accion = tkMessageBox.askyesno("Atencion","Haz perdido el juego\n Quieres volver a jugar?")
        imagen4 = PhotoImage(file='perdiste.gif')
        lblusuario = Label(ventana, image=imagen4).place(x=500, y=500)
        if accion == False:
            ventana.destroy()
        else:
            aux = 0
            inicio_jugar()

ventana=Tk()
ventana.config(bg="gray")
contenedor=Frame(ventana,width=650,height=650)
contenedor.pack()
t1=Label(contenedor,text="Bienvenido al juego adivina el numero",font=("Times New Roman",15)).place(x=90,y=25)
t2=Label(contenedor,text="Ingresa tu nombre: ",font=("Times New Roman",15)).place(x=90,y=87)


b1=StringVar()
b1.set("Iniciar juego")
bgame=Button(contenedor,textvariable=b1,command=inicio_jugar).place(x=407,y=87)
entrada1=StringVar()
objentrada=Entry(contenedor,textvariable=entrada1).place(x=240,y=90)


ventana.mainloop()

No hay comentarios.:

Publicar un comentario