jueves, 29 de octubre de 2020

PROGRAMA GATO

 from tkinter import *

from tkinter import messagebox

from tkinter import simpledialog #pedir informacion

from pymongo import MongoClient

import time

global nombreJugador1,nombreJugador2,fecha,hora,ganador

hora= time.strftime("%H:%M:%S")

fecha= time.strftime("%d-%m-%Y")




def bloquear():

    for i in range(0,9):

        listaBotones[i].config(state="disable")


def iniciar():

    for i in range(0,9):

        listaBotones[i].config(state="normal")

        listaBotones[i].config(bg="Lightgray")

        listaBotones[i].config(text="")

        t[i]="N"

    global nombreJugador1,nombreJugador2

    nombreJugador1= simpledialog.askstring("Jugador","Escribe el nombre del jugador 1:")

    nombreJugador2 = simpledialog.askstring("Jugador", "Escribe el nombre del jugador 2:")

    turnoJugador.set("Turno: "+ nombreJugador1)



def cambiar(num):

    global turno,nombreJugador1,nombreJugador2

    if t[num]=="N" and turno==0:

        listaBotones[num].config(text="X",fg="white",font=("Arial Black" , 8))

        listaBotones[num].config(bg="#F781D8")

        t[num] = "X"

        turno = 1

        turnoJugador.set("Turno: "+ nombreJugador2)

    elif t[num]=="N" and turno==1:

        listaBotones[num].config(text="O",fg="white",font=("Arial Black" , 8))

        listaBotones[num].config(bg="#A9F5D0")

        t[num] = "O"

        turno = 0

        turnoJugador.set("Turno: " + nombreJugador1)

    verificar()



def info(ganador):

    list = Listbox(ventana, width=50)


    list.insert(1, "  primera ronda")

    list.insert(2, "  Nombre Jugador 1", nombreJugador1)

    list.insert(4, "  Nombre Jugador 2", nombreJugador2)

    list.insert(6, "  Ganador  de la partida", ganador)

    list.place(x=160, y=370)


def Salir():

    exit()



def verificar ():

    hora = time.strftime("%H:%M:%S")

    fecha = time.strftime("%d-%m-%Y")

    ganador=""

    if (t[0]=="X" and t[1]=="X" and t[2]=="X") or (t[3]=="X" and t[4]=="X" and t[5]=="X") or (t[6]=="X" and t[7]=="X" and t[8]=="X"):

        bloquear()

        ganador = nombreJugador1

        messagebox.showinfo("Ganador", "Ganaste  " + nombreJugador1)

        conexion(hora, fecha, nombreJugador1, nombreJugador2, ganador)

        messagebox.showinfo("guardadar ", "Otra partida??PLAY")

        info(ganador)

    elif (t[0]=="X" and t[3]=="X" and t[6]=="X") or (t[1]=="X" and t[4]=="X" and t[7]=="X") or (t[2]=="X" and t[5]=="X" and t[8]=="X"):

        bloquear()

        ganador = nombreJugador1

        messagebox.showinfo("Ganador", "Ganaste  " + nombreJugador1)

        conexion(hora, fecha, nombreJugador1, nombreJugador2, ganador)

        messagebox.showinfo("guardadar ", "Otra partida??PLAY")

        info(ganador)

    elif (t[0]=="X" and t[4]=="X" and t[8]=="X") or (t[2]=="X" and t[4]=="X" and t[6]=="X"):

        bloquear()

        ganador = nombreJugador1

        messagebox.showinfo("Ganador", "Ganaste  " + nombreJugador1)

        conexion(hora, fecha, nombreJugador1, nombreJugador2, ganador)

        messagebox.showinfo("guardadar ", "Otra partida??PLAY")

        info(ganador)

    elif (t[0]=="O" and t[1]=="O" and t[2]=="O") or (t[3]=="O" and t[4]=="O" and t[5]=="O") or (t[6]=="O" and t[7]=="O" and t[8]=="O"):

        bloquear()

        ganador = nombreJugador2

        messagebox.showinfo("Ganador", "Ganaste  " + nombreJugador2)

        conexion(hora, fecha, nombreJugador1, nombreJugador2, ganador)

        messagebox.showinfo("guardadar ", "Otra partida??PLAY")

    elif (t[0]=="O" and t[3]=="O" and t[6]=="O") or (t[1]=="O" and t[4]=="O" and t[7]=="O") or (t[2]=="O" and t[5]=="O" and t[8]=="O"):

        bloquear()

        ganador = nombreJugador2

        messagebox.showinfo("Ganador", "Ganaste  " + nombreJugador2)

        conexion(hora, fecha, nombreJugador1, nombreJugador2, ganador)

        messagebox.showinfo(" guardadar ", "Otra partida??PLAY")

        info(ganador)

    elif (t[0]=="O" and t[4]=="O" and t[8]=="O") or (t[2]=="O" and t[4]=="O" and t[6]=="O"):

        bloquear()

        ganador = nombreJugador2

        messagebox.showinfo("Ganador", "Ganaste Jugador " + nombreJugador2)

        conexion(hora, fecha, nombreJugador1, nombreJugador2, ganador)

        messagebox.showinfo("guardadar", "Otra partida??PLAY")

        info(ganador)


    return ganador


