#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: penglaixy
#
# Created: 08/09/2013
# Copyright: (c) penglaixy 2013
# Licence: <your licence>
#-------------------------------------------------------------------------------
import pygame
import random
card_image = pygame.image.load("cards.png")
cards_width = card_image.get_width()//13
cards_height = card_image.get_height()//4
class CardSprite:
def __init__(self, img, num, target_pos):
self.image = img
self.card_in_row = num // 13
self.card_in_col = num % 13
self.pos = target_pos
def draw(self, target_surface):
patch_rect = (cards_width * self.card_in_col, cards_height * self.card_in_row, cards_width, cards_height)
target_surface.blit(self.image, self.pos, patch_rect)
return
def draw_board():
'''
Draw a chess board with queens, from the borad.
'''
pygame.init()
surface_wz = cards_width * 5
surface_ht = cards_height
surface = pygame.display.set_mode((surface_wz, surface_ht))
card_list =list(range(52))
my_clock = pygame.time.Clock()
print "Hello world!"
while True:
ev = pygame.event.poll()
if ev.type == pygame.QUIT:
break
random.shuffle(card_list)
card_queen = []
for (col, card_num) in enumerate(card_list):
if col == 5:
break
card_instance = CardSprite(card_image, card_num, (col*cards_width, 0))
card_queen.append(card_instance)
for sprite in card_queen:
sprite.draw(surface)
pygame.display.flip()
my_clock.tick(4)
pygame.quit()
def main():
'''
set up the game and run the main game loop
'''
draw_board()
if __name__ == '__main__':
main()
How to think like a Computer Scientist: 課後習題第十七章3
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.