Docsity

Snake Game for Computer Science, Assignments of Computer science

Toggle sidebar
bg1

Partial preview of the text

Download Snake Game for Computer Science and more Assignments Computer science in PDF only on Docsity!

Dl) pygame. init© SO eee Er) 600 (CP) white = (255, 255, 255) red = (213, 50, 80) Ck COMES) ast Er ele ee snake_speed = 15 Ee Brat clock = pygame.time.Clock¢) renee CRN ea en GT te ea ae) Cm ee ee el a Cm oe ene mets 2 ee eee aC ae PC ae Ce ana) def message(msg, color): mesg = font_style.render(msg, True, color) dis.blit(mesg, [width / 6, height / 3]) cr POH Prem ee ers game_close = False cal an Orta fortes ce emer snake_List = [] eye ae cd reel Peer uC aOR cee Ca SU EE) round(random.randrange(@, height - snake_block) / 10.0) * 10.0 Oe ean while game_close == True: Cieeaea Kerrey eet Gn oes eo ee cata CN CC) pygame..display.updateC) eee O ed if event.type — pygame.KEYDOWN: a ee ea eee ee a Pelee ee pa een a gamel.oop() for event in pygame.event.get(): Se aa ee Ce ee eat) if event.type == pygame.KEYDOWN: if event.key = pygame.K_LEFT: See et em Cm ate a t) Ne ee snake_block Smee eure emer Cee nt Ree eB pee eee Ce hr cme een) een Ce Ree RUE SC eae game_close = True eee ee Vere mer dis. fillCwhite) pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_bLock] snake_Head = [] Pee Sere cures) Pee eRe eu eeb) Pe ee te Meee em) Cen mnt See mae Co Poe Cm n es] for x in snake_List[:-1]: ae ee Cn game_close = True Ore Cyr oe) Ct aT Ce Res) pygame. dispLay.updateC) ce een a Re or Cr ume CMC Le em Ces AOR foody = round¢random.randrange(@, height - snake_block) / 10.0) * [en oe el clock. tick(snake_speed) CO ee as@) rmeaO} e display pygame.display.set_mode((width, height)) OL Mee emcee se nC) ra Port) CT