Question: Complete the implementation of the draw_paddles function. This function displays a pair of game paddles. The function must draw two paddles, one on each side

Complete the implementation of the draw_paddles function. This function displays a pair of game paddles.

The function must draw two paddles, one on each side of the terminal, satisfying the following rules.

The paddles should be constructed using '&' symbols.

Both paddles should be 9 units (character sizes) in length.

The left paddle should be placed so that the center is offset 2 units above the middle of the screen, and 3 units in from the left-hand edge of the screen.

The center of the right paddle should be positioned 4 units below the middle of the screen, and located 2 units in from the right hand edge of the screen.

Notes:

Make no assumption about the size of the terminal window. Instead, use screen_width() and screen_height() to compute the size of the screen.

The left-most column of the screen corresponds to a horizontal offset of 0.

The right-most column of the screen is at screen_width() - 1. To position the right paddle, the offset should be subtracted from this value.

The formula to place the top of a paddle of length p at a position yt so that the paddle as a whole appears to be offset by d units above (or below) the center of a screen of height h is: yt = (h - p) / 2 d.

The bottom of the paddle will then be at position yb: yb = yt + p - 1.

Use integer variables and integer arithmetic for all calculations, so that results of division operations always truncate toward zero. Do not attempt to round.

The program should produce a display that resembles the image below. Your results will not be exactly the same as this view, because each user gets a unique set of parameters. However, it should give you an idea what to aim for.

Things to make sure you do:

Include the #include "cab202_graphics.h" directive and the draw_paddles() function in your submission.

Use ZDK functions to complete this activity, as listed above.

Call show_screen() once at the end of your function.

Use this test driver to implement and test your function prior to submission.

#include "cab202_graphics.h" void draw_paddles( void ) { // INSERT CODE HERE show_screen( ); } int main( void ) { setup_screen(); draw_paddles(); draw_string( 0, screen_height( ) - 1, "Press any key to finish..." ); wait_char(); cleanup_screen(); return 0; } 

Things to avoid:

Don't add any code to "Press any key to exit". The program runs without human intervention, so your submission will time out and you will lose an attempt.

If you include a main() function in your submission it will not compile on the server. Don't include main().

Make no direct use of ncurses or standard I/O functions such as printf(). The AMS is looking for a ZDK screen.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!