Wed Nov 13 05:18:58 CET 2013

```Could you point out any errors in my code:

#This is a game where you have to escape a dragon.
# By Saad Imran

import random
import pygame

# Define questions and answers.
que1 = "4481 *2"
ans1 = "8962"
que2 = "457 * 21"
ans2 =  "9597"
que3 = "2345*23"
ans3 =  "53935"
que4 = "Who plays against the USA in golf's Walker Cup?"
ans4 = "britain"
que5 = "Which game is played in autumn using the fruit of the horse chestnut tree?"
ans5 = "conkers"
que6 = "From what country does Lego come?"
ans6 = "denmark"
que7 = "What term is used in cricket for the two men on the field who decide on whether batsmen are out, and signal for extras and boundaries?"
ans7 =  "umpire"
que8 = "What date was D-Day?"
ans8 = "06,06,1944"
que9 ="Who is called the 'Great One' in hockey history?"
ans9 = "wayne gretzky"

# intro
print("Welcome!")
print("")
name = input("What is your name? ")
print("")
print("You are in a cave and hear a dragon!",name)
print("")
print("Thinking you are doomed, you panic and run")
print("")

# Ask whether user wants to play or not
print("You run into a wizard who tells you that he will teleport you out of the cave if you solve his questions!")
print("")
game = input("Do you trust him?(y/n) ")
print("")

#if he doesn't game is ended
if game == "N" or game == "n":
print("The dragon catches you and you are doomed!")
gameloop = False
loop = False
# if he does, game starts

else:
gameLoop = True

while gameLoop ==True:

# Tell user how to write answers

print("Please use all lower case letters. date format is dd,mm,yyyy")
print("dragon is red, You are green!")

# The following code intialises a pygame window where user can track progress of self and dragon
# Needed to initialize pygame
pygame.init()

# define variable for user position
userX =75
userY =450

# define variable for dragon position.
dragonX = 0
dragonY = 450

# Define some Constants(colours and screen size)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)

SCREEN_WIDTH = 700
SCREEN_HEIGHT = 500

# Create a screen
size = [SCREEN_WIDTH,SCREEN_HEIGHT]
screen = pygame.display.set_mode(size)

pygame.display.set_caption("dragonEscape Game")

# Used to manage how fast the screen updates
clock = pygame.time.Clock()

#Loop until the user clicks the close button.
loop = True

# -------- Main Program Loop -----------
while loop == True:
# EVENT PROCESSING
for event in pygame.event.get():
if event.type == pygame.QUIT:
loop = False

#if user is caught

if userX <= dragonX:
print("The dragon ate you for dinner!")
loop = False
gameLoop = False

#if user wins
if userX >= 680:

print("You win!")
loop = False
gameLoop = False

# DRAW COMMANDS
screen.fill(WHITE)

pygame.draw.rect(screen, GREEN, [userX,userY,50,50])
pygame.draw.rect(screen, RED, [dragonX,dragonY,50,50])
pygame.draw.line(screen, BLACK, [680,0],[680,500],40)

#Code to generate random number

questionSelection = random.randrange(1,10)

# if statements that select question randomly based on random number generated and collects user answer
print("")
print("")
print("")
print("")
print("")
print("")
if questionSelection == 1:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 2:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 3:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 4:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 5:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 6:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX +=75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 7:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 75
else:
print("UH-OH!")
dragonX += 75

elif questionSelection == 8:
print(que1)
playerAnswer = input("What do you think the answer is?")
print("Correct!")
userX += 76
else:
print("UH-OH!")
dragonX += 75

else:
print(que9)
playerAnswer = input("What do you think the answer is?")
if playerAnswer == ans9:
print("Correct!")
userX += 25
else:
print("UH-OH!")
dragonX += 75

print("")
print("")
print("")
print("")
print("")

# Update Screen
pygame.display.flip()

# Set frames per second
clock.tick(20)
# -------- End of Main Program Loop --------

# Close the window and quit.
pygame.quit()

#game over, ending remarks.
print("Thanks for playing!")

```