Esempio n. 1
0
def main():
    gui = False
    if len(sys.argv) > 1:
        if str(sys.argv[1]) == 'cli':
            gui = False
    if(gui):
        myboard = Board(8)
        comp = BotRandom(myboard, 'b')
        print(myboard.outputFEN())
        win = GraphWin('Chess', WIDTH, HEIGHT)
        while not win.isClosed():
            drawBoard(myboard, win)
            if myboard.gamestate != 0:
                print("Checkmate!")
                drawCheckmate(myboard, win)
            if myboard.active == 'w':
                getNextMove(myboard, win)
            else:
                comp.getNextMove()
            # print(myboard.allLegalMoves(True))
            win.update()
            time.sleep(.1)
        win.close()
    else:
        boardSize = 8
        if len(sys.argv) > 2:
            boardSize = int(sys.argv[2])
        myboard = Board(boardSize)
        comp = BotHeuristic(myboard, 'b')
        print(myboard.outputFEN())
        while myboard.gamestate == 0:
            print(myboard.asciiBoard())
            if myboard.active == 'w':
                cliNextMove(myboard)
            else:
                comp.getNextMove()
        print(myboard.asciiBoard())
        if myboard.gamestate == 1:
            print("Game Over! Black Wins!")
        if myboard.gamestate == 2:
            print("Game Over! White Wins!")
        if myboard.gamestate == 3:
            print("Game Over! Draw!")
x, y = pyautogui.position()  # получаем в x, y координаты мыши
r, g, b = pyautogui.pixel(x, y)  # получаем в r, g, b цвет

ColorDot = Circle(Point(100, 100), 25)  # создаем точку, отображающую цвет
ColorDot.setFill(color_rgb(r, g, b))  # устанавливает ей заливку из ранее полученных цветов
ColorDot.draw(win)  # рисуем на форме win

RGBtext = Entry(Point(win.getWidth() / 2, 25), 10)  # создаем RGB вывод
RGBtext.draw(win)  # рисуем на форме win

RGBstring = Entry(Point(win.getWidth() / 2, 45), 10)  # создаем вывод цвета в web стиле
RGBstring.draw(win)  # рисуем на форме win

Coordstring = Entry(Point(win.getWidth() / 2, 185), 10)  # создаем отображение координат
Coordstring.draw(win)  # рисуем на форме win

while True:  # цикл перереисовки формы
    time.sleep(0.1)  # задержка в 0.1 с, чтобы питон не сходил с ума

    x, y = pyautogui.position()  # получаем в x, y координаты мыши
    r, g, b = pyautogui.pixel(x, y)  # получаем в r, g, b цвет
    ColorDot.setFill(color_rgb(r, g, b))  # Обновляем цвет
    RGBtext.setText(pyautogui.pixel(x, y))  # Обновляем RGB
    RGBstring.setText(color_rgb(r, g, b))  # Обновляем web цвет
    Coordstring.setText('{} x {}'.format(x, y))  # Обновляем координаты

    if win.isClosed():
        break

    win.flush()  # Даем команду на перерисовку формы
Esempio n. 3
0
class Application:
    def __init__(self,
                 title="",
                 sWidth=1280,
                 sHeight=720,
                 bgC=color_rgb(25, 25, 25)):
        self.window = GraphWin(title, sWidth, sHeight)
        self.window.setBackground(bgC)

        self.gameState = GameState.MENU

        self.menu = MainMenu(self.window)
        self.game = Game(self.window, False)

        self.dt = 0.0  #DeltaTime
        self.lastFrameTime = 0.0

        self.setState(self.gameState)

    def quit(self):
        self.window.flush()
        self.window.close()

    def undraw(self):
        if self.gameState == GameState.MENU:
            self.menu.undraw()
        elif self.gameState == GameState.GAME:
            self.game.undraw()
        else:
            self.menu.undraw()
            self.game.undraw()

    def run(self):
        while not self.window.isClosed():
            #Calculate deltatime
            currentTime = time.time()
            self.dt = currentTime - self.lastFrameTime
            self.lastFrameTime = currentTime

            self.update(self.dt)

            if not self.window.isClosed():
                self.window.flush()

            #If the close key is pressed, close window, for debugging
            if input.kClose():
                quit()

    def update(self, dt):
        state = GameState.NONE
        if self.gameState == GameState.MENU:
            state = self.menu.update(self.window)
        elif self.gameState == GameState.GAME:
            state = self.game.update(dt, self.window)

        if not state == GameState.NONE:
            if state == GameState.QUIT:
                quit()
            else:
                self.setState(state)

    def setState(self, state=GameState.NONE):
        if state == GameState.NONE:
            self.setState(GameState.MENU)
        else:
            if state == GameState.GAMEONLINE:  #Failsafe since its not yet implemented
                print("Game Online Unavailable")
                print("Reverting to GameState.GAME")
                self.setState(GameState.GAME)
            else:
                self.undraw()
                if state == GameState.GAME:
                    self.game.draw(self.window)
                elif state == GameState.MENU:
                    self.menu.draw(self.window)
                self.gameState = state