편집 기록

편집 기록
  • 프로필 ᅟᅟᅟᅟ님의 편집
    날짜2021.06.17

    틱택토 터틀 함수 같은 지역에 안들어가게 하는법


    from turtle import * 로 실행하고 9개 지역에서 x 랑 o 까지 넣는 것은 됐습니다. 근데 3줄 맞추고 게임을 끝내는 것하고 이미 문자가 입력된 곳에 중복으로 들어가는 오류가 발생합니다 어떻게 해결하면 좋을까요?

    
    pieces = ["", "", "", "", "", "", "", "", ""]
    nextTurn = "X"
    
    
    def drawPieces(pieces):
        x = -300
        y = 300
    
        for piece in pieces:
            if piece == "X":
                cross(x, y)
            elif piece == "O":
                nought(x, y)
    
            x = x +200
            if x > 100:
                x = -300
                y = y - 200
    
    def clicked(x, y):
        global nextTurn, pieces
        column = (x+300)//200
        row = -(y-300)//200
        square = column + row*3
        square = int(square)
        print("You clicked ",x,",",y," square", square)
        pieces[square] = nextTurn
        if nextTurn == "X":
            nextTurn = "O"
        else:
            nextTurn = "X"
    
        drawPieces(pieces)
    
    onscreenclick(clicked)
    mainloop()
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2021.06.17

    틱택토 터틀 함수 같은 지역에 안들어가게 하는법


    from turtle import * 로 실행하고 9개 지역에서 x 랑 o 까지 넣는 것은 됐습니다. 근데 3줄 맞추고 게임을 끝내는 것하고 이미 문자가 입력된 곳에 중복으로 들어가는 오류가 발생합니다 어떻게 해결하면 좋을까요?

    pieces = ["", "", "", "", "", "", "", "", ""] nextTurn = "X"

    def drawPieces(pieces): x = -300 y = 300

    for piece in pieces:
        if piece == "X":
            cross(x, y)
        elif piece == "O":
            nought(x, y)
    
        x = x +200
        if x > 100:
            x = -300
            y = y - 200
    

    def clicked(x, y): global nextTurn, pieces column = (x+300)//200 row = -(y-300)//200 square = column + row*3 square = int(square) print("You clicked ",x,",",y," square", square) pieces[square] = nextTurn if nextTurn == "X": nextTurn = "O" else: nextTurn = "X"

    drawPieces(pieces)
    

    onscreenclick(clicked) mainloop()