Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- def fun(l:list, x):
- print(l)
- photo = PhotoImage(file = 'White_Rook.png')
- for i in range(64):
- if board.boxes[i].coordinates == l:
- print(board.boxes[i].file)
- board.boxes[i].photo = PhotoImage("White_Rook.png")
- board.boxes[i].button.config(image = photo)
- board.boxes[i].file = "White_Rook.png"
- board.boxes[i].button.grid(row = l[0], column = l[1])
- class box:
- def __init__(self, coords:list, Master, color:str = "None", FigureName:str = "None"):
- self.master = Master
- names = ["Pawn", "Rook", "Knight", "Bishop", "Queen", "King"]
- if len(coords) != 2:
- raise NameError("Wrong coords")
- else:
- self.coordinates = coords
- if color != "Black" and color != "White" and color != "None":
- raise NameError("Wrong piece color")
- else:
- self.PieceColor = color
- if color == "Black":
- if FigureName == "Pawn":
- self.file = "Black_Pawn.png"
- self.Figure = Pawn(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Knight":
- self.file = "Black_Knight.png"
- self.Figure = Knight(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Bishop":
- self.file = "Black_Bishop.png"
- self.Figure = Bishop(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Rook":
- self.file = "Black_Rook.png"
- self.Figure = Rook(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Queen":
- self.file = "Black_Queen.png"
- self.Figure = Queen(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "King":
- self.file = "Black_King.png"
- self.Figure = King(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif color == "White":
- if FigureName == "Pawn":
- self.file = "White_Pawn.png"
- self.Figure = Pawn(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Knight":
- self.file = "White_Knight.png"
- self.Figure = Knight(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Bishop":
- self.file = "White_Bishop.png"
- self.Figure = Bishop(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Rook":
- self.file = "White_Rook.png"
- self.Figure = Rook(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "Queen":
- self.file = "White_Queen.png"
- self.Figure = Queen(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- elif FigureName == "King":
- self.file = "White_King.png"
- self.Figure = King(self.PieceColor, self.coordinates)
- self.Figure_Name = FigureName
- if FigureName not in names:
- self.Figure = NoPiece(self.coordinates)
- self.Figure_Name = "None"
- if FigureName in names:
- self.photo = PhotoImage(file = self.file)
- else:
- self.file = "None.png"
- self.photo = PhotoImage(file = "None.png")
- self.button = Button(Master, image = self.photo, bg = "#69230a")
- if (self.coordinates[0] + self.coordinates[1]) % 2 == 1:
- self.button = Button(Master, image = self.photo, bg = "#69230a")
- else:
- self.button = Button(Master, image = self.photo, bg = "white")
- if (self.Figure_Name in names) and (self.PieceColor == "White" or self.PieceColor == "Black"):
- self.State = 1
- elif self.Figure_Name == "None":
- self.State = 0
- else:
- raise NameError("Wrong Piece name")
- self.button.bind("<Button>", self.funkcja)
- def funkcja(self, event):
- fun(self.coordinates, self)
- class Board:
- def __init__(self, _boxes:list, Master):
- self.boxes = _boxes
- for i in range(64):
- self.boxes[i].button.grid(row = int(i / 8), column = i % 8)
- def MovePiece(self, x, event):
- if x == 0:
- print("black rook")
- else:
- print("Not rook")
- class Piece:
- def __init__(self, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- def move(self, event):
- pass
- class Pawn(Piece):
- def __init__(self, _color:str, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- colors = ["White", "Black"]
- if _color in colors:
- self.Color = _color
- else:
- raise NameError("WrongColorException")
- self.moved = 0
- def move(self, event):
- if self.Color == "White":
- print("White pawn moves")
- elif self.Color == "Black":
- print("Black Pawn moves")
- class Knight(Piece):
- def __init__(self, _color:str ,_coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- colors = ["White", "Black"]
- if _color in colors:
- self.Color = _color
- else:
- raise NameError("WrongColorException")
- def move(self, event):
- print("Knight")
- class Bishop(Piece):
- def __init__(self, _color:str, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- colors = ["White", "Black"]
- if _color in colors:
- self.Color = _color
- else:
- raise NameError("WrongColorException")
- def move(self, event):
- print("Bishop")
- class Rook(Piece):
- def __init__(self, _color:str, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- colors = ["White", "Black"]
- if _color in colors:
- self.Color = _color
- else:
- raise NameError("WrongColorException")
- def move(self, event):
- print("Rook")
- class Queen(Piece):
- def __init__(self, _color:str, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- colors = ["White", "Black"]
- if _color in colors:
- self.Color = _color
- else:
- raise NameError("WrongColorException")
- def move(self, event):
- print("Queen")
- class King(Piece):
- def __init__(self, _color:str, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- colors = ["White", "Black"]
- if _color in colors:
- self.Color = _color
- else:
- raise NameError("WrongColorException")
- def move(self, event):
- print("King")
- class NoPiece(Piece):
- def __init__(self, _coords:list):
- if len(_coords) == 2:
- self.coords = _coords
- self.st = Status()
- def move(self, event):
- print("No figure on this box")
- class Status:
- Status = 0
- def __init__(self):
- self.currentCoords = [-1, -1]
- root = Tk()
- root.title("Cześć Klaudiusz xD")
- p1 = box([0, 0], root, "Black", "Rook")
- p2 = box([0, 1], root, "Black", "Knight")
- p3 = box([0, 2], root, "Black", "Bishop")
- p4 = box([0, 3], root, "Black", "Queen")
- p5 = box([0, 4], root, "Black", "King")
- p6 = box([0, 5], root, "Black", "Bishop")
- p7 = box([0, 6], root, "Black", "Knight")
- p8 = box([0, 7], root, "Black", "Rook")
- p9 = box([1, 0], root, "Black", "Pawn")
- p10 = box([1, 1], root, "Black", "Pawn")
- p11 = box([1, 2], root, "Black", "Pawn")
- p12 = box([1, 3], root, "Black", "Pawn")
- p13 = box([1, 4], root, "Black", "Pawn")
- p14 = box([1, 5], root, "Black", "Pawn")
- p15 = box([1, 6], root, "Black", "Pawn")
- p16 = box([1, 7], root, "Black", "Pawn")
- p17 = box([2, 0], root)
- p18 = box([2, 1], root)
- p19 = box([2, 2], root)
- p20 = box([2, 3], root)
- p21 = box([2, 4], root)
- p22 = box([2, 5], root)
- p23 = box([2, 6], root)
- p24 = box([2, 7], root)
- p25 = box([3, 0], root)
- p26 = box([3, 1], root)
- p27 = box([3, 2], root)
- p28 = box([3, 3], root)
- p29 = box([3, 4], root)
- p30 = box([3, 5], root)
- p31 = box([3, 6], root)
- p32 = box([3, 7], root)
- p33 = box([4, 0], root)
- p34 = box([4, 1], root)
- p35 = box([4, 2], root)
- p36 = box([4, 3], root)
- p37 = box([4, 4], root)
- p38 = box([4, 5], root)
- p39 = box([4, 6], root)
- p40 = box([4, 7], root)
- p41 = box([5, 0], root)
- p42 = box([5, 1], root)
- p43 = box([5, 2], root)
- p44 = box([5, 3], root)
- p45 = box([5, 4], root)
- p46 = box([5, 5], root)
- p47 = box([5, 6], root)
- p48 = box([5, 7], root)
- p49 = box([6, 0], root, "White", "Pawn")
- p50 = box([6, 1], root, "White", "Pawn")
- p51 = box([6, 2], root, "White", "Pawn")
- p52 = box([6, 3], root, "White", "Pawn")
- p53 = box([6, 4], root, "White", "Pawn")
- p54 = box([6, 5], root, "White", "Pawn")
- p55 = box([6, 6], root, "White", "Pawn")
- p56 = box([6, 7], root, "White", "Pawn")
- p57 = box([7, 0], root, "White", "Rook")
- p58 = box([7, 1], root, "White", "Knight")
- p59 = box([7, 2], root, "White", "Bishop")
- p60 = box([7, 3], root, "White", "Queen")
- p61 = box([7, 4], root, "White", "King")
- p62 = box([7, 5], root, "White", "Bishop")
- p63 = box([7, 6], root, "White", "Knight")
- p64 = box([7, 7], root, "White", "Rook")
- GlobalBoxes = [p1, p2, p3, p4, p5, p6, p7, p8,
- p9, p10, p11, p12, p13, p14, p15, p16,
- p17, p18, p19, p20, p21, p22, p23, p24,
- p25, p26, p27, p28, p29, p30, p31, p32,
- p33, p34, p35, p36, p37, p38, p39, p40,
- p41, p42, p43, p44, p45, p46, p47, p48,
- p49, p50, p51, p52, p53, p54, p55, p56,
- p57, p58, p59, p60, p61, p62, p63, p64]
- GlobalClick = 0
- board = Board(GlobalBoxes, root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement