Beispiel #1
0
    def __create_window(self):
        for row in range(self.__dimension[1]):
            for coll in range(self.__dimension[0]):
                cell_position = (OFFSET + CELL_DIMENSION[0] * coll,
                                 OFFSET + CELL_DIMENSION[1] * row)

                if row == 0 or row == self.__dimension[1] - 1 or coll == 0 or coll == self.__dimension[0] - 1 or\
                        (coll == 15 and row < 18) or (coll == 32 and row > 13):
                    cell_type = WALL
                    cell = Cell(pos=cell_position,
                                cell_type=cell_type,
                                win=self.__win,
                                cell_pos=(coll, row),
                                color=BLOCK_COLOR)
                else:
                    cell_type = EMPTY
                    cell = Cell(pos=cell_position,
                                cell_type=cell_type,
                                win=self.__win,
                                cell_pos=(coll, row))

                cell.draw()

                self.__cells.append(cell)

        self.__day_counter = Text(
            Point(150, OFFSET + CELL_DIMENSION[1] * (self.__dimension[1] + 2)),
            f"Day: {self.__day}")
        self.__day_counter.draw(self.__win)

        self.__generation_counter = Text(
            Point(OFFSET + CELL_DIMENSION[0] * self.__dimension[0] - 100,
                  OFFSET + CELL_DIMENSION[1] * (self.__dimension[1] + 2)),
            f"Generation: {self.__generation}")
        self.__generation_counter.draw(self.__win)

        self.__bot_counter = Text(
            Point(OFFSET + CELL_DIMENSION[0] * self.__dimension[0] - 375,
                  OFFSET + CELL_DIMENSION[1] * (self.__dimension[1] + 2)),
            f"Bots count: {len(self.__bots)}")
        self.__bot_counter.draw(self.__win)

        text = Text(
            Point(
                OFFSET + self.__dimension[0] * CELL_DIMENSION[0] + 2 * OFFSET,
                OFFSET), "Last generation duration:").draw(self.__win)
        text.setSize(18)

        for i in range(10):
            text = Text(
                Point(
                    OFFSET + self.__dimension[0] * CELL_DIMENSION[0] +
                    2 * OFFSET, OFFSET + 2 * CELL_DIMENSION[0] * (i + 1)), "")
            text.draw(self.__win)
            self.__try_texts.append(text)
Beispiel #2
0
def main():
    win = GraphWin("Window", 700, 700)
    
    #func = plane
    #func = circle(Point(350,350), 150)
    func = wigglyCircle(Point(350, 350), 150, 75)

    func = rotate(45, Point(350, 350), func)

    a = 50
    b = 650

    cell = Cell(Point(a,a), Point(b, a), Point(b,b), Point(a,b), EdgeStore(func))
    cell.splitForFunc(func, 0, 7, 1)
    cell.draw(win)

    win.getMouse()
Beispiel #3
0
    def __init__(self, sizeX, sizeY, canvas, tk, firstCell, lastCell):

        self.cellSize = self.screenWidth / sizeX
        self.sizeX = sizeX
        self.sizeY = sizeY
        self.allCells = [[Cell for i in range(sizeY)] for j in range(sizeX)]
        self.canvas = canvas
        self.noGUI = noGUI
        for x in range(sizeX):
            for y in range(sizeY):
                cell = Cell(x, y, self.cellSize, self, canvas)
                self.allCells[x][y] = cell
                cell.draw(canvas, tk)

        if noGUI == False:
            canvas.pack()

        self.tk = tk
        self.firstCell = firstCell
        self.lastCell = lastCell
        self.cellMax = sizeX * sizeY

        arg_1 = "%d" % sizeX
        arg_2 = "%d" % sizeY

        if noGUI == True and quiet == False:
            print "Generowanie labiryntu: 0000 / %04d" % self.cellMax

        process = subprocess.Popen(["bash", "generate_maze.sh", arg_1, arg_2],
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)

        while True:
            out = process.stdout.readline()
            if out == '' and process.poll() != None:
                break
            if out != '':
                self.interpretRecivedCellData(out[1:-2])

        if noGUI == True:
            print "Struktura labiryntu:"

            if printASCII == False:
                sys.stdout.write(self.getMazeReadableDataToString())
            else:
                self.printMazeInASCII()

        if fileSave == True:
            self.saveToFile('w', self.getMazeReadableDataToString())

        if findPath == -1 and noGUI == False:
            res = tkMessageBox.askyesno(
                "Generator labiryntu",
                "Czy chcesz aby zostala znaleziona najkrotsza sciezka w labiryncie?"
            )

            if res == True:
                res = tkMessageBox.askyesno(
                    "Generator labiryntu",
                    "Czy chcesz wybrac punkt startowy i koncowy sciezki?")

                if res == True:
                    tkMessageBox.showinfo(
                        "Generator labiryntu",
                        "Kliknij na komorke, ktora ma byc punktem startowym")

                    self.selectFirst = True
                else:
                    self.findShortestWay()
        elif findPath == 1 or (findPath == -1 and noGUI == True):
            self.findShortestWay()