jueves, 29 de octubre de 2020

JUEGO GATO.PY

 # -*- coding: utf-8 -*-

from  tkinter import*

from tkinter import messagebox  # para las cajas de mensajes

from tkinter import  simpledialog  # para pedir nombre de jugadores


def bloquear():

    for i in range(0,9):

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


def iniciarJ():

    for i in range(0,9):

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

        listaBotones[i].config(bg="#E6E6E6")

        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")

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

        t[num]="X"

        turno=1

        turnoJugador.set("Turno:"+ nombreJugador2)

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

        listaBotones[num].config(text="O")

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

        t[num] = "O"

        turno = 0

        turnoJugador.set("Turno:" + nombreJugador1)

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

    verificar()


def verificar():

        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()

            messagebox.showinfo("Ganador", "Gaste Jugador:" + nombreJugador1)


        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()

            messagebox.showinfo("Ganador", "Gaste Jugador:" + nombreJugador1)


        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()

            messagebox.showinfo("Ganador", "Gaste Jugador:" + nombreJugador1)


        if (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()

            messagebox.showinfo("Ganador", "Gaste Jugador:" + nombreJugador2)


        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()

            messagebox.showinfo("Ganador", "Gaste Jugador:" + nombreJugador2)


        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()

            messagebox.showinfo("Ganador", "Gaste Jugador:" + nombreJugador2)

        




def Salir(): #función salir

    exit()


ventana= Tk()

ventana.title("                                     JUEGO DEL GATO  ")

ventana.geometry("461x800")

imagen=PhotoImage(file="C:\PyCharm 2020.2.1\GATO1.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")



turno= 0

nombreJugador1=""

nombreJugador2=""

listaBotones=[] # lista para los objetos de 9 botones

t=[]  # lista para escojer x o 0

turnoJugador= StringVar()

#turno entre jugador y otro y lo vaya mostrando

# llenar tableros de vacios con la letra n

for i in range(0,9):

    t.append("N")


# hacer nuestro  nueve botones

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

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

listaBotones.append(boton0)


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

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

listaBotones.append(boton1)


boton2=Button(ventana,width=9, heig=3,bg="#F5DA81",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="#F5DA81",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="#F5DA81",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="#F5DA81",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="#F5DA81",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="#F5DA81",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="#F5DA81",activebackground="#E6E6E6",cursor="hand1",command=lambda:cambiar(8))

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

listaBotones.append(boton8)


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


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

               cursor="hand1",command=iniciarJ).place(x=180,y=510)

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=180,y=590)


bloquear()


#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')


ventana.mainloop()

PANTALLA DE SALIDA 





No hay comentarios:

Publicar un comentario