G11_C8
Player Lives and declaring the WINNER
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
4-10 | Warm up Quiz+Revision | 5 min | |
TA1 | 11-17 | Ball bypassing the paddle and hitting the wall. Player life is decremented | 7 min |
TA2 | 18-20 | Game over is displayed | 6 min |
TA3 | 21-23 | Code for winner declaration | 10 min |
SA1 | 24 | Student Activity 1 | 2 min |
SA2 | 25-26 | Student Activity 2 | 2 min |
SAA 1 | 27-28 | Student Additional Activity 1 | |
SAA 2 | 29 | Student Additional Activity 2 | |
30-32 | Post Class Quiz | 4 min |
Slide No. | Topic |
---|---|
18 | TA1 solution |
21 | TA2 solution |
25 | SA1 solution |
29 | SAA1 solution |
30 | SAA2 solution |
Class Structure
Preparation and Reference
Pre-Requisites
FOR TEACHER
FOR STUDENTS
1. Computer with an Internet connection.
2. The latest browser installed.
1. Computer with an Internet connection.
2. The latest browser installed.
3. Spyder installed.
4. Projector to present the screen
(WARM-UP QUIZ)
Same images
What would be the output of the
following codes:
Q.1
-
String and Int are the two integer datatypes, which will be resulted from the output of above two code blocks.
-
The output of first code block is "String".
-
The output of second code block is "Int"
name="Grade 11"
print(type(name))
age=68
print(type(age)
1.
2.
1. 0
A
B
2. 68
1. Grade 11
2. 68
C
1. String
2. Int
What would happen, when the
following code snippet runs:
for i in bricksR:
if i.collidepoint(ball.x,ball.y):
bricksR.remove(i)
ballx=-ballx
bally=-bally
score+=3
Q.2
The x and y coordinates of the ball will get reset to 0. Score will get incremented by 3.
A
C
The x and y coordinates of the ball will get updated 10. Score will get incremented by 2.
B
The x and y coordinates of the ball will get updated. Score will get incremented by 3.
Revise!!
- Created a paddle
- Created a ball
import pygame
...
pygame.Rect()
....
for event in pygame.event.get():
...
pygame.draw.rect()
pygame.display.update()
- Ball is moving in x and y direction
ballx=-1
bally=-1
...
ball.x=ball.x+ballx
ball.y=ball.y+bally
if ball.x>=590:
ballx=-ballx
if ball.x<=10:
ball.x=-ballx
...
- Movement of paddle in y direction.
- Changing the direction of ball after hitting the paddle
...
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
if paddle.x<540:
paddle.x+=paddlex
if event.key == pygame.K_LEFT:
if paddle.x>0:
paddle.x-=paddlex
...
if paddle.collidepoint(ball.x,ball.y):
bally=-bally
...
- Creation of Bricks
...
for i in range(6):
brick=pygame.Rect(10 + i* 100,60,80,30)
pygame.draw.rect(screen,(255,0,0),brick)
for i in range(6):
brick=pygame.Rect(10 + i* 100,100,80,30)
pygame.draw.rect(screen,(255,100,0),brick)
...
- Implementing Lists
...
carryOn = True
while carryOn:
for event in pygame.event.get():
if event.type == pygame.QUIT:
carryOn = False
...
- Introduction to Lists, removing bricks after collision and displaying score
...
for i in bricksR:
if i.collidepoint(ball.x,ball.y):
bricksR.remove(i)
...
for i in bricksR:
if i.collidepoint(ball.x,ball.y):
bricksR.remove(i)
ballx=-ballx
bally=-bally
score+=3
...
font = pygame.font.Font(None, 34)
text = font.render("Score: ", 1, WHITE)
screen.blit(text, (20,10))
...
if ball.y>=590:
lives-=1
font = pygame.font.Font(None, 74)
text = font.render("LOST A LIFE", 1, WHITE)
screen.blit(text, (150,250))
font = pygame.font.Font(None, 34)
text = font.render("Lives left:"+str(lives), 1, WHITE)
screen.blit(text, (150,300))
pygame.display.flip()
ball.x=200
ball.y=250
pygame.time.wait(1000)
if lives==0:
font = pygame.font.Font(None, 74)
text = font.render("GAME OVER", 1, RED)
screen.blit(text, (150,350))
pygame.display.flip()
pygame.time.wait(2000)
if score>=10:
font = pygame.font.Font(None, 74)
text = font.render("YOU WON!!", 1, RED)
screen.blit(text, (150,350))
pygame.display.flip()
pygame.time.wait(2000)
break
SA 1
Step 1: Write a code to declare a winner, when the score hits 30.
Step 2: Change the color of the font "You Won" to Green.
SA 2
Write a code to change the color of "Lost Life" and "Lives left " to WHITE
GREAT!
SAA 1: Write a program, using "while loop" to print the sum of first 10 natural numbers
white
white
200
250
Solution
GREEN
score==30
SAA 2: Write a program, using "for loop" to print the sum of all the numbers, stored in a list
Solution
C
If you want to display text data, what is the correct sequence of execution of events ?
Q.1
A
Specify style of text --->Specify content of text ---> Display text
B
Specify content of text ---> Specify style of text ---> Display text
C
Specify content of text ---> Display text---> Specify style of text
Which of the following is the correct sequence of commands, that are to be executed by Spyder Interpreter ?
C
Q.2
A
font=pygame.font.Font(name,size)
text=font.render(text,smoothen,color)
screen.blit(text,location)
B
font=pygame.Font(name,size)
text=font.render(text,smoothen,color)
screen.blit(location,text)
C
font=pygame.Font(name,size)
text=font.render(text,smoothen,color)
screen.blit(text,location)
G11 C8_ANJALI
By anjali_sharma
G11 C8_ANJALI
- 102