{"id":217635,"date":"2018-09-15T22:59:13","date_gmt":"2018-09-15T22:59:13","guid":{"rendered":"http:\/\/localhost\/wordpress\/index.php\/2018\/09\/15\/gsp-125-week-4-ilab-simple-game-inheritance\/"},"modified":"2018-10-24T08:46:20","modified_gmt":"2018-10-24T08:46:20","slug":"gsp-125-week-4-ilab-simple-game-inheritance","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/gsp-125-week-4-ilab-simple-game-inheritance\/","title":{"rendered":"GSP 125 Week 4 iLab Simple Game inheritance"},"content":{"rendered":"<p>GSP 125 GSP\/125 GSP 125 \u00a0Week 4 iLab\t\u00a0\t\/\/\t\/\/\t\/\/\t\/\/\t\/\/\t\/\/\t\/\/ INSTRUCTIONS\t&#8212;&#8212;&#8212;&#8211;Compile this code. You should see a rectangular play field of periods, with\t3 Entity objects visible on it. The happy-face Entity moves with the &quot;wasd&quot;\tkeys, and the club Entity moves with the &quot;ijkl&quot; keys. If the happy-face\treaches the diamond Entity, the player wins. If the happy-face reaches the\tclub, the player loses.\tRead through this code! Try to understand it before starting the assignment.\tComment confusing lines with what you think code is doing, and experiment\twith existing code to test your understanding.\tOnce you feel comfortable with this code, accomplish each of the following,\tand make sure your code compiles and runs after each step is completed.\t1) Getting comfortable with the game code\ta) Implement initialization lists in Vector2, Entity, and Game (setting\tobject values after a &#8216;:&#8217;, between the constructor signature and body).\tHave initialization lists set initial values for each member variable.\tb) Add another Entity to the game that isn&#8217;t the same location as an\texisting Entity. Use a heart icon (ASCII code 3). It should display in\tthe game.\tc) Add logic that makes the club (PLAYER2) win the game if that player\treaches the heart Entity. You may want to make new constants, like\tGOAL2, and WIN2, to follow the existing code convention.\td) Make a new private function called &quot;void Game::handleUserInput()&quot;, move\tthe user input handling logic from Game::update() into this new\tfunction, and call Game::handleUserInput from Game::update.\te) Add whitespace to the handleUserInput logic, and comment each line with\twhat you understand it is doing. If you don&#8217;t understand what the code\tis doing, experiment with it until you do! Do things like printing\tvariables you are unsure about, and guess what output will look like.\tf) Implement the prototyped overloaded operators for Vector2. Once they\tare finished you should be able to use the alternate code for setting\tup PLAYER2 in Game::Game() in &quot;game.cpp&quot;.\t2) A &quot;BlinkEntity&quot; class\ta) Create 2 new files in your project: &quot;blinkentity.h&quot;, and\t&quot;blinkentity.cpp&quot;\tb) Make a BlinkEntity class that extends Entity. Declare the class in\t&quot;blinkentity.h&quot; and define it&#8217;s methods in &quot;blinkentity.cpp&quot;. Your\t&quot;blinkentity.h&quot; file should look something like:\t#pragma once\t#include &quot;entity.h&quot;\tclass BlinkEntity : public Entity {\t};\tc) Instead of using an Entity for the Entity marked GOAL1 in the Game\tconstructor, use a BlinkEntity. You will need to create a public\tBlinkEntity constructor.\td) Give BlinkEntity another member variable called &quot;alternateIcon&quot;. When\tBlinkEntity calls it&#8217;s update function, swap the values of &quot;icon&quot; and\t&quot;alternateIcon&quot;. You won&#8217;t notice a change during runtime until you add\tthe virtual modifier to Entity::update().\t3) A &quot;WanderingEntity&quot; class\ta) Create 2 new files in your project: &quot;wanderingentity.h&quot;, and\t&quot;wanderingentity.cpp&quot;\tb) Make a WanderingEntity class that extends Entity. Declare the class in\t&quot;wanderingentity.h&quot; and define it&#8217;s methods in &quot;wanderingentity.cpp&quot;. \/\/\tYour &quot;wanderingentity.h&quot; file should look something like:\t\/\/\t#pragma once\t\/\/\t\/\/\t#include &quot;entity.h&quot;\t\/\/\t\/\/\tclass WanderingEntity : public Entity {\t\/\/\t};\t\/\/ c) Instead of using an Entity for the Entity marked PLAYER2 in the Game\t\/\/\tconstructor, use a WanderingEntity. You will need to create a public\t\/\/\tWanderingEntity constructor.\t\/\/ d) Create a new update method for WanderingEntity. Declare it in\t\/\/\t&quot;wanderingentity.h&quot;, and define it in &quot;wanderingentity.cpp&quot;. In the\t\/\/\tWanderingEntity::update() method, set the &quot;howToMoveNext&quot; variable\t\/\/\tto a random number from 0 to 3. You can use &quot;rand() % 4&quot; to do this in\t\/\/\t&quot;wanderingentity.cpp&quot; if you #include &lt;cstdlib&gt; or &lt;stdlib.h&gt;. After\t\/\/\tsetting the &quot;howToMoveNext&quot; variable in update, call the parent class&#8217;s\t\/\/\tupdated with &quot;Entity::update()&quot;.\t\/\/ e) Add at least 2 more WanderingEntity objects in the Game. Add game logic\t\/\/\twill cause the player to lose if the player shares a location with any\t\/\/\tWanderingEntity object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GSP 125 GSP\/125 GSP 125 \u00a0Week 4 iLab \u00a0 \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ INSTRUCTIONS &#8212;&#8212;&#8212;&#8211;Compile this code. You should see a rectangular play field of periods, with 3 Entity objects visible on it. The happy-face Entity moves <a href=\"https:\/\/www.benedictsol.com\/blogs\/gsp-125-week-4-ilab-simple-game-inheritance\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217635","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=217635"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217635\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=217635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=217635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=217635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}