How to think like a Computer Scientist: 课后习题第十七章3

发布时间:2016-12-11 14:11:35 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"How to think like a Computer Scientist: 课后习题第十七章3",主要涉及到How to think like a Computer Scientist: 课后习题第十七章3方面的内容,对于How to think like a Computer Scientist: 课后习题第十七章3感兴趣的同学可以参考一下。

#------------------------------------------------------------------------------- # 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()

上一篇:到底怎么样才叫看书?——下篇
下一篇:Balanced Binary Tree

相关文章

相关评论