Пример #1
0
def start_game():
    start_button.config(state=DISABLED)  # no accidental presses while play
    game = Gamelogic(34, 34)
    game.add_rand()
    graphic = Graphic(34, 34, game, root)
    graphic.init_graphic(320, 20)
    while True:
        graphic.root.after(50)
        graphic.game.update_field()
        graphic.game.found_piece()
        graphic.update_graphic()
        score_label.config(text="Score: " + str(graphic.game.score))
        score_label.place(x=20, y=460)
        graphic.root.update_idletasks()
        graphic.root.update()
        if graphic.game.is_lost() is True:
            break
    graphic.root.after(500, graphic.end())
    start_button.config(state="normal")
    if graphic.game.score > int(highscore):
        highscore_label.config(text="Highscore: " + str(graphic.game.score))
        highscore_label.place(x=20, y=500)
        with open("highscore.txt", "w") as f:
            f.write(str(graphic.game.score))
            f.close()
Пример #2
0
    def thuatToan_3(self):
        #Tao ma tran rong
        map = Map()
        #Lay cac gia tri input tu file input.txt
        print("Nhap file input:\n(input1_1.txt, input1_2.txt, input1_3.txt)")
        string = input("Ten file: ")
        A = Input(string, map)
        print(A)
        #Tao ma tran va canvas theo input
        g = Graphic(map.ngang, map.doc)
        #To mau cac da giac
        for i in range(map.ngang):
            for j in range(map.doc):
                if A[i][j] == 1:
                    g.Rectangle(i, j, "lightpink")
        listDaGiac = map.getDaGiac()
        for i in range(0, len(listDaGiac), 2):
            g.Rectangle(listDaGiac[i], listDaGiac[i + 1], "lightcoral")

        ids(A, map.xStart, map.yStart, map.xEnd, map.yEnd)
        print(A)

        g.Pack()
        g.Display()
        return 1
Пример #3
0
    def muc_3(self):
        #Tao ma tran rong
        map = Map()
        #Lay cac gia tri input tu file input.txt
        print("Nhap file input:\n(input1_1.txt, input1_2.txt, input1_3.txt)")
        string = input("Ten file: ")
        A = Input(string, map)
        #Tao ma tran va canvas theo input
        g = Graphic(map.ngang, map.doc)
        #To mau cac da giac
        for i in range(map.ngang):
            for j in range(map.doc):
                if A[i][j] == 1:
                    g.Rectangle(i, j, "lightpink")
        listDaGiac = map.getDaGiac()
        for i in range(0, len(listDaGiac), 2):
            g.Rectangle(listDaGiac[i], listDaGiac[i + 1], "lightcoral")
        chiPhi = xuatDuongDi(A, map)
        print("Chi phi: ", chiPhi)
        #Gia tri to mau: Start, end: 3      Diem don: 4     Duong di: 2     Rong: 0     Tuong: 1
        A[map.xStart][map.yStart] = 3
        A[map.xEnd][map.yEnd] = 3
        g.Rectangle(map.xStart, map.yStart, "lightskyblue")
        g.Rectangle(map.xEnd, map.yEnd, "lightskyblue")
        for i in map.danhSachDon:
            x, y = i
            A[x][y] = 4
            g.Rectangle(x, y, "lightgreen")
        g.Pack()
        for i in range(map.ngang):
            for j in range(map.doc):
                if A[i][j] == 2:
                    wait = 1
                    while wait:
                        g.Rectangle(i, j, "lightsteelblue")
                        g.windown.update_idletasks()
                        g.windown.update()
                        time.sleep(0.1)
                        g.Pack()
                        wait = 0

        g.Pack()
        g.Display()
        return 1
