Skip to content
Snippets Groups Projects
Commit 554cfbc7 authored by @dion-tsang's avatar @dion-tsang
Browse files

Lesson 06

parent 10026e36
No related branches found
No related tags found
No related merge requests found
Pipeline #503762 passed
# Lesson 06 - Rainbow Chain 🌈 彩虹链 🦄🦄
## While-loop vs for-loop 循环语句 🎡
![alt text](image.png)
什么是 while 循环? 什么是 for 循环? 上面的结果分别是什么?
## Initial Code
以下是你的练习代码,请复制粘贴到你的编辑器上,**应用刚才学到的循环语句**,绘制出目标图案。
![alt text](image-1.png)
```python
import pygame
# Initialize pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
SAND = (255, 255, 255)
# Game setup
# window size
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# window caption
pygame.display.set_caption("Chrome Dino Game")
# Create a Frame Rate object
clock = pygame.time.Clock()
# Game loop
running = True
while running:
screen.fill(SAND)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Ground
pygame.draw.rect(screen,(0,0,0),(0,500,800,5))
# Create a cube
pygame.draw.rect(screen, (0, 0, 255), (80, 400, 50, 100), 0)
pygame.display.flip()
clock.tick(30)
pygame.quit()
```
docs/assignments/ISAGeekClub/Lesson06/image-1.png

76.3 KiB

docs/assignments/ISAGeekClub/Lesson06/image.png

94.2 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment