GSP 125 Week 4 iLab Simple Game inheritance

GSP 125 GSP/125 GSP 125  Week 4 iLab   // // // // // // // INSTRUCTIONS ———–Compile this code. You should see a rectangular play field of periods, with 3 Entity objects visible on it. The happy-face Entity moves with the "wasd" keys, and the club Entity moves with the "ijkl" keys. If the happy-face reaches the diamond Entity, the player wins. If the happy-face reaches the club, the player loses. Read through this code! Try to understand it before starting the assignment. Comment confusing lines with what you think code is doing, and experiment with existing code to test your understanding. Once you feel comfortable with this code, accomplish each of the following, and make sure your code compiles and runs after each step is completed. 1) Getting comfortable with the game code a) Implement initialization lists in Vector2, Entity, and Game (setting object values after a ‘:’, between the constructor signature and body). Have initialization lists set initial values for each member variable. b) Add another Entity to the game that isn’t the same location as an existing Entity. Use a heart icon (ASCII code 3). It should display in the game. c) Add logic that makes the club (PLAYER2) win the game if that player reaches the heart Entity. You may want to make new constants, like GOAL2, and WIN2, to follow the existing code convention. d) Make a new private function called "void Game::handleUserInput()", move the user input handling logic from Game::update() into this new function, and call Game::handleUserInput from Game::update. e) Add whitespace to the handleUserInput logic, and comment each line with what you understand it is doing. If you don’t understand what the code is doing, experiment with it until you do! Do things like printing variables you are unsure about, and guess what output will look like. f) Implement the prototyped overloaded operators for Vector2. Once they are finished you should be able to use the alternate code for setting up PLAYER2 in Game::Game() in "game.cpp". 2) A "BlinkEntity" class a) Create 2 new files in your project: "blinkentity.h", and "blinkentity.cpp" b) Make a BlinkEntity class that extends Entity. Declare the class in "blinkentity.h" and define it’s methods in "blinkentity.cpp". Your "blinkentity.h" file should look something like: #pragma once #include "entity.h" class BlinkEntity : public Entity { }; c) Instead of using an Entity for the Entity marked GOAL1 in the Game constructor, use a BlinkEntity. You will need to create a public BlinkEntity constructor. d) Give BlinkEntity another member variable called "alternateIcon". When BlinkEntity calls it’s update function, swap the values of "icon" and "alternateIcon". You won’t notice a change during runtime until you add the virtual modifier to Entity::update(). 3) A "WanderingEntity" class a) Create 2 new files in your project: "wanderingentity.h", and "wanderingentity.cpp" b) Make a WanderingEntity class that extends Entity. Declare the class in "wanderingentity.h" and define it’s methods in "wanderingentity.cpp". // Your "wanderingentity.h" file should look something like: // #pragma once // // #include "entity.h" // // class WanderingEntity : public Entity { // }; // c) Instead of using an Entity for the Entity marked PLAYER2 in the Game // constructor, use a WanderingEntity. You will need to create a public // WanderingEntity constructor. // d) Create a new update method for WanderingEntity. Declare it in // "wanderingentity.h", and define it in "wanderingentity.cpp". In the // WanderingEntity::update() method, set the "howToMoveNext" variable // to a random number from 0 to 3. You can use "rand() % 4" to do this in // "wanderingentity.cpp" if you #include <cstdlib> or <stdlib.h>. After // setting the "howToMoveNext" variable in update, call the parent class’s // updated with "Entity::update()". // e) Add at least 2 more WanderingEntity objects in the Game. Add game logic // will cause the player to lose if the player shares a location with any // WanderingEntity object.

Previous answers to this question


This is a preview of an assignment submitted on our website by a student. If you need help with this question or any assignment help, click on the order button below and get started. We guarantee authentic, quality, 100% plagiarism free work or your money back.

order uk best essays Get The Answer
Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *