WELCOME TO MY BASIC GAMES!

We have learnt to code with python and here are some codes we have created:

Input.01

This a code to guess which is my name:


  # This orders the computer to print the sentence between the parenthesis
  print("What's your name?:")
  
  # You create a variable named x
  x = input()
  
  # This orders the computer to say Hi, and the name the person have write 
  print("Hi", x)
  
   # If the name writed is Ona the computer prints the sentence between the parenhesis
  if x == "Ona":
    print("I remember you, nice to meet you an other time")

This is a videotutotial showing how you create a basic game named input.01:

Input.02

This a code to guess how is the weather today:


  # This orders the computer to print the sentence between the parenthesis
  print("How is the weather like today?:")
  
  # You create a variable named x
  x = input()
  
  # This orders the computer to print what is between commits
  print("Today is", x)
  
  # You create the different possibilities can the user write and preparate the computer what it haves to say for each answer
  if x == "Sunny":
    print("What a good weather! Enjoy the day")
  elif x == "Cloudy":
    print("It would be better if it was sunny but that way you don't get hot")
  elif x == "Rainy":
    print("Rainy days are not pleasant but keep smiling")
  elif x == "Snowing":
    print("Snow days are so funny, play and have fun")
  elif x == "Windy":
    print("Today there's danger in the street, be careful")
  else:
    print("I don't understand your answer, please write sunny, cloudy, rainy, icy or windy ", x)

This is a videotutotial showing how you create a basic game named input.02:

Math.01

This is a code to make a maths operation:


  # This prepares the computer to understand and generate random numbers
  import random 
  
  # This create three random variables with whole numbers (int is whole number)
  # Zero is the minimum and ten the maximum
  n = random.randint(0,10)

  m= random.randint(10,20)#

  t= random.randint(0,5)

  print("What is ", n, "minus", m, "plus", t,"?")
  
  # Input is the entrance of the keyboard(str is used for words and float for decimal numbers)
  g = int(input())
  
   # If what the user writes is equal to the solution it writes correct
  if g == n - m + t: 
    print("Correct, you're in the good way")
  
   in opposite case it writes wrong
  else: 
    print("Wrong, you have to practice more")

This is a videotutotial showing how you create a basic game named math.01:

Math.02

This is a python game to make four maths operation:


  # The initial puntuation is zero
  score = 0

  # It shows this question in the screen
  print("What is 15+10 ?")
  
  # What the user writes needs to be an integrer, whole number
  g = int(input())
  
  # If the user puts 25, print correct in the screen and add 1 to the score
  if g == 25:
    print("Correct, you carry the additions very well")
    score = score + 1

  # It shows this question in the screen
  print("What is 25-7 ?")
  
  # What the user writes needs to be an integrer, whole number
  g = int(input())
  
  # If the user puts 18, print correct in the screen and add 1 to the score
  if g == 18:
    print("Correct, you're on the right track")
    score = score + 1

  # It shows this question in the screen
  print("What is 18·3 ?")
  
  # What the user writes needs to be an integrer, whole number
  g = int(input())
  
  # If the user puts 54, print correct in the screen and add 1 to the score
  if g == 54:
    print("Correct, your maths are perfect")
    score = score + 1

  # It shows this question in the screen
  print("What is 54:3 ?")
  
  # What the user writes needs to be an integrer, whole number
  g = int(input())
  
  # If the user puts 18, print correct in the screen and add 1 to the score
  if g == 18:
    print("Perfect, good job")
    score = score + 1

  # It writes in the screen the final puntuation
  print("Your score:", score)

This is a videotutotial showing how you create a basic game named math.02:

Guess.01

This is a python game to guess the number the computer is thinking for:


  # This prepares the computer to understand and generate random numbers
  import random

  # N creates an integrer number from 50 to 60
  n = random.randint(50,60)

  # Do the following code all the time counting up guesses until breack condition
  while True:
  
  # It shows in the screen this sentence
    print("I am thinking of a number from 50 to 60, can you guess what it is?")
    
  # G is an integrer,whole number entered by the user
    g = int(input())
    
  # If the number ented by the user is equal to the random number the code stops
    if g == n:
        break
        
  #If the user doesn't match the number print wrong
    else:
        print("Wrong, try another number")
        
  # The computer prints this sentence if the user matchs the number
  print("Correct! You guess my number easily")

This is a videotutotial showing how you create a basic game named guess.01:

Guess.02

This is a python game to guess the number the computer is thinking for and say yo if it's lower or higher


  #  is a python library to create random numbers
    import random

  # n is a integer number from 0 to 50
  n = random.randint(0,50)

  # guesses is a variable with initial value 0
  guesses = 0

  # do the following code all the time counting up guesses until break conditions
  while True:

  # add a guess every time I try to answer
    guesses = guesses + 1
    
  # show in the screen this question
    print("I am thinking of a number from 0 to 50, can you guess what it is?")
    
  # g is a number entered by the user
    g = int(input())
    
  # if the number entered by the user is equal to the random number the code stops
    if g == n:
  # break means stop the code when the previous condition is met
        break
        
  # if the number entered by the user is less than the random number tell the user "too low, try with a higher number"
  # elif means "else if", means if also happens this
    elif g < n:
        print("Too low, try with a higher number")
        
  # is the number entered by the user is more than the random number tell the user "too high, try with a lower number"
    elif g > n:
        print("Too high, try with a lower number")
        
  # if the number entered by the user is correct tell the user this sentence
  # tell the user also the number of attempts
  print("Perfect! You took",guesses, "attempts.")

This is a videotutotial showing how you create a basic game named guess.02:

Pong

This is a pygame zero game to ensure that the ball doesn't fall, moving a bar underneath:


  # This determines the width and height of the screen
  WIDTH = 800
  HEIGHT = 500

  # This delimits the measurements of the ball and the bat
  ball = Rect((150, 400), (16, 17))
  bat = Rect((200, 480), (100, 20))
  
  # This controls the velocity of the bat
  vx = 4
  vy = 4
  # Def is a function that appears when you put parentheses
  def draw():
  
  # This defines the background color
    screen.fill((0,255,255))
    
  # This defines the color of the ball between quotes
    screen.draw.filled_rect(ball, "purple")
    
  # This defines the color of the bat between quotes
    screen.draw.filled_rect(bat, "black")

  # Def is a function that appears when you put parentheses
  def update():
  
  # It's a global variable
    global vx, vy
    
  # You add in x the velocity to the x ball position to move it
    ball.x += vx
    
  # You add in y the velocity to the y ball position to move it
    ball.y +=vy
    
  # If the ball surpass the width of the screen or exits on the left side
    if ball.right > WIDTH or ball.left < 0:
    
  # Changes the sign of the velocity and changes the direction too
        vx = -vx
        
  # If the ball collides with the bat or the ball exits up because it's less than 0
    if ball.colliderect(bat) or ball.top < 0:
    
  # Changes the sign of the velocity and changes the direction too
        vy = -vy
        
  # If the ball doesn't touch the bat the game ends
    if ball.bottom > HEIGHT:
        exit()
        
  # If in the keyboard I type the arrow in the right, the bat moves 10 pixels right
    if(keyboard.right):
        bat.x += 10
        
  # If in the keyboard I type the arrow in the left, the bat moves 10 pixels left 
    elif(keyboard.left):
        bat.x -= 10

This is a videotutotial showing how you create a basic game named pong:

Game.01

This is a pygame zero game where appears a rotating image:


  # Yoo is a sprite, that is, a moving image in a game
  # Yoo is the name of a class sprite (Ona is an example of the class Homo sapiens), this means create an object from a class
  # 'yoo' is a name of a image in the folder images
  yoo = Actor('yoo')
  
  # Topright means to locate the image in the top right corner
  yoo.topright = 0, 10

  # Screen width based on the width of the 'yoo'
  WIDTH = 500
  
  # Height based on the 'yoo' height + 20
  HEIGHT = yoo.height + 20

  # Def is a function which appears when you put parentheses
  def draw():
  
  # Put all the screen black
    screen.clear()
    
  # Draw the image in the screen
    yoo.draw()

  # Def is a function. This is a function and appears when you put parentheses
  def update():
  
  # Number of the velocity of the image
    yoo.left += 2
    
  # If the image left is bigger than the width
    if yoo.left > WIDTH:
    
  # The puntuation is zero
        yoo.right = 0