def conexion(hora,fecha,nombreJugador1,nombreJugador2,ganador ):

    client = MongoClient('localhost', 27017)

    db = client['TABLA_GATO']  # me conecto con la bd store



    document = {"Fecha: ":fecha,"Hora:": hora,"Nombre Jugador1:":nombreJugador1 , "Nombre Jugador 2:": nombreJugador2,"Ganador:":ganador}

    _id = db['Juego'].insert(document)


ventana = Tk()

ventana.title("JUEGO DEL GATO")

ventana.geometry("512x512")

imagen = PhotoImage(file="C:\PyCharm 2020.2.1\CAT.png")  # llamamos a la imagen

fondo = Label(ventana, image=imagen).place(x=0, y=0)  # visualizamos la imagen como fondo

ventana.iconbitmap("C:\PyCharm 2020.2.1\cat_6_icon-icons.com_53579.ico")  # agregue icono

vp = Frame(ventana)

ventana.config(background="white")

list= Listbox(vp, width=10,borderwidth=2,selectborderwidth=1)



c = Listbox(ventana, width=30).place(x=160,y=370)#listbox


turno = 0;

nombreJugador1 = ""

nombreJugador2 = ""

listaBotones = []

t = [] # X O N

turnoJugador = StringVar()

ganador = StringVar()

for i in range(0,9):

    t.append("N")

# hacer nuestro  nueve botones

boton0 = Button(ventana, width=9, heig=3, bg="#BDBDBD", cursor="hand1",command=lambda: cambiar(0))

boton0.place(x=55, y=55)

listaBotones.append(boton0)


boton1 = Button(ventana, width=9, heig=3, bg="#A9A9F5", cursor="hand1",command=lambda: cambiar(1))

boton1.place(x=155, y=55)

listaBotones.append(boton1)


boton2 = Button(ventana, width=9, heig=3, bg="#BDBDBD", activebackground="#E6E6E6",cursor="hand1",command=lambda: cambiar(2))

boton2.place(x=255, y=55)

listaBotones.append(boton2)


boton3 = Button(ventana, width=9, heig=3, bg="#A9A9F5", activebackground="#E6E6E6", cursor="hand1",command=lambda: cambiar(3))

boton3.place(x=55, y=155)

listaBotones.append(boton3)


boton4 = Button(ventana, width=9, heig=3, bg="#BDBDBD", activebackground="#E6E6E6", cursor="hand1",command=lambda: cambiar(4))

boton4.place(x=155, y=155)

listaBotones.append(boton4)


boton5 = Button(ventana, width=9, heig=3, bg="#A9A9F5", activebackground="#E6E6E6", cursor="hand1",command=lambda: cambiar(5))

boton5.place(x=255, y=155)

listaBotones.append(boton5)


boton6 = Button(ventana, width=9, heig=3, bg="#BDBDBD", activebackground="#E6E6E6", cursor="hand1",command=lambda: cambiar(6))

boton6.place(x=55, y=255)

listaBotones.append(boton6)


boton7 = Button(ventana, width=9, heig=3, bg="#A9A9F5", activebackground="#E6E6E6", cursor="hand1",command=lambda: cambiar(7))

boton7.place(x=155, y=255)

listaBotones.append(boton7)


boton8 = Button(ventana, width=9, heig=3, bg="#BDBDBD", activebackground="#E6E6E6", cursor="hand1",command=lambda: cambiar(8))

boton8.place(x=255, y=255)

listaBotones.append(boton8)

#etiquetas

turnoe = Label(ventana, textvariable=turnoJugador).place(x=140, y=10)

hora1=Label(ventana,text=hora, bg="#F5A9F2",font=("Helvetica", 12)).place(x=55,y=350)

txthora=Label(ventana,text="HORA:", bg="#F5A9F2",font=("Helvetica", 12)).place(x=0,y=350)

fecha1=Label(ventana,text=fecha, bg="#F5A9F2",font=("Helvetica" ,12)).place(x=55,y=370)

txtFecha=Label(ventana,text="FECHA:", bg="#F5A9F2",font=("Helvetica" ,12)).place(x=0,y=370)

#Botones

iniciar = Button(ventana, bg="#04B404", fg="white", text="play", width=4, height=2, font="Arial", borderwidth=9,activebackground="#E6E6E6",

                 cursor="hand1", command=iniciar).place(x=350, y=37)

Salir = Button(ventana, bg="#FF0000", fg="white", text="Salir", width=4, height=2, font="Arial", borderwidth=9,activebackground="#E6E6E6",

               cursor="hand1", command=Salir).place(x=350, y=155)



# Crea y posiciona las lineas con Canvas()

linea = Canvas(ventana, width=310, height=10)

linea.place(x=35, y=125)

linea.create_line(310, 0, 0, 0, width=20, fill='#80FF00')

l2 = Canvas(ventana, width=310, height=10)

l2.place(x=35, y=225)

l2.create_line(310, 0, 0, 0, width=20, fill='#80FF00')

l3 = Canvas(ventana, width=10, height=310)

l3.place(x=135, y=25)

l3.create_line(0, 310, 0, 0, width=20, fill='#80FF00')

l4 = Canvas(ventana, width=10, height=310)

l4.place(x=235, y=25)

l4.create_line(0, 310, 0, 0, width=20, fill='#80FF00')

bloquear()



ventana.mainloop()

-----------------------------------------------------------------------------------------------------------------------------
PANTALLA DE EJECUCION




No hay comentarios:

Publicar un comentario