Esempio n. 1
0
class GameManager:
    def __init__(self):
        self.ttt = TicTacToe()

    def play(self):
        print(self.ttt)

        while True:

            row = int(input("row : "))
            col = int(input("col : "))
            self.ttt.set(row, col)
            print(self.ttt)

            if self.ttt.check_winner() == "0":
                print(" O win!!!")
                break

            elif self.ttt.chenck_winner() == "X":
                print("X win!!!")
                break

            elif self.ttt.check_winner() == "d":
                print("무승부")
                break
Esempio n. 2
0
class GameManager:
    def __init__(self):
        self.ttt = TicTacToe()

    def play(self):
        #show_board()
        print(self.ttt)
        while True:
            #input()
            row = int(input("row: "))
            col = int(input("col: "))
            self.ttt.set(row, col)
            print(self.ttt)
            #check_winner()
            if self.ttt.check_winner() in ["O", "X", "d"]:
                break

        if self.ttt.check_winner() == "O":
            #  O:
            print("O가 이겼습니다.")
        elif self.ttt.check_winner() == "X":
            #  X:
            print("X가 이겼습니다.")
        elif self.ttt.check_winner() == "d":
            #  d:
            print("무승부입니다.")
class Gamemanager:
    def __init__(self):
        self.ttt = TicTacToe()

    def play(self):
        #show_bord

        #반복하자
        while True:
            #위치를 입력 받자
            row = int(input("row: "))
            col = int(input("col: "))
            #말을 놓자
            self.ttt.set(row,col)
            print(self.ttt)
            #check_winner()
            if self.ttt.check_winner() == "o":
                print("O 승리,ㅊㅋㅊㅋ")
                break
            elif self.ttt.check_winner() == "x":
                print("x 승리,ㅊㅋㅊㅋ")
                break
            elif self.ttt.check_wiiner() == "d":
                print("무승부")
                break
Esempio n. 4
0
class GameManager:
    def __init__(self):
        self.ttt = TicTacToe()
        self.images=dict(0)
    def play(self):
        # 게임판 보여주자
        print(self.ttt)
        while True:
            # row, col 입력받자
            row = int(input("row : "))
            col = int(input("col :"))
            self.ttt.set(row, col)
            self.ttt.set(1, 1)
            print(self.ttt)

            # check_winner 면 끝내자
            if self.ttt.check_winner() == "O":
                print("O win!!!")
                break
            elif self.ttt.check_winner() == "X":
                print("X win!!!")
                break
            elif self.ttt.check_winner() == "d":
                print("무승부")
                break
Esempio n. 5
0
class GameManager:
    def __init__(self):
        self.ttt = TicTacToe()

    def play(self):
        #게임판 보여주기
        print(self.ttt)

        while True:
            #row, col 입력받기
            row = int(input("row : "))
            col = int(input("col : "))

            self.ttt.set(row, col)
            print(self.ttt)

            #check_winner 면 끝내자
            if self.ttt.check_winner() == "o":
                print("o Win!")
                break
            elif self.ttt.check_winner() == "x":
                print("x Win!")
                break
            elif self.ttt.check_winner() == "d":
                print("무승부")
                break
Esempio n. 6
0
class GameManager:
    def __init__(self):
        self.ttt = TicTacToe()

    def play(self):
        #show board
        print(self.ttt)
        #반복하자
        while (True):
            #   위치를 입력받자
            row = int(input("row : "))
            col = int(input("col : "))
            #   말을 놓자
            self.ttt.set(row, col)
            print(self.ttt)
            #   check_winner()
            #결과 출력하자
            if self.ttt.check_winner() == "O":
                print("O 승리, ㅊㅋㅊㅋ")
                break
            elif self.ttt.check_winner() == "X":
                print("X 승리, ㅊㅋㅊㅋ")
                break
            elif self.ttt.check_winner() == "d":
                print("무승부")
                break
