PYTHON
Welcome to my basic games!
In class we have learnt to code with python , this are my codes!
My python codes using pygame zero:
Enter Name
print("Enter here your name:")
x= input()
print("What's up", x)
if x == "Jose":
print("That's the name of my dog")
This is a videotutorial showing how to create Enter Name:
Eye Colour
print("Enter your eye colour")
x = input()
print("WoW", x)
if x == "Green":
print("Green like the grass")
elif x == "Blue":
print("Blue like the sea")
elif x == "Brown":
print("Brown like the wood")
else:
print("That's an awesome colour")
This is a videotutorial showing how to create Eye Colour:
Random
Guess
import random #random is a python libary to ceate random numbers
n = random.randint(0, 200) #n is a integer number from 0 to 200
guesses = 0 #guesses is a variable with initial vale 0
while True: #do the following code all the time
guesses = guesses + 1 #add a guess every time I try to answer
print("Guess the number I am thinking") #show on the screen this question
g = int(input()) #g is a number entered by the user (input()
if g == n: #if the number entered by the user is equal to the random number stop the code
break
elif g < n: #if the number entered by the user is menor than the random number tell user "Try to go higher"
print("Try to go higher")
elif g > n: #if the number entered by the user is higher than the random number tell the user "Go lower or you won't get it this way"
print("Go lower or you won't get it this way")
print("Correct! You took", guesses, "guesses.")
#if the number entered by the user is correct tell the user "Correct! You took (guesses) guesses"
#tell the user also the number of guesses and the word attemps
This tutorial is explained by the "#"
Random Operation
import random #random is a python libary to ceate random numbers
n = random.randint(22, 300) #n is a integer number from 22 to 300
print("What is", n, "+45-9-5?") #this is used to show in the screen the words "What is" + the random number and the operation
g = int(input()) #g is a number entere by the user
if g == n + +45-9-5: #this does that the operation and if it's correct it'll print "You are a genious!"
print("You are a genius!")
else: #this does the operation and if it's wrong it'll print "Your teacher would be mad right now"
print("Your teacher would be mad righ now")
This tutorial is explained by the "#"
Continents
score = 0 #this confirms that your initial score is 0
print("How many continents are on the Earth?") #this prints the question
g = int(input()) #this is a number that the user needs to enter
if g == 7: #if the user entered the number "7" it'll print "Correct"
print("Correct")
score = score +1 3 if it's correct the score will be +1 point.
print("And how many countries are?") #this prints the questions
g = int(input()) #g is the number that the user needs to enter
if g == 194: #if the user entered "194" it'll print "Correct"
print("Correct")
score = score + 1 #if it's correct the score will add +1
print("You got:", score) #this prints the score you got
This tutorial is explained by the "#"
Alicia Passing
alicia = Actor('alicia') #this makes 'alicia' an sprite
alicia.topright = 0, 10 #this is the size of the sprite on topright
WIDTH = 800 #the width of the game
HEIGHT = alicia.height + 4 #the height of the game
def draw(): #this says what is going to be on the screen
screen.clear() #this clears the screen
alicia.draw() #this puts the image of the sprite
def update(): #this says what is going to move on the screen
alicia.left += 8 #the sprite is going to move 8 to the left always
if alicia.left > WIDTH: #this says that the sprite > WIDTH
alicia.right = 2 #this says that alicia right equals 2
This tutorial is explained by the "#"
Bus
autob = Actor('autob')
autob.topright = 0, 100
WIDTH = 650
HEIGHT = autob.height + 200
def draw():
screen.clear()
autob.draw()
def update():
autob.left += 10
if autob.left > WIDTH:
autob.right = 5
score = 0
def on_mouse_down(pos):
global score
if autob.collidepoint(pos):
score += 1
else:
score -= 1
print("I'll quit u 1 point, now u have:")
print(score)
This is a videotutorial showing how to create Bus:
Squirrel
ardillaviva = Actor('ardillaviva')
ardillaviva.topright = 0, 10
WIDTH = 500
HEIGHT = ardillaviva.height + 22
def draw():
screen.clear()
ardillaviva.draw()
def update():
ardillaviva.left += 6
if ardillaviva.left > WIDTH:
ardillaviva.right = 0
score = 0
def on_mouse_down(pos):
global score
if ardillaviva.collidepoint(pos):
sounds.rifle.play()
ardillaviva.image = 'ardillamuerta'
score += 1
else:
score -= 1
print("You didn't hit it")
print(score)
This is a videotutorial showing how to create Squirrel:
Nil and the Door
nilc = Actor('nilc')
nilc.topright = 0, 10
WIDTH = 650
HEIGHT = nilc.height + 22
def draw():
screen.clear()
nilc.draw()
def update():
nilc.left += 4
if nilc.left > WIDTH:
nilc.right = 0
score = 0
def on_mouse_down(pos):
global score
if nilc.collidepoint(pos):
set_nilc_hit()
score += 1
print(score)
else:
score -= 1
print(score)
def set_nilc_hit():
nilc.image = 'nile'
sounds.puerta.play()
clock.schedule_unique(set_nilc_normal, 0.4)
def set_nilc_normal():
nilc.image = "nilc"
This is a videotutorial showing how to create Nil and the Door:
Alien Fall
import random
WIDTH = 800
HEIGHT = 600
alien_hurt = Actor('alien', midbottom=(WIDTH // 2, HEIGHT))
alien = Actor('alien_hurt')
alien.topright = 100, 10
def draw():
screen.fill('violet')
alien.draw()
alien_hurt.draw()
xpos = random.randint(0, 800)
def update():
global xpos
alien.y += 5
if keyboard.left:
alien.x -= 8
if keyboard.right:
alien.x += 8
if alien_hurt.colliderect(alien):
print('you win')
alien.y = 0
xpos = random.randint(0, 800)
alien.x = xpos
if alien.y > 600:
print('you lose')
alien. y = 0
xpos = random.randint(0, 800)
alien.x = xpos
def on_mouse_down(pos):
global score
if alien.collidepoint(pos):
set_alien_hit()
score += 1
print(score)
else:
score -= 1
print(score)
def set_alien_hit():
alien.image = 'alien_hurt'
sounds.eep.play()
clock.schedule_unique(set_alien_normal, 0.5)
def set_alien_normal():
alien.image = "alien"
This is a videotutorial showing how to create Alien Fall:
Robber
nilc = Actor('nilc')
nilc.topright = 0, 10
WIDTH = 650
HEIGHT = nilc.height + 22
def draw():
screen.clear()
nilc.draw()
def update():
nilc.left += 4
if nilc.left > WIDTH:
nilc.right = 0
score = 0
def on_mouse_down(pos):
global score
if nilc.collidepoint(pos):
set_nilc_hit()
score += 1
print(score)
else:
score -= 1
print(score)
def set_nilc_hit():
nilc.image = 'nile'
sounds.puerta.play()
clock.schedule_unique(set_nilc_normal, 0.4)
def set_nilc_normal():
nilc.image = "nilc"
This is a videotutorial showing how to create Robber:
Pong
WIDTH = 900
HEIGHT = 600
ball = Rect((150, 400), (10, 9))
bat = Rect((240, 480), (150, 20))
vx = 8
vy = 8
def draw():
screen.clear()
screen.draw.filled_rect(ball, "violet")
screen.draw.filled_rect(bat, "white")
def update():
global vx, vy
ball.x += vx
ball.y += vy
if ball.right > WIDTH or ball.left < 0:
vx = -vx
if ball.colliderect(bat) or ball.top < 0:
vy = -vy
if ball.bottom > HEIGHT:
exit()
if(keyboard.right):
bat.x += 10
elif(keyboard.left):
bat.x -= 10
This is a videotutorial showig how to create Pong:
Big Quiz: Economy Quiz
import pgzrun
import pygame
WIDTH = 1350
HEIGHT = 700
main_box = Rect(0, 0, 1250, 350)
timer_box = Rect(0, 0, 100, 80)
answer_box1 = Rect(0, 0, 375, 150)
answer_box2 = Rect(0, 0, 375, 150)
answer_box3 = Rect(0, 0, 375, 150)
answer_box4 = Rect(0, 0, 375, 150)
main_box.move_ip(50, 40)
timer_box.move_ip(10, 30)
answer_box1.move_ip(200, 400)
answer_box2.move_ip(750, 400)
answer_box3.move_ip(200, 600)
answer_box4.move_ip(750, 600)
answer_boxes = [answer_box1, answer_box2, answer_box3, answer_box4]
score = 0
time_left = 10
q1 = ["Which country is the first in the Gini Index?",
"Panama", "South Africa", "Namibbia", "Siria", 2]
q2 = ["Which is the richest busisness?",
"Apple", "Amazon", "Google", "Intel", 1]
q3 = ["What is the country with the lowest unemployment?",
"Spain", "Greece", "China", "Japan", 4]
q4 = ["Who is the richest person right now?",
"Elon Musk", "Jeff Bezos", "Ralph Lauren", "Amancio Ortega", 1]
q5 = ["Which of these countries has the highest GDP?",
"India", "China", "Morocco", "Canada",2]
q6 = ["What is the capital?",
"Money", "A house", "A car", "All of them are correct", 4]
q7 = ["What is the income of a busissness?",
"The money it does", "The money it wants", "The money it expends", "The objects that it sells", 1]
q8 = ["Who is the actual president of the USA?",
"Joe Biden", "John F. Kennedy", "Donald Trump", "Michael Jordan", 1]
q9 = ["When was made the first Bitcoin?",
"1999", "2005", "2007", "2009", 4]
q10 = ["What sport makes the more money?",
"American Football", "Baseball", "Golf", "Basketball", 1]
questions = [q1, q2, q3, q4, q5, q6, q7, q8, q9, q10]
question = questions.pop(0)
def draw():
screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
screen.fill("grey")
screen.draw.filled_rect(main_box, "yellow2")
screen.draw.filled_rect(timer_box, "red2")
for box in answer_boxes:
screen.draw.filled_rect(box, "darkorchid2")
screen.draw.textbox(str(time_left), timer_box, color=("black"))
screen.draw.textbox(question[0], main_box, color=("black"))
index= 1
for box in answer_boxes:
screen.draw.textbox(question[index], box, color=("black"))
index = index + 1
def game_over():
global question, time_left
message = "Game over. You got %s questions correct" % str(score)
question = [message, "-", "-", "-", "-", 5]
time_left = 0
def correct_answer():
global question, score, time_left
score = score + 1
if questions:
question = questions.pop(0)
time_left = 10
else:
print("End of questions")
game_over()
def on_mouse_down(pos):
index = 1
for box in answer_boxes:
if box.collidepoint(pos):
print("Clicked on answer" + str(index))
if index == question[5]:
print("You got it correct!")
correct_answer()
else:
game_over()
index = index + 1
def update_time_left():
global time_left
if time_left:
time_left = time_left - 1
else:
game_over()
clock.schedule_interval(update_time_left, 1.0)
pgzrun.go()
This is a videotutorial showing how to create Economy Quiz:
Web made by: Nil Cots.
Hope that you like it!