Пример #1
0
def main():
    now = datetime.now()
    dt_string = now.strftime("--%d-%m-%Y--%H-%M-%S")  # --2009-12-31--23-59-59

    print('Enter LEVEL (1- 15)')
    level = input()

    level = int(level)
    
    

    print('Play in Console (Enter "1")')
    print('Play in Window  (Enter "2")')

    inputNum = input()
    inputNum = int(inputNum)

    if inputNum == 1:
        # cons Print (PicPuzzle printArr fixen)
        consPicPuzzle = PicPuzzle(level)
        consPicPuzzle.startConsole()

    elif inputNum == 2:
        winPicPuzzle = WindowPicPuzzle(level)
        winPicPuzzle.renameLogFile("Log-File" + dt_string + ".txt")
        winPicPuzzle.start()
Пример #2
0
    def __init__(self, LEVEL):

        WIDTH = 400
        HEIGHT = 400
        OFFSETR = 200
        OFFSETL = 200
        self.LEVEL = LEVEL
        self.p = PicPuzzle(self.LEVEL)
        self.LOGFILENAME = "log.txt"
        m_arr = self.p.getPuzzle()

        self.p.writeLogFile(self.LOGFILENAME, str(m_arr), "w")
        # self.p.startConsole()
        self.root = tk.Tk()
        self.root.title("Pic Puzzle")
        self.root.geometry("+{0}+{1}".format(OFFSETR, OFFSETL))

        canvas = tk.Canvas(self.root, width=WIDTH, height=HEIGHT)
        canvas.pack()

        frameBG = tk.Frame(self.root, bg='#1B2021')
        frameBG.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
        frameBtns = tk.Frame(frameBG, bg='#1B2021')
        frameBtns.place(relx=0.025, rely=0.025, relwidth=0.95, relheight=0.95)

        helv36 = tkinter.font.Font(
            family='Arial', size=int(100/self.LEVEL), weight='bold')

        print(m_arr)
        btns = [[None for _ in range(self.LEVEL)] for _ in range(self.LEVEL)]

        for i in range(self.LEVEL):
            for j in range(self.LEVEL):
                btns[i][j] = tk.Button(frameBtns, text=self.getNum(m_arr[j][i]), bg="#EEB868", fg="#1B2021",
                                    activebackground="#FFEED6", activeforeground="#11151C",
                                       font=helv36, command=lambda i=i, j=j: self.btn_clicked(btns, btns[i][j]))
                btns[i][j].place(relx=(i*1/self.LEVEL-0.05) + 0.05, rely=((j *
                                                                    1/self.LEVEL-0.05) + 0.05), relwidth=1/self.LEVEL, relheight=1/self.LEVEL)
Пример #3
0
from PicPuzzle import PicPuzzle
import tkinter as tk
import tkinter.font
from tkinter import messagebox

WIDTH = 400
HEIGHT = 400
OFFSETR = 200
OFFSETL = 200
LEVEL = 3
p = PicPuzzle(LEVEL)
m_arr = p.getPuzzle()


def main():

    p.log("log.txt", str(m_arr), "w")
    # p.startConsole()
    root = tk.Tk()
    root.title("Pic Puzzle")
    root.geometry("+{0}+{1}".format(OFFSETR, OFFSETL))

    canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT)
    canvas.pack()

    frameBG = tk.Frame(root, bg='#1B2021')
    frameBG.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
    frameBtns = tk.Frame(frameBG, bg='#1B2021')
    frameBtns.place(relx=0.025, rely=0.025, relwidth=0.95, relheight=0.95)

    helv36 = tkinter.font.Font(family='Arial',
Пример #4
0
class WindowPicPuzzle:

    def __init__(self, LEVEL):

        WIDTH = 400
        HEIGHT = 400
        OFFSETR = 200
        OFFSETL = 200
        self.LEVEL = LEVEL
        self.p = PicPuzzle(self.LEVEL)
        self.LOGFILENAME = "log.txt"
        m_arr = self.p.getPuzzle()

        self.p.writeLogFile(self.LOGFILENAME, str(m_arr), "w")
        # self.p.startConsole()
        self.root = tk.Tk()
        self.root.title("Pic Puzzle")
        self.root.geometry("+{0}+{1}".format(OFFSETR, OFFSETL))

        canvas = tk.Canvas(self.root, width=WIDTH, height=HEIGHT)
        canvas.pack()

        frameBG = tk.Frame(self.root, bg='#1B2021')
        frameBG.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
        frameBtns = tk.Frame(frameBG, bg='#1B2021')
        frameBtns.place(relx=0.025, rely=0.025, relwidth=0.95, relheight=0.95)

        helv36 = tkinter.font.Font(
            family='Arial', size=int(100/self.LEVEL), weight='bold')

        print(m_arr)
        btns = [[None for _ in range(self.LEVEL)] for _ in range(self.LEVEL)]

        for i in range(self.LEVEL):
            for j in range(self.LEVEL):
                btns[i][j] = tk.Button(frameBtns, text=self.getNum(m_arr[j][i]), bg="#EEB868", fg="#1B2021",
                                    activebackground="#FFEED6", activeforeground="#11151C",
                                       font=helv36, command=lambda i=i, j=j: self.btn_clicked(btns, btns[i][j]))
                btns[i][j].place(relx=(i*1/self.LEVEL-0.05) + 0.05, rely=((j *
                                                                    1/self.LEVEL-0.05) + 0.05), relwidth=1/self.LEVEL, relheight=1/self.LEVEL)

        

    def btn_clicked(self, btns, pressed_btn):

        for i in range(self.LEVEL*self.LEVEL):
            # check num of pressed button

            if pressed_btn.cget("text") == "{0}".format(i):
                print("Button {0} pressed".format(i))

                self.p.checkWindow(i)
                m_arr = self.p.getPuzzle()
                print(m_arr)
                self.p.writeLogFile(self.LOGFILENAME, str(m_arr), "a")

                # rename btn names to __m_arr names ^^
                self.renameBtns(btns, pressed_btn, m_arr)

                if self.p.game_end == True:
                    MsgBox = tk.messagebox.askquestion(
                        title='Game Finished', message='Restart Game With Yes, Exit with No', )
                    if MsgBox == 'yes':
                        self.p.restartGame()
                        m_arr = self.p.getPuzzle()
                        self.p.checkWindow(i)
                        print(m_arr)
                        self.p.writeLogFile(self.LOGFILENAME, str(m_arr), "w")

                        # rename btn names to __m_arr names ^^
                        self.renameBtns(btns, pressed_btn, m_arr)
                    else:
                        exit()

    def renameBtns(self, btns, pressed_btn, arr):
        for i in range(self.LEVEL):
            for j in range(self.LEVEL):
                btns[i][j].config(text=self.getNum(arr[j][i]))


    def getNum(self, x):
        if x == 0:
            return ""
        else:
            return str(x)

    def renameLogFile(self, strName):
        os.remove(self.LOGFILENAME)
        self.LOGFILENAME = strName
        

    def start(self):
        self.root.mainloop()