Esempio n. 7
0
class GameManager_GUI:
    def __init__(self):
        self.ttt = TicTacToe()
        CANVAS_SIZE = 300
        self.TILE_SIZE = CANVAS_SIZE / 3

        self.root = tkinter.Tk()
        self.root.title("틱택토") # setTitle이 아닌, 그냥 title
        self.root.geometry(str(CANVAS_SIZE) + "x" + str(CANVAS_SIZE)) # "300x300"
        self.root.resizable(width=False, height=False) # 창크기 변경 x
        self.canvas = tkinter.Canvas(self.root, bg="white", width=CANVAS_SIZE, height=CANVAS_SIZE)
        self.canvas.pack()

        self.images = dict()
        self.images["O"] = tkinter.PhotoImage(file="img/O.gif")
        self.images["X"] = tkinter.PhotoImage(file="img/X.gif")

        self.canvas.bind("<Button-1>", self.click_handler)

    def click_handler(self, event):
        row = int(event.y // self.TILE_SIZE) # 교과서 : math.floor(event.y / self.TILE_SIZE)
        col = int(event.x // self.TILE_SIZE)
        self.ttt.set(row, col)
        # print(self.ttt)

        # draw_board()
        self.draw_board()

        #check_winner()
        if self.ttt.check_winner() == "O":
            messagebox.showinfo("게임오버", "O win !")
            self.root.quit()
        elif self.ttt.check_winner() == "X":
            messagebox.showinfo("게임오버", "X win !")
            self.root.quit()
        elif self.ttt.check_winner() == "d":
            messagebox.showinfo("게임오버", "무승부")
            self.root.quit()

    def draw_board(self):
        # clear
        self.canvas.delete("all")

        x = 0
        y = 0

        for i, v in enumerate(self.ttt.board):
            if v == ".":
                pass
            elif v == "O":
                self.canvas.create_image(x, y, anchor="nw", image=self.images["O"])
            elif v == "X":
                self.canvas.create_image(x, y, anchor="nw", image=self.images["X"])
            x += self.TILE_SIZE
            if i % 3 == 2:
                x = 0
                y += self.TILE_SIZE

    def play(self):
        self.root.mainloop()
Esempio n. 8
0
class GameManager_GUI:
    def __init__(self):
        CANVAS_SIZE = 300
        self.TILE_SIZE = CANVAS_SIZE/3

        self.root = tkinter.Tk()
        self.root.title("틱택토")
        self.root.geometry(str(CANVAS_SIZE)+"x"+str(CANVAS_SIZE))
        self.root.resizable(width=False, height=False)
        self.canvas = tkinter.Canvas(self.root, bg="white", width=CANVAS_SIZE, height=CANVAS_SIZE)
        self.canvas.pack()
        self.images = dict()
        self.images["O"] = tkinter.PhotoImage(file="O.gif")
        self.images["X"] = tkinter.PhotoImage(file="X.gif")

        self.ttt = TicTacToe()
        self.canvas.bind("<Button-1>", self.click_handler)

    def click_handler(self, event):
        self.ttt.set(math.floor(event.y/self.TILE_SIZE), math.floor(event.x/self.TILE_SIZE))
        print(math.floor(event.y/self.TILE_SIZE), math.floor(event.x/self.TILE_SIZE))
        self.draw_board()
        #check_winner()
        if self.ttt.check_winner() == "O":
            #  O:
            messagebox.showinfo("Game Over", "O가 이겼습니다.")
            self.root.quit()
        elif self.ttt.check_winner() == "X":
            #  X:
            messagebox.showinfo("Game Over", "X가 이겼습니다.")
            self.root.quit()
        elif self.ttt.check_winner() == "d":
            #  d:
            messagebox.showinfo("Game Over", "무승부입니다.")
            self.root.quit()

    def draw_board(self):
        # clear
        self.canvas.delete("all")

        SIZE = 100
        x = 0
        y = 0
        for i, v in enumerate(self.ttt.board):
            if v == ".":
                pass
            elif v == "O":
                self.canvas.create_image(x, y, anchor="nw", image=self.images["O"])
            elif v == "X":
                self.canvas.create_image(x, y, anchor="nw",image=self.images["X"])
            x += SIZE
            if i % 3 == 2:
                x = 0
                y += SIZE

    def play(self):
        self.root.mainloop()
class GameManager_GUI:
    def __init__(self):
        self.ttt = TicTacToe()
        CANVAS_SIZE = 300
        self.TILE_SIZE = CANVAS_SIZE/3

        self.root = tkinter.Tk()#창 frame
        self.root.title("틱 택 토")
        self.root.geometry(str(CANVAS_SIZE)+"x"+str(CANVAS_SIZE)) #geometry("300x300")
        self.root.resizable(width=False, height=False)
        self.canvas = tkinter.Canvas(self.root, bg="white", width=CANVAS_SIZE, height=CANVAS_SIZE)

        self.canvas.pack()

        self.images = dict()
        self.images["o"] = tkinter.PhotoImage(file="img/o.gif")
        self.images["x"] = tkinter.PhotoImage(file="img/x.gif")
        self.canvas.bind("<Button-1>",self.chick_handler)
    def click_handler(self, event):
        row = math.floor(event.y/self.TILE_SIZE)
        col = math.floor(event.x/self.TILE_SIZE)
        self.ttt.set(row,col)
        self.draw_board()
        #check_winner()
        if self.ttt.check_winner() == "o":
            tkinter.messagebox.showinfo("게임 오버", "o win!!!")
            self.root.quit()
        elif self.ttt.check_wiiner() =="x":
            tkinter.messagebox.showinfo("게임 오버", "x win!!!")
            self.root.quit()
        elif self.ttt.check_wiiner() =="d":
            tkinter.messagebox.showinfo("게임 오버", "무승부!!!")
            self.root.quit()

    def draw_board(self):
        #closer
        self.canvas.delete("all")

        SIZE = 100
        x = 0
        y = 0
        for i,v in enumerate(self.ttt.board):
            if v == ".":
                pass
            elif v == "o":
                self.canvas.create_image(x,y, anchor="nw", image=self.images["o"])
            elif v == "x":
                self.canvas.create_image(x,y, anchor="nw", image=self.images["x"])
            x += self.TILE_SIZE
            if i % 3 == 2:
                x = 0
                y += self.TILE_SIZE

    def play(self):
        self.root.mainloop()
Esempio n. 10
0
 def test_check_winner(self):
     game = TicTacToe(
         state=[
             [BALL, EMPTY, CROSS],
             [BALL, CROSS, EMPTY],
             [BALL, CROSS, CROSS],
         ],
         setup_pygame=False,
     )
     self.assertEqual(game.check_winner(),
                      BALL,
                      msg="""
             wrong winner, BALL have won on columns
             [
                 [BALL, EMPTY, CROSS],
                 [BALL, CROSS, EMPTY],
                 [BALL, CROSS, CROSS],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [CROSS, EMPTY, BALL],
                          [CROSS, BALL, EMPTY],
                          [CROSS, BALL, BALL],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on columns
             [
                 [CROSS, EMPTY, BALL],
                 [CROSS, BALL, EMPTY],
                 [CROSS, BALL, BALL],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [EMPTY, CROSS, BALL],
                          [BALL, CROSS, EMPTY],
                          [BALL, CROSS, BALL],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on columns
             [
                 [EMPTY, CROSS, BALL],
                 [BALL,  CROSS, EMPTY],
                 [BALL,  CROSS, BALL],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [EMPTY, BALL, CROSS],
                          [BALL, EMPTY, CROSS],
                          [BALL, BALL, CROSS],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on columns
             [
                 [EMPTY, BALL, CROSS],
                 [BALL,  EMPTY, CROSS],
                 [BALL,  BALL, CROSS],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [CROSS, CROSS, CROSS],
                          [BALL, EMPTY, BALL],
                          [BALL, BALL, CROSS],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on rows
             [
                 [CROSS, CROSS, CROSS],
                 [BALL, EMPTY, BALL],
                 [BALL, BALL, CROSS],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [BALL, EMPTY, BALL],
                          [CROSS, CROSS, CROSS],
                          [BALL, BALL, CROSS],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on rows
             [
                 [BALL, EMPTY, BALL],
                 [CROSS, CROSS, CROSS],
                 [BALL, BALL, CROSS],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [BALL, EMPTY, BALL],
                          [BALL, BALL, CROSS],
                          [CROSS, CROSS, CROSS],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on rows
             [
                 [BALL, EMPTY, BALL],
                 [BALL, BALL, CROSS],
                 [CROSS, CROSS, CROSS],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [CROSS, EMPTY, BALL],
                          [BALL, CROSS, BALL],
                          [CROSS, BALL, CROSS],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on diagonal
             [
                 [CROSS, EMPTY, BALL],
                 [BALL, CROSS, BALL],
                 [CROSS, BALL, CROSS],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [EMPTY, EMPTY, CROSS],
                          [BALL, CROSS, BALL],
                          [CROSS, BALL, EMPTY],
                      ])
     self.assertEqual(game.check_winner(),
                      CROSS,
                      msg="""
             wrong winner, CROSS have won on diagonal
             [
                 [EMPTY, EMPTY, CROSS],
                 [BALL, CROSS, BALL],
                 [CROSS, BALL, EMPTY],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [EMPTY, EMPTY, EMPTY],
                          [EMPTY, EMPTY, BALL],
                          [CROSS, BALL, EMPTY],
                      ])
     self.assertEqual(game.check_winner(),
                      NO_WINNER,
                      msg="""
             wrong winner on game, there in NO_WINNER
             [
                 [EMPTY, EMPTY, EMPTY],
                 [EMPTY, EMPTY, BALL],
                 [CROSS, BALL, EMPTY],
             ]
         """)
     game = TicTacToe(setup_pygame=False,
                      state=[
                          [CROSS, BALL, BALL],
                          [BALL, CROSS, CROSS],
                          [CROSS, BALL, BALL],
                      ])
     self.assertEqual(game.check_winner(),
                      DRAW,
                      msg="""
             wrong winner, we have a draw here
             [
                 [CROSS, BALL, BALL],
                 [BALL, CROSS, CROSS],
                 [CROSS, BALL, BALL],
             ]
         """)