General Programming Help
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Remember me

Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Add This Thread To:   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
Unread Dev Articles Community Forums Sponsor:
Old February 16th, 2014, 07:28 PM
Oosimple Oosimple is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
Join Date: Feb 2014
Posts: 1 Oosimple User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 31 sec
Reputation Power: 0

Does anybody know how to write the code for the following assignment?

1. []. This assignment combines pygame and classes
a. Create the following classes
i. class Circle(location, size, color)
ii. class Rect(location, length, width, color)
iii. class Picture(location, filename)

b. I should be able to create instances of your classes like this
i. my_circle = Circle((100,100), 23, RED)
ii. my_rect = Rect((100,100), 150,100, RED)
iii. my_pic = Picture((100,100),”picure.png”)

c. I should be able to have those instances draw themselves using the commands below:
i. my_circle.draw()
ii. my_rect.draw()
iii. my_pic.draw()

d. Doing so should have the following effect, i.e., it all occurs within each class’s draw():
i. Pygame gets initialized
ii. The specified object should be created
iii. Pygame should show the object in a game loop
iv. When the user closes the window or presses the ‘q’ key, the draw loop should be
exited and pygame should be shut down.

e. For each class, I should be able to query any property of instances like this:
i. print my_circle.color [result might be (255,0,0)]
ii. print my_circle.radius [result might be 23]
iii. print my_circle.position [result might be (100,100)]

2. [ ]. Specify which key events get monitored.
a. Tweak the code in your previous code file so that each class takes an additional parameter,
a list (regular list, not a tuple) of allowable keys, like this:
i. My_circle =
Circle((100,100), 23, RED, [pygame.K_y,pygame.K_n])

b. The draw() method keeps looping until any one of these keys are pressed, but only those
keys specified when the class instance was created.

3. [ ]. Start with code from your first program Write a
new class just like the others but instead it’s going to display text on the pygame surface (see book
or for help). Should work like this:

a. my_text = Text((100,100), “What is your name?”, Green)

b. …and then I should be able to call my_text.draw()

c. In the game loop, the prompt (in this case “What is your name?”) should be printed to the
surface so the user can see it.

d. Then, like the other classes draw() method, wait for a response in the game loop, but:
i. The only key that should shut down pygame is the ENTER key, i.e., use
ii. Every other key the user presses should be appended to a string so that it builds up
over each keypress.
iii. When the user does finally press the ENTER key, shut down pygame as before, but
also print (the normal print function) the string.
iv. We’re basically making a graphical version of raw_input() except it draws the
prompt using pygame doesn’t return the response, just prints it.

Reply With Quote

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Pygame

Developer Shed Advertisers and Affiliates

Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap