Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Figure 1 depicts a screen shot from a game called Dodge. Dodge consists of: A single player who can only move left and right

Figure 1 depicts a screen shot from a game called Dodge. Dodge consists of: - A single player who can only move left and riListing 17: Screen class I/ The KeyBoardinputHandler class recognises the following keys enum Key {None, Space, Escape, Left   

Figure 1 depicts a screen shot from a game called "Dodge". Dodge consists of: A single player who can only move left and right and is controlled via the keyboard. Raindrops which appear in random positions in the top quarter of the screen and fall vertically downwards. The number of raindrops on the screen at any one time remains constant whenever a raindrop disappears off the bottom of the screen, a new one appears at the top of the screen. The objective of the game is to move the player so that he or she does not get wet, that is, the player must dodge the raindrops. If a raindrop touches the player then the game is over. Raindrops fall vertically Player moves horizontally left and right Figure 1: Dodge screenshot Provide the complete source code for the Dodge game. Your solution must be object-oriented. Certain classes have already been implemented and you should use these, where appropriate, in your solution. The interfaces for these classes are given in Listings 17 and 18 in Appendix 2. You may use very simple graphics for the game elements and you can assume that the player will not move beyond the borders of the screen. You are not required to separate the display logic from the game logic. Appendix 2: Existing Dodge Game Classes // This structure is used in the Screen class interface (see drawRectangle) struct Rectangle ( }; class Screen ( unsigned int x.pos; // top-left x-coordinate // top-left y-coordinate unsigned int y_pos; unsigned int width; // rectangle width unsigned int height; // rectangle height public: }; // Screen constructor // A "ScreenInitialisationError exception is thrown // if the Screen cannot be initialised // For the default screen, the top-left co-ordinate is (0,0) and // the bottom-right co-ordinate is (640,480) Screen(int width 640, int height=480); // Screen destructor, frees up all of Screen's resources -Screen(); }; // Returns the Screen width int width() const; // Returns the Screen height int height() const; // Updates the Screen with all the changes that have occurred since // the previous display call void display(); // Clears the Screen, by drawing over it in black void clear(); // Sets the foreground colour (the background colour is black) // R represents the red component (0 = minimum, 255= maximum) // G represent the green component (8 minimum, 255= maximum) // B represents the blue component (8 void setDrawingColour (int R, int G, int B); minimum, 255= maximum) // Draws a rectangle on the screen in the foreground colour void drawRectangle (Rectangle rect); // Draws a circle on the screen in the foreground colour void drawCircle(unsigned int centre.x, unsigned int centre_y, unsigned int radius); // The KeyBoardInputHandler class recognises the following keys enum Key (None, Space, Escape, LeftArrow, RightArrow, UpArrow, DownArrow); class KeyBoardInputHandler { Listing 17: Screen class public: // Returns the most recent key that was pressed // Only the keys specified in the enumeration type above are recognised // If no key has been pressed "None" is returned Key getKeyPressed() const; Listing 18: KeyboardInputHandler class.

Step by Step Solution

3.40 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Physics

Authors: Alan Giambattista, Betty Richardson, Robert Richardson

2nd edition

77339681, 978-0077339685

More Books

Students also viewed these Accounting questions

Question

Was the decision maker aware that he or she was acting unfairly?

Answered: 1 week ago

Question

What are some basic guidelines for designing brochures? Web pages?

Answered: 1 week ago

Question

Write the Boolean equation in sum - of - products form for each of

Answered: 1 week ago