The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 364 Weeks Ago, 2 Days Ago |
| Questions Answered: | 1850 |
| Tutorials Posted: | 1850 |
Graduate in Biology and Nutrition, MBA Finance
Florida State University
Aug-2000 - Jul-2007
Ass. Relationship Manager
Penn-Florida
Mar-2009 - Feb-2016
I tried getting help from a tutor and they gave me code that would not compile correctly. I have attached the instructions to the lab and what I currently have. I would ask to add comments if possible on what you did. This assignment is due tonight.
The specified errors were:
1>d:visual studiogsp125 projectsgsp125_douglas_lab1gsp125_douglas_lab1gsp125_douglas_lab1entity.h(48): error C4716: 'Entity::getY': must return a value
1>d:visual studiogsp125 projectsgsp125_douglas_lab1gsp125_douglas_lab1gsp125_douglas_lab1entity.h(56): error C4716: 'Entity::getIcon': must return a value
1>d:visual studiogsp125 projectsgsp125_douglas_lab1gsp125_douglas_lab1gsp125_douglas_lab1entity.h(40): error C4716: 'Entity::getX': must return a value
Â
struct Vector2 {
int x;
int y;
Â
Vector2() :
x(0), y(0) {
Â
}
Â
Vector2(int x, int y) {
this->x = x;
this->y = y;
}
Â
bool is(int a_x, int a_y) {
if (a_x == x && a_y == y) {
return true;
}
Â
return false;
}
Â
};
Â
class Entity {
Â
public:
Entity(int x, int y, char i) {
pos.x = x;
pos.y = y;
this->icon = i;
}
Â
void setX(int x) {
this->pos.x = x;
}
Â
int getX() {
this->pos.x;
}
Â
void setY(int y) {
this->pos.y = y;
}
Â
int getY() {
this->pos.y;
}
Â
void setIcon(char i) {
this->icon = i;
}
Â
char getIcon() {
this->icon;
}
Â
private:
Vector2 pos;
char icon;
Â
Â
};
// lab1: simplegame_OOP
// <insert your name here>
// read main.cpp, and follow the instructions at the bottom of main.cpp
Â
#include <iostream> // std::cout
#include "Entity.h"
Â
using namespace std;
Â
Â
Â
#include <windows.h> // SetConsoleCursorPosition(HANDLE,COORD)
#include <conio.h> // _getch()
Â
Â
enum GameState{
RUNNING,WIN,LOST,USER_QUIT
};
Â
Â
Â
/**
 * moves the console cursor to the given x/y coordinate
 * @param x
 * @param y
 */
void moveCursor(int x, int y)
{
COORD c = {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
Â
int main()
{
// player data
Entity e(3,4,1);
Â
Â
Â
// game data
GameState state = RUNNING;
int input;
Vector2 size(20,15);
Vector2 winPosition(size.x/2, size.y/2);
Â
do
{
// draw the game world
moveCursor(0,0);
for(int row = 0; row < size.x; row++)
{
for(int col = 0; col < size.y; col++)
{
cout << '.';
}
cout << '\n';
}
// draw the player
moveCursor(e.getX(), e.getY());
cout << e.getIcon();
Â
// get input from the user (wait for one key press)
input = _getch();
Â
// process input from the user
switch(input)
{
case 'w':e.setY(e.getY() - 1);break;// move up
case 'a':e.setX(e.getX()-1);break;// move left
case 's':e.setY(e.getY()+1);break;// move down
case 'd':e.setX(e.getX()+1);break;// move right
case 27:state = USER_QUIT;break;// quit
}
// show the game state message
moveCursor(0, size.y+1);
switch(state)
{
case WIN:cout << "You WON! Congratulations!\n";break;
case LOST:cout << "You lost...\n";break;
}
Â
if(winPosition.is(e.getX(),e.getY()))
{
state = WIN;
}else
{
state = LOST;
}
}
while(state == RUNNING);
Â
// user must press ESCAPE before closing the program
cout << "press ESCAPE to quit\n";
while(_getch() != 27);
return 0;
}
Â
Attachments:Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I