This is a videotutotial showing how you create a basic game named game.01:

Game.02

This is a pygame zero game where appears a rotating image and you have to click on it to count points:


  # 'hola' is a sprit and a name of a image in the folder images too
  hola = Actor('hola')
  
  # Topright means to locate the image in the top right corner
  hola.topright = 0, 10

  # Screen width based on the width of the image 'hola'
  WIDTH = 500
  
  # Height based on the 'hola' height + 20
  HEIGHT = hola.height + 20

  # Def is a function which and appears when you put parentheses
  def draw():
  
  # This puts all the screen in black
    screen.clear()
    
  # This draws the image in the screen
    hola.draw()

  # Def is a function which and appears when you put parentheses
  def update():
  
  # This is the speed of the passing image
    hola.left += 8
    
  # If the image left is bigger than the width, the puntuation of the image is zero
    if hola.left > WIDTH:
        hola.right = 0

  # This is a variable and starts with 
  score = 0

  def on_mouse_down(pos):
  
  # The computer start counting your points
    global score
    
  # If you touch the image you win one point
    if hola.collidepoint(pos):
        score += 1
        
  # If you don't touch the image you lose one point
    else:
        score -= 1
        
  # The computer write the sentence between quotes
        print("Nothing here")
        
  # The computer writes your final puntuation
    print(score)

This is a videotutotial showing how you create a basic game named game.02:

Game.03

This is a pygame zero game where appears a rotating image and when you click the image changes and appears sound:


  # 'Shaki' is a sprite, that is, a moving image in a game
  # 'Actor' is the name of a Class sprite (Ona is an example of he class Homo sapiens), this means create an object from a class
  # 'Shaki' is a name of a image in the folder images
  
  shaki = Actor('shaki')

  # topright means to locate the image in the top right corner
  shaki.topright = 0, 10

  # the pixel number of the screen
  WIDHT = 500
  
  # screen height based on shaki height plus 20
  HEIGHT = shaki.height + 20

  def draw():

  # put all the screen black
    screen.clear()
    shaki.draw()

  # Def is a function which appears when you put parentheses
  def update():

  # Used for the velocity of the image
    shaki.left += 5 
    
  # If the image left is bigger than the width the puntuation is zero points
    if shaki.left > WIDHT:
        shaki.right = 0

  # The variable score starts with zero points
  score = 0

  def on_mouse_down(pos):
  
  # The computer start counting your points
    global score
    
  # If you touch the image sound the 'hi' sound
    if shaki.collidepoint(pos):
        sounds.hi.play()
        
  # The image change to the image 'yeah'
        shaki.image = 'yeah'
        
  # You win one point
        score += 1
        
  # If you don't touch the image you lose 1 point
    else:
        score -= 1
        
  # The computer writes the sentence between quotes
        print("Nothing here, tap on the photo!")
        
  # The computer writes your final puntuation
    print(score)

This is a videotutotial showing how you create a basic game named game.03:

Game.05

This is a pygame zero game that joins one image with another, controlling the top one with the keyboard:


  import pgzrun
  import random
  WIDTH = 800 #numero de llargada que té la pantalla
  HEIGHT = 600 #numero d'alçada que té la pantalla
  alien_hurt = Actor('vater2', midbottom=(WIDTH // 2, HEIGHT))
  alien = Actor ('papel')
  alien.topright = 100,10
  def draw():
    screen.fill('black') #poses el nom del color que vols que apareixi al fons de la pantalla
    alien.draw()
    alien_hurt.draw()
  xpos = random.randint(0, 800) #entre aquests dos numeros apareixen numeros aleatoris que determinen la posició de la primera imatge que va "caient"
  def update():
    global xpos
    alien.y += 5
    if keyboard.left:
        alien.x -= 5
    if keyboard.right:
        alien.x += 5
    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 = 'papel'
    sounds.eep.play()
    clock.schedule_unique(set_alien_normal, 0.5)
  def set_alien_normal():
    alien.image = "vater2"

This is a videotutotial showing how you create a basic game named game.05: