联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-04-15 10:35

Due Thursday by 11:59pm Points 10 Submitting a file upload

Available Apr 8 at 10pm - Apr 19 at 11:59pm 11 days

Submit Assignment (https://canvas.wisc.edu/courses/139003/assignments/530342?

module_item_id=1765191#)

Program 4 - Flash Cards

In this assignment, you will write a simple graphical program for displaying images when keys are pressed.

This program is inspired by the idea of flash cards, but the implementation will be a bit more abstract.

Learning Goals: Students will...

practice installing custom libraries and extensions

set up a graphical interface through the SDL library, (the Simple Directmedia Layer library)

create a program using the Event Loop program style

Program Requirements

For this assignment, you will need to download the SDL library (https://www.libsdl.org/download-2.0.php)

and its "image" extension (https://www.libsdl.org/projects/SDL_image/) . I recommend following LazyFoo's

Lesson 1 (http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php) for a step-by-step guide on how to set up

your workspace to use SDL. If you run into difficulties getting SDL set up properly, seek help early. I

anticipate that for many students, this setup step will take 50% of your time spent on this

assignment! For convenience, and because you can't install things on lab machines, I expect each of you

will want to work on your own computer for this program. Please let me know if this is a difficulty--working on

your own computer is not required for this course, so it is no trouble to make accommodations as needed.

You will also need to create one simple image file and download several more of your choice.

Openclipart.org (https://openclipart.org/) is a good source of usable images. GIMP (linux/mac) or MSPaint

(Windows) are fine for creating the original image.

Source file list:

p4.cpp <--The only source file for this program.

Step 1. Initialize SDL and set up a window

P4 2019/4/12 下午9(25

file:///Users/liujinmeng9861/Desktop/P4.htm 第 2 ?(共 4 ?)

if (SDL_Init(SDL_INIT_VIDEO)<0) {

//SDL failed to initialize. Print something descriptive.

}

Use the SDL_Init method outlined above to launch SDL. Whenever launching a graphical component,

explicitly check for failure. Most of these components do not break in easily predictable ways such as

crashing your program. Once you have successfully launched SDL, create a window:

SDL_Window* myWindow = NULL;

myWindow = SDL_CreateWindow( [name], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, [screen width],

[screen height], SDL_WINDOW_SHOWN );

Finally, get the surface attached to the window:

SDL_Surface* windowSurface = SDL_GetWindowSurface( myWindow );

PAUSE. If you use SDL_Delay(milliseconds) you should now be able to run your program and see a blank

white screen that hangs out for your delay period and then vanishes. The screen may hide behind your IDE,

so if your program seems to be running but you can't see the window, try extending the pause duration and

minimizing all other windows.

Also don't forget to use SDL_FreeSurface(), SDL_DestroyWindow(), and SDL_Quit() as appropriate to clean

up when you're done!

Step 2. Display an original image

Create an original background image for your program. It must include your name somewhere on the

image. It may include anything else you feel is relevant. Suggestions include:

A colorful border

A list of keystrokes your program will recognize

Tiny previews of the "cards" that your program will be able to display

Create a new SDL_Surface* and use the IMG_Load() method to load your original image file into it. PNG

format is recommended, but any image format will likely work. To display your image in your window, use the

following two method calls:

SDL_BlitSurface( surfaceWithData, NULL, windowSurface, NULL );

SDL_UpdateWindowSurface( myWindow );

Step 3. Create an event loop

Recall that an event loop has the following structure:

P4 2019/4/12 下午9(25

file:///Users/liujinmeng9861/Desktop/P4.htm 第 3 ?(共 4 ?)

p4 rubric

SDL_Event eventObject;

while (!done) {

while (SDL_PollEvent( &eventObject ) ) {

//TODO Detect the type of event (keypress) and react to the keypress

}

SDL_BlitSurface( correctSurface, NULL, windowSurface, NULL );

SDL_UpdateWindowSurface( myWindow );

}

Update your program to use an event loop rather than using SDL_Delay. Exit can be detected if ever

eventObject.type == SDL_QUIT

All other recognized events should be of type SDL_KEYDOWN. Precisely which keys to recognize is up to

you, and MUST be clearly documented both at the top of your program and inline in the appropriate places.

You must include a recognized key which brings back your original image. You must also include 2 other

keys that, when pressed, cause one of your chosen additional images to be shown. You may choose which

2 additional images to use, but obviously do not use any inappropriate content, nor any content which you

don't have the legal right to distribute (since you will be "distributing" the images to me and Michael). All of

your images should live in the same directory as p4.cpp.

Submission

Create a .zip file containing your p4.cpp and your three image files, plus an additional image file that is a

screenshot of you running your program. Since we may not be able to run your program properly

ourselves due to platform-specific code, we need this screenshot as evidence that you ran your program

successfully. Since the program consists at any given time of static images, the best thing to do is include is

some print statements within your program indicating when steps succeed or fail, and take a screenshot that

includes both your window and your console output to prove that your run was successful. You may submit

as many times as you like - only the last submission received will be graded. This program is due Thursday,

April 18 at 11:59pm. Late work will not be accepted.

P4 2019/4/12 下午9(25

file:///Users/liujinmeng9861/Desktop/P4.htm 第 4 ?(共 4 ?)

Total Points: 10.0

Criteria Ratings Pts

6.0 pts

2.0 pts

1.0 pts

1.0 pts

Correct program behavior

Does your program compile and run as expected? (We will compile and run

your program if feasible, and otherwise compare your run screenshot to your

code.)

6.0 to >0.0 pts

Full Marks

0.0 pts

No

Marks

Code organization

Did you follow good practices, creating functions where appropriate to avoid

code duplication and cleaning up your graphics objects?

2.0 pts

Full Marks

0.0 pts

No Marks

Code style

Did you follow the Stanford Style Guide?

1.0 pts

Full Marks

0.0 pts

No Marks

Code documentation

Did you document your code with helpful comments? (This includes a "use"

guide in comments at the top of your program.)

1.0 pts

Full Marks

0.0 pts

No Marks


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp