Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABCMeta, abstractmethod, abstractproperty
- from enum import Enum
- class TicTacToeBoardBase:
- """A base class used for implementing the GUI part of a Tic-Tac-Toe board."""
- __metaclass__ = ABCMeta
- Empty = 0
- X = 1
- O = 2
- defaultBoardColor = (0, 0, 0)
- defaultBoardWidth = 100
- defaultXColor = (1, 0, 0)
- defaultOColor = (0, 1, 0)
- class winCase(Enum):
- vertLeft=1
- vertMiddle=2
- vertRight=3
- horizTop=4
- horizMiddle=5
- horizBottom=6
- diagonalTopLeft=7
- diagonalTopRight=8
- @abstractproperty
- def board(self):
- """The board, stored as a 1D array of length 9. Can only store Board.X, Board.Y, and Board.Empty. See above."""
- @abstractproperty
- def boardPosition(self):
- """The position of the board, stored as a tuple."""
- @abstractproperty
- def boardColor(self):
- """The color of the board, stored as a 3 or 4 item tuple containing floats between 0 and 1."""
- @abstractproperty
- def boardWidth(self):
- """The width of the lines of the board, in pixels."""
- @abstractproperty
- def xColor(self):
- """The color of the X, stored as a 3 or 4 item tuple containing floats between 0 and 1."""
- @abstractproperty
- def oColor(self):
- """The color of the O, stored as a 3 or 4 item tuple containing floats between 0 and 1."""
- @abstractproperty
- def boardSize(self):
- """The length of the (square) board."""
- @abstractmethod
- def __init__(self, x, y, boardColor, xColor, oColor, boardWidth):
- """Create the canvas, and anything else needed to start the program initially."""
- _,__,___,____,_____,_____=x,y,boardColor,xColor,oColor,boardWidth # Removes PyCharm warning
- @abstractmethod
- def drawBoard(self):
- """Draw the board at the given coordinates, with the given width and height.
- Assume (0,0) is in the top left, and the positive direction is right in the X axis, and down in the Y axis.
- The minimum size of the board is 5px by 5px."""
- @abstractmethod
- def redrawBoard(self):
- """Redraw the board after a value change."""
- @abstractmethod
- def drawX(self, xIndex, yIndex):
- """Draw an X at the given x index or y index, treating it as a 3x3, zero-indexed array.
- Raise an exception when an X is drawn over an existing X or existing O."""
- @abstractmethod
- def drawO(self, xIndex, yIndex):
- """Draw an X at the given x index or y index, treating it as a 3x3, zero-indexed array.
- Raise an exception when an X is drawn over an existing X or existing O."""
- @abstractmethod
- def drawLine(self, winCase):
- """Draw the victory line for the given winCase."""
- @abstractmethod
- def onClick(self, x, y, button=1):
- """Run when the mouse is pressed."""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement