100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Summary CPSC 110 Racket Solution PSET 5

Rating
1.0
(1)
Sold
4
Pages
8
Grade
A+
Uploaded on
15-10-2021
Written in
2021/2022

Summary CPSC 110 Racket Solution PSET 5

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
October 15, 2021
Number of pages
8
Written in
2021/2022
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

1 ;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE.
2 ;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
3 ;; PARTNER.
4 (require 2htdp/universe)
5 (require 2htdp/image)
6 (require spd/tags)
7
8 (@assignment pset-05);Do not edit or remove this tag
9 (@cwl sumi1008) ;Replace ??? with your cwl,
10 ;; ;second ??? is replaced with partner cwl if you have one
11
12 ;; Bounce any number of balls around the screen.
13
14
15 ;;
16 ;; In this problem set you are given our official solution to problem
17 ;; set 4 (with a few additional things added) as a starting point.
18 ;; We have given you some more constants, a helper function called
19 ;; touch-paddle? which you may use, and a new data defintion called Game.
20 ;; You need to revise the program so that:
21 ;; - the game includes a paddle that moves back and forth across the
22 ;; bottom of the screen
23 ;; - the paddle is controlled by the left and right arrow keys
24 ;; - when a ball hits the paddle it disappears




m
25 ;; - as before the mouse can be used to add balls to the game




er as
26 ;;
27 ;; As stated above, we have given you a new data definition called Game.




co
28 ;; You MUST revise the program so that it uses Game as the world state.




eH w
29 ;; You MUST NOT change the Game data definition in anyway (though you are




o.
30 ;; allowed to add more Game constants).
31 ;;
rs e
32 ;; We suggest you work in three distinct phases, making sure your program
ou urc
33 ;; works correctly at the end of each phase before going on to the next.
34 ;; - change the program's world state to Game
35 ;; - provide left/right arrow key control over the paddle
36 ;; - make it so that when a ball hits the paddle it disappears
o

37 ;;
aC s


38 ;; In each of these phases you should follow the design recipes! Re-work
vi y re


39 ;; the domain analysis for changing and constant information, update the
40 ;; data definitions, revise the main function, and so on. Make sure that
41 ;; your tags are correct and that all your tests work correctly before you
42 ;; proceed to the next phase.
43 ;;
ed d




44 ;; NOTE: Your on-tick function MUST be designed as a composition of two other
ar stu




45 ;; functions called game-with-next-balls and game-with-caught-balls.
46 ;;
47 ;; Note that we are giving you significant help in the starter file.
48 ;; You absolutely MUST USE OUR STARTER AS THE BASIS FOR YOUR WORK.
is




49 ;;
50 ;; We recommend that you begin by printing this file and planning out what
Th




51 ;; needs to change, what needs to be added, and what will be unchanged.
52 ;;
53 (@problem 1)
54 (@htdw ListOfBall)
55
sh




56 ;; Constants:
57 (define WIDTH 605)
58 (define HEIGHT 535)
59
60 (define PADDLE-WIDTH 60)
61 (define PADDLE-THICKNESS 10)
62 (define PADDLE (rectangle PADDLE-WIDTH PADDLE-THICKNESS "solid" "white"))
63 (define PADDLE-CTR-Y (- HEIGHT 40))
64 (define PADDLE-MOVE-PER-KEY 10)
65
66This(define BALL-RADIUS
study source was 10)
downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:26:46 GMT -05:00
67

https://www.coursehero.com/file/81743757/Pset5pdf/

, 68 (define TOP BALL-RADIUS)
69 (define BOT (- HEIGHT BALL-RADIUS 1))
70 (define LEF BALL-RADIUS)
71 (define RIG (- WIDTH BALL-RADIUS 1))
72
73 (define BALL (circle BALL-RADIUS "solid" "white"))
74
75 (define MTS (rectangle WIDTH HEIGHT "solid" "green"))
76
77
78 ;; ===========================================================================
79 ;; ===========================================================================
80 ;; Data definitions:
81
82 (@htdd Ball)
83 (define-struct ball (x y dx dy))
84 ;; Ball is (make-ball Number Number Number Number)
85 ;; interp. (make-ball x y dx dy) is ball
86 ;; - position x, y in screen coordinates
87 ;; - velocity dx, dy in pixels/tick
88 ;; CONSTRAINT: x is in [LEF, RIG]; y is in [TOP, BOT]
89 (define B1 (make-ball (/ WIDTH 2) (/ HEIGHT 2) 4 -3))
90
91 (@dd-template-rules compound)




m
92




er as
93 (define (fn-for-ball b)
94 (... (ball-x b)




co
95 (ball-y b)




eH w
96 (ball-dx b)




o.
97 (ball-dy b)))
98
99 (@htdd ListOfBall) rs e
ou urc
100 ;; ListOfBall is one of:
101 ;; - empty
102 ;; - (cons Ball ListOfBall)
103 ;; interp. a list of balls
o

104 (define LOB1 empty)
aC s


105 (define LOB2 (cons B1 empty))
vi y re


106
107 (@dd-template-rules one-of
108 atomic-distinct
109 compound
110 ref
ed d




111 self-ref)
ar stu




112
113 (define (fn-for-lob lob)
114 (cond [(empty? lob) (...)]
115 [else
is




116 (... (fn-for-ball (first lob))
117 (fn-for-lob (rest lob)))]))
Th




118
119
120 (@htdd Game)
121 (define-struct game (balls paddle))
122 ;; Game is (make-game ListOfBall Number)
sh




123 ;; interp. the current state of a game, with all the balls in play,
124 ;; as well as the x-position of the paddle in screen coordinates
125 (define G0 (make-game empty (/ WIDTH 2)))
126 (define G1 (make-game (cons B1 empty) (/ WIDTH 2)))
127
128 (@dd-template-rules compound ref)
129
130 (define (fn-for-game g)
131 (... (fn-for-lob (game-balls g))
132 (game-paddle g)))
133This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:26:46 GMT -05:00
134

https://www.coursehero.com/file/81743757/Pset5pdf/
$17.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Reviews from verified buyers

Showing all reviews
2 year ago

1.0

1 reviews

5
0
4
0
3
0
2
0
1
1
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
StuviaGuides West Virgina University
Follow You need to be logged in order to follow users or courses
Sold
15169
Member since
6 year
Number of followers
8354
Documents
5312
Last sold
1 day ago
Accounting, Finance, Statistics, Computer Science, Nursing, Chemistry, Biology & More — A+ Test Banks, Study Guides & Solutions

As a Top 1st Seller on Stuvia and a nursing professional, my mission is to be your light in the dark during nursing school and beyond. I know how stressful exams and assignments can be, which is why I’ve created clear, reliable, and well-structured resources to help you succeed. I offer test banks, study guides, and solution manuals for all subjects — including specialized test banks and solution manuals for business books. My materials have already supported countless students in achieving higher grades, and I want them to be the guide that makes your academic journey easier too. I’m passionate, approachable, and always focused on quality — because I believe every student deserves the chance to excel.

Read more Read less
4.3

2134 reviews

5
1471
4
281
3
168
2
69
1
145

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions