GSP125 Lab 1 in C++ – Oop Game – Instant Delivery – Perfect Solution
Start Visual Studio. From the menu, click File –> New Project… (or press Ctrl + Shift + N, or click the New Project icon on the toolbar) to create a new project in Visual Studio.
On the New Project dialog, open the Visual C++ group by clicking the (triangle arrow) icon if the group is not already opened. If you do not see the Visual C++ group, you may need to open the Other Languages group and then the Visual C++ group. If you cannot find C++, seek help!
Click Win32 in the Project Types section on the left side of the dialog and Win32 ConsoleApplication in the Templates section on the right side. Then change the name of the project in the bottom section to GSP125_YourLastName_Lab1, where you replace YourLastName with your actual last name.
Click Browse on the bottom-right corner and click Desktop on the list to the left. Click the Make New Folder button (or right click and select New –> Folder, or press Ctrl + Shift + N). Type GSP125 Projects and then press the Enter key to save the name. With the GSP125 Projects folder selected, click the OK button. Look at the Location and confirm that it is pointing to the GSP125 Projects folder. If not, click the Browse button and find (or create) that folder.
Once you are pointing to the GSP125 Projects folder, click the OK button to start creating the new project. In the first screen of the Win32 Application Wizard, simply click the Next> button. On the second screen, confirm that the Console Application radio button is selected. Then put a check mark in the Empty Project checkbox. Click the Finish button to complete the wizard.
Find the Solution Explorer window. If you do not see the Solution Explorer window, click View –> Solution Explorer on the menu. Right click on the Source Files filter (it looks like a folder) in the Solution Explorer. If you do not see Source Files, click the (triangle arrow) icon on the project name to open the filters. Then right click on the Source Files filter. Select Add –> New Item on the shortcut menu. On the Add New Item dialog, select Code in the Categories section (left side) and C++ File in the Templates section (right side). In the Name field at the bottom, type GSP125_YourLastName_Lab1 (using your last name). Then click the Add button.
The GSP125_YourLastName_Lab1.cpp was created and it should be open now, ready for you to add code. If you look in the Solution Explorer, you will see the new file under the Source Files folder. In addition, if you look at the tab at the top of the open file, you will see the file name on the tab. It is time to add some code!
STEP 2: Test Your Compiler With Simple Code
Type a header at the top of your main file. Use \* and *\ to create a block comment. The header should include your name, the course number, the date, and a brief description of the project.
We need to create a main method. The code in the main method is executed line by line as you learned in your previous C++ programming course. Add your main method and then return your environment variable.
/*
YOURNAME, GSP125, DATE
Lab1
*/
#include
using namespace std;
#include
int main()
{
cout << "Press any key!" << endl;
_getch();
return 0;
}
The int at the beginning of the first line is the return type. The main method will return an integer (whole number). The parenthesis ()must be present because main is a method. You can also receive arguments in the parenthesis when you work with methods, as you learned in your previous programming course.
The main method is optionally able to receive command line arguments. The standard (optional) arguments to receive command-line input are (int argc, char * argv[]).
cout (included by iostream) prints the message to the screen, and _getch() (included by conio.h) waits for a single key press in the Win32 console. The return 0 line supplies a return error code to the application that called this one. 0 is universal for "good," or "no error." If your application intentionally crashes, you should return -1, which is universal for "error."
Run your application by clicking Debug --> Start Debugging (or pressing the green arrow on the toolbar, or pressing the F5 key). A window should open that states “Press any key!” and closes after you press a key. If you ran the application with Debug –> Start Without Debugging (or press Ctrl + F5), you should see the “Press any key!” message, and then another “Press any key to continue . . .” message. The second message is the automatic pause command that the Win32 console executes after running in release mode.
This is the starting point for all of your applications for this course, as well as further examples in the lectures. We will learn the programming concepts in this course using console applications. When you get to your future 3D graphics course in C++, you will apply these concepts in a 3D graphical environment as you build your games.
STEP 3: Create Your Application
Review the Week 1 Lecture material; it will be helpful in explaining concepts required to finish your assignment. Once you have reviewed the reading, complete this program:
Download simplegame_OOP.zip (Links to an external site.)Links to an external site.. Inside this zip file, you will find main.cpp. Copy the contents of main.cpp into your GSP125_YourLastName_Lab1.cpp file. You are welcome and encouraged to type out the entire file by hand, which will help you understand the code better. But the process of copying can also be accomplished with a few simple keystrokes: In main.cpp, press Ctrl + A (to select all), and Ctrl + C (to copy), then go to GSP125_YourLastName_Lab1.cpp and press Ctrl + V (to paste).
Follow the instructions located toward the bottom of the main.cpp file.
Programming Tips
• You can save your program by clicking File –> Save All (or by clicking the Save All button on the toolbar, or Ctrl + Shift + S).
• Be careful with the Save As option, which will allow you to make copies of your code. A common mistake for new programmers is to Save As outside of the project folder and continue editing the file, which is now not saved as a file inside the project!
• When compiling, you will likely see error messages. This is fine! The compiler does not hate you; it is a tool that is trying to help you diagnose what is wrong! Try to fix your code and compile the application again.
• If you do not see the Errors List at all, click View –> Other Windows –> Errors List. Click on the errors button to see the errors. Once you make corrections to your code, go ahead and click Debug –> Start Debugging again to find more errors or to see your output.
• Compile often as you write your code! It will help you find syntax errors early and it will conveniently prompt you to save as well!
• Make guesses about how you think your code will run as it compiles, or what errors might pop up when it compiles, and compare the results to your predictions!
• It is important that you become comfortable with error messages. Extremely skilled programmers are in the habit of being excitedby errors, sometimes joyfully so, intrigued by an opportunity to learn something new about their code, about how the compiler works, or about how they can improve themselves as programmers.
• If you encounter errors that seem too frustrating to deal with, look for help! Do searches for your error using your favorite search engine; ask friends, classmates, and your professor for advice over e-mail or instant messaging; or even ask questions in the discussions!
STEP 4: Capture Output
Capture a screen print of your final working program’s output: Hold down the Alt key while you press the PrtScr (Print Screen) buttonon your keyboard. If you are using a notebook computer, you may need to hold down the Fn (function) key and the Alt key while you press and release the PrtScr button.
Open MS Paint. To do this, press the Start menu, type mspaint into the search bar, and press Enter. Or press Windows + R (the Windows key is between your Ctrl and Alt buttons) to bring up the Run command, and in the input field, type mspaint and press Enter.
Inside MS Paint, paste your screenshot with Ctrl + V. If the image does not appear, use Alt + PrtScr again, and paste in MS Paint again.
Save the image as GSP125_YourLastName_Lab1.png. Be sure that the course number, your last name, and the Lab number are part of the file name.
STEP 5: Submit Your Work
Create a folder called GSP125_YourLastName_Lab1.
Put copies of the following files into this new folder.
• GSP125_YourLastName_Lab1.png (contains your screenshot)
• GSP125_YourLastName_Lab1.cpp (main source file, located in the project folder)
Right click on the folder and select Send To –> Compressed (zipped) Folder. You can also use other tools to compress the files into a single zip folder (e.g., 7-Zip).
If you choose to submit your entire project, do not include temporary files or temporary folders. Close Visual Studio and delete these files before adding your project to a zip file:
• Temporary folders are named Debug or ipch; delete them (after closing Visual Studio).
• Temporary files end with the suffixes .sdf, .suo, .ncb, and .opensdf; delete them (after closing Visual Studio). If you cannot see file name extensions in the file explorer, then do the following.
o In Windows 7 (and Windows XP): Press Alt, select Tools –> Folder Options… –> View –> and uncheck Hide extensions for known file types,then click OK.
o In Windows 8: Select View and check File name extensions.
• Not including temporary files reduces the size of your submission 100 times.
Submit your assignment.
// INSTRUCTIONS
// ————
// Compile this code. You should see a happy-face character on a field of
// periods. You can move the character with the ‘w’, ‘a’, ‘s’, and ‘d’ keys.
//
// 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) Object Oriented Refactoring
// a) Write a class called Entity to store two public integers named x and y,
// and a char named icon (the player data).
// b) Remove x, y, and icon (the player data) from main(), create an instance
// of the Entity class (named whatever you like) in main(), and use its
// members as replacements for the x, y, and icon variables that were
// removed.
// c) Write a parameterized constructor for the Entity class that sets x, y,
// and icon, and use it when creating the instance.
// d) Make x, y, and icon private variables of Entity, and create Accessor
// and Mutator (or Getter and Setter) functions to use them in main().
// (hint: “player.x++” could be “player.setX(player.getX()+1);” )
// e) Write a struct called Vector2, which has two int variables, x and y.
// f) Write a default constructor for Vector2, which sets x and y to 0.
// g) Write a parameterized constructor for Vector2, which sets x and y.
// h) Remove x, and y from Entity, add an instance of the Vector2 structure
// named “pos” to the Entity class, and use pos’s members as replacements
// for the x, and y variables that were removed.
// i) Remove height and width (in the game data) from main(), create an
// instance of the Vector2 structure named “size”, and use size’s x member
// as a replacement for width, and size’s y member as a replacement for
// height.
// j) Write a method in Vector2 with the signature
// “bool is(int a_x, int a_y)”. “is” should return true if a_x is equal to
// that instance’s x, and a_y is equal that instance’s y.
// k) Instantiate a new object of class Vector2 called “winPosition”, and set
// it’s x, y value to size.x/2, size.y/2.
// 2) Add Game Logic
// a) Add code to the while-loop so that when the player reaches
// “winPosition”, which should be determined by using the “is” method, the
// “state” variable should be set to WIN, ending the game.
// b) Add code to the while-loop so that the state variable is set to to LOST
// if the player leaves the play field (ending the game).
// 3) Using enums
// a) Create an enum called “GameState” with the possible values “RUNNING”,
// “WIN”, “LOST”, and “USER_QUIT”.
// b) Replace the state variable with an isntance of the GameState enum.
// Stuck? Don’t forget to do your reading! If you’d like more educational
// resources, these websites may also be useful:
// http://en.cppreference.com/book/intro/classes
// http://www.cplusplus.com/doc/tutorial/classes/
// http://www.cplusplus.com/doc/tutorial/structures/
// http://en.wikibooks.org/wiki/C++_Programming/Classes
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.