用python设计一款象棋游戏的代码
import pygame
# Define some colors
black = ( 0, 0, 0)
white = ( 255, 255, 255)
green = ( 0, 255, 0)
red = ( 255, 0, 0)
# This sets the width and height of each grid location
width=60
height=60
# This sets the margin between each cell
margin=10
# Initialize pygame
pygame.init()
# Set the height and width of the screen
screen_width = 700
screen_height = 600
screen = pygame.display.set_mode([screen_width, screen_height]) #Set title of screen
pygame.display.set_caption("The Chess Game")
#Loop until the user clicks the close button
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
# -------- Main Program Loop -----------
while done == False:
for event in (): # User did something
pe == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop # Set the screen background
screen.fill(white)
# Draw the grid
for row in range (8):python可以做什么游戏
for column in range (8):
color = black
if (row + column) % 2 == 0:
color = red
(screen,color,[(margin+width)*column+margin,( margin+height)*row+margin,width,height])
# Limit to 60 frames per second
clock.tick(60)
# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# Be IDLE friendly pygame.quit()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论