Question: Use this chessboard (python): import basic_graphics from cmu_112_graphics import * def swapRows(board): # Swap the first and last rows of the board board[0], board[-1] =

Use this chessboard (python):

import basic_graphics

from cmu_112_graphics import *

def swapRows(board):

# Swap the first and last rows of the board

board[0], board[-1] = board[-1], board[0]

return board

def drawChessBoard(canvas, width, height, board, color, margin):

# Set background color of canvas to blue

canvas.config(background='blue')

canvas.pack()

# Convert the color to hexadecimal format

color2 = "#{:02x}{:02x}{:02x}".format(*color)

# Calculate the size of the spacers between squares

spacer = (width - (margin * 2)) // 8

# Draw the chess board

for i in range(8):

for j in range(8):

# Determine the fill color for the square

if (i + j) % 2 == 0:

fill = 'white'

else:

fill = color2

# Create the rectangle for the square

canvas.create_rectangle(i * spacer + margin, j * spacer + margin, (i + 1) * spacer + margin, (j + 1) * spacer + margin, fill=fill, outline='black')

# Get the standard chess board

chessBoard = getStandardChessBoard()

# If the board is reversed, swap the rows

if board[0][0].islower():

chessBoard = swapRows(chessBoard)

# Draw the chess pieces

for j in range(8):

for i in range(8):

piece = chessBoard[j][i]

if piece != ' ':

canvas.create_text((i * spacer + margin) + spacer // 2, (j * spacer + margin) + spacer // 2, text=piece, font=f'Arial {spacer // 2} bold', fill='black')

# Set the scroll region for the canvas

canvas.config(scrollregion=canvas.bbox("all"))

def getStandardChessBoard():

# Return the standard chess board

return [

['', '', '', '', '', '', '', ''],

['', '', '', '', '', '', '', ''],

[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],

[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],

[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],

[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],

['', '', '', '', '', '', '', ''],

['', '', '', '', '', '', '', '']

]

def draw(canvas, width, height):

drawChessBoard(canvas, width, height, "RHBQPPHRPPKBPPPP pppppppprhbqkbhr", (0, 234, 255), 30)

def testAll():

basic_graphics.run(width=800, height=800)

def main():

testAll()

if __name__ == '__main__':

main()

Extend the chess board included with some animated features. You must satisfy the following requirements to get full credit:

When the mouse left-click button is pressed inside a cell, and there's a piece of the player's color inside the cell, that piece is selected. Use the print function to indicate which row and col were selected, and if a piece was selected or not [ 8 points ]

Your code MUST follow the MVC approach.

Only one piece can be selected at any time. The selected piece must match the color of the player (black or white).

When a piece is selected, the piece blinks (appears and dissapears): it is visible for 0.5 seconds, and not-visible for 0.5 seconds. [8 points]

When the mouse left-click button is pressed inside a cell that doesn't contain any piece, inside a cell that contains a piece of a different color , or outside the board, the currently selected piece is unselected. When any key except the keyboard arrows is pressed, the currently selected piece is unselected. Use the print function to report that the current piece was unselected. [ 8 points ]

When a piece is selected, the user can move the piece up, down, left, or right using the keyboard arrows. The piece must continue to blink. [8 points]

A selected piece cannot be moved to a cell that already contains a piece of same color. [5 points]

When the program starts, a splash screen is displayed with following message [6 pts]

 Welcome to MightyChess Press s to start Press w to select the white pieces Press b to select the black pieces 

Implement the functionality of the intro screen (keys s, w, and b) [7 points]

In the upper left hand corner of the screen is a timer. It counts down from 60 seconds to 0 seconds, only displaying whole seconds. [7 points]

After the 60 second timer has counted down to 0, the game stops and displays "Game Over" [5 points]

If all pieces of different color have been removed, the user wins. The game stops and displays "You Win". [5 points]

When the user presses the Space Bar, a splash screen that covers the entire canvas is shown, with the word "Game Paused". The countdown timer also stops. [6 points]

When the user presses the Space Bar when the game is paused, the game and the countdown timer should resume [7 points]

A selected piece can be moved to a cell that already contains a piece of different color. In this case, the other piece is removed from the board. [8 points]

A selected piece cannot be moved outside the board. For instance, if it is located in the first row and the user pressed up arrow, the piece shouldn't move. [7 points]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!