Пример #4
0
    def muc_1(self):
        #Tao ma tran rong
        map = Map()
        #Lay cac gia tri input tu file input.txt
        print("Nhap file input:\n(input1_1.txt, input1_2.txt, input1_3.txt)")
        string = input("Ten file: ")
        A = Input(string, map)
        #Tao ma tran va canvas theo input
        g = Graphic(map.ngang, map.doc)
        #To mau cac da giac
        for i in range(map.ngang):
            for j in range(map.doc):
                if A[i][j] == 1:
                    g.Rectangle(i, j, "lightpink")
        listDaGiac = map.getDaGiac()
        for i in range(0, len(listDaGiac), 2):
            g.Rectangle(listDaGiac[i], listDaGiac[i + 1], "lightcoral")

        #chay bang BFS
        bfs = BFSItem(A, (map.xStart, map.yStart), (map.xEnd, map.yEnd))
        path = bfs.BFS()
        print("Chi phi: ", len(path) - 1, "\n")

        g.Rectangle(map.xStart, map.yStart, "lightskyblue")
        g.Rectangle(map.xEnd, map.yEnd, "lightskyblue")
        g.Pack()
        for j in range(1, len(path) - 1):
            r = path[j][0]
            c = path[j][1]
            wait = 1
            while wait:
                g.Rectangle(r, c, "lightsteelblue")
                g.windown.update_idletasks()
                g.windown.update()
                time.sleep(0.1)
                g.Pack()
                wait = 0

        g.Pack()
        g.Display()
        return 1  #Gia tri de chay tiep
Пример #5
0
    def thuatToan_1(self):
        #Tao ma tran rong
        map = Map()
        #Lay cac gia tri input tu file input.txt
        print("Nhap file input:\n(input1_1.txt, input1_2.txt, input1_3.txt)")
        string = input("Ten file: ")
        A = Input(string, map)
        #Tao ma tran va canvas theo input
        g = Graphic(map.ngang, map.doc)
        #To mau cac da giac
        for i in range(map.ngang):
            for j in range(map.doc):
                if A[i][j] == 1:
                    g.Rectangle(i, j, "lightpink")
        listDaGiac = map.getDaGiac()
        for i in range(0, len(listDaGiac), 2):
            g.Rectangle(listDaGiac[i], listDaGiac[i + 1], "lightcoral")
        paths = astar(A, (map.xStart, map.yStart), (map.xEnd, map.yEnd))
        paths.reverse()
        print("Chi phi: ", len(paths))
        del paths[len(paths) - 1]
        g.Rectangle(map.xStart, map.yStart, "lightskyblue")
        g.Rectangle(map.xEnd, map.yEnd, "lightskyblue")
        g.Pack()

        for i in paths:
            y, x = i
            wait = 1
            while wait:
                g.Rectangle(y, x, "lightsteelblue")
                g.windown.update_idletasks()
                g.windown.update()
                time.sleep(0.1)
                g.Pack()
                wait = 0

        g.Pack()
        return 1
Пример #6
0
"""
Copyright 2020 Patrick Müller
Tetris
"""
# check tkinter for design and to do the menu and pause option
# sometimes placed tetriminos disappeared
from Gamelogic import *
from Graphic import *
from time import time

state = 0
previous_state = 0
game = GameLogic()
g = Graphic(game, state)

while g.state != -1:
    while g.state == 0:
        # start menu
        previous_state = 0
        g.state = 1

    if g.state == 1 and previous_state == 0:
        g.init_canvas()
        g.update_canvas()
        g.next_tetrimino()
        g.init_score()
        g.root.bind("<Up>", g.event_handler)
        g.root.bind("x", g.event_handler)
        g.root.bind("<Right>", g.event_handler)
        g.root.bind("<Left>", g.event_handler)
        g.root.bind("<Down>", g.event_handler)
Пример #7
0
    for i in range(8):
        nx = x + dx[i]
        ny = y + dy[i]
        if (nx >= 0  and ny >= 0 and nx < n and ny < m):
            if (d[nx][ny] == -1 and map[nx][ny] != 1):
                heappush(pq,(l[nx][ny],i))

    while (len(pq) > 0):
        (p,t) = heappop(pq)
        kx = x + dx[t]
        ky = y + dy[t]
        dfs(kx, ky, d, count + 1)
        if (foundPath): return
        step +=1
        stack.append((x,y,step))

dfs(seekerRowPos,seekerColPos,d,0)

for i in range (len(stack)):
    print(stack[i])

graphic = Graphic.Graphic(map, seekerRowPos, seekerColPos, hiderList, stack)
# point = graphic.heuristic()
# for i in range(15):
#     print(point[i])
graphic.run()
#graphic.observed()
#graphic.printBoard()
#graphic.printChecked()
Пример #8
0
def main():
    graphic = Graphic.Graphic()
Пример #9
0
from Graphic import *

app = Graphic()
app.run()