Commit 5fa009b7 by source_reader

initial commit

parents
import pygame
# Animal Class (models a farm animal)
#
# Attributes: x (top left x coordinate, must be provided)
# y (top left y coordinate, must be provided)
# color (an RGB array eg [255,0,0])
# FOR THE BONUS: replace color with sprite object
# vaccinated (set to False)
# Methods: vaccinate() => sets vaccinated to True
# draw(surface) => draws the animal onto the surface as a 120x110 rectangle
# at its (x,y) location and color
class Animal:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color
self.vaccinated = False
def vaccinate(self):
self.vaccinated = True
def draw(self, surface):
pygame.draw.rect(surface, self.color,
pygame.Rect(self.x, self.y, 120, 110))
import pygame
from pygame.locals import *
import sys
import animal
from random import randint
def main():
background = pygame.image.load('farmyard.bmp')
screen = pygame.display.set_mode((1324, 847))
screen.blit(background, (0, 0))
# ---------- BEGIN YOUR CODE ----------
# 1.) Ask the user for their full name then display a greeting
#
# Example: $> Enter your full name: John Willy Smith
# Hello there John Willy Smith, welcome to your farm
# 2.) Ask the user for the number of ducks and pigs on their farm.
# The number should be between 1 and 10. If the number is outside of this
# range tell them it is invalid and prompt for a new input
#
# Example: $> How many pigs? 4
# Ok, 4 pigs.
# How many ducks? 100
# You cannot have that many ducks.
# How many ducks? 5
# Ok, 5 ducks.
num_pigs = 0
num_ducks = 0
# 3.) See the animal class before starting this problem (animal.py)
# Create a list of pigs and a list of ducks (both are Animals) with random
# locations. Pigs must be in the pig pen and ducks must be in the duck pond.
# The duck pond rectangle is <x=715, y=175, height=500, width=550>
# The pig pen rectangle is <x=100, y=175, height=500, width=550>
# Pigs should be pink and ducks should be green- pick an appropriate RGB value
pigs = []
ducks = []
# 4.) Vaccinate all your animals by calling the vaccinate method
# 5.) Draw the animals on the farm
# 6.) BONUS: Replace the rectangles with the pig and duck sprites in farm_sprites.bmp
# Magenta pixels (255,0,255) should be transparent
# ---------- END YOUR CODE ----------
pygame.display.update()
# wait until the user closes the game
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
main()
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment