-
Notifications
You must be signed in to change notification settings - Fork 0
/
chesssquare.py
40 lines (32 loc) · 1.1 KB
/
chesssquare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Name: Leigh Stauffer
Project 6
File: chesssquare.py
"""
from breezypythongui import EasyCanvas
from tkinter import PhotoImage
class ChessSquare(EasyCanvas):
"""Represents a square in a chess board."""
IMAGE = None
def __init__(self, parent, width, height, background):
"""Sets up the canvas."""
EasyCanvas.__init__(self, parent, width = width,
height = height, background = background)
self.parent = parent
self.x = width / 2
self.y = height / 2
if not ChessSquare.IMAGE:
ChessSquare.IMAGE = PhotoImage(file = "Queen.gif")
self.queenExists = False
def isOccupied(self):
return self.queenExists
def drawQueen(self):
"""Draws the queen on the square."""
if self.isOccupied(): return
self.item = self.drawImage(ChessSquare.IMAGE, self.x, self.y)
self.queenExists = True
def eraseQueen(self):
"""Erases the queen from the square."""
if not self.isOccupied(): return
self.delete(self.item)
self.queenExists = False