MY .H FILE
using namespace std;
#include
#define FORWARD 0
#define BACKWARD -1
#define RIGHT 2
#define LEFT -2
#define t true
class Player
{
public:
//x pos
float x;
//y pos
float y;
//id of player
string id;
};
string d;
string mv;
// Making a new player
Player p;
int direction;
void turnForward()
{
direction = FORWARD;
}
void turnBackward()
{
direction = BACKWARD;
}
void turnRight()
{
direction = RIGHT;
}
void turnLeft()
{
direction = LEFT;
}
int spaces;
void move(int spaces, int direction, float x, float y, Player p)
{
x = p.x;
y = p.y;
if(direction == LEFT)
{
x = x - spaces;
cout << x << ","<< y << endl;
}
p.x = x;
if(direction == RIGHT)
{
x = x + spaces;
cout << x << ","<< y << endl;
}
p.x = x;
if(direction == FORWARD)
{
y = y + spaces;
cout << x << ","<< y << endl;
}
p.y = y;
if(direction == BACKWARD)
{
y = y - spaces;
cout << x << ","<< y << endl;
}
p.y = y;
}
MY MAIN FILE
#include
#import
#include "assets.h"
using namespace std;
void run()
{
while(t)
{
cout << "What direction would you like to turn? Left (L), Right (R), Forward (F), Backward (B) ";
cin >> d;
if(d == "L" || d == "l")
{
turnLeft();
cout << "Would you like to move " << d << "? Y/N ";
cin >> mv;
if(mv == "Y" || mv == "y")
{
cout << "How many spaces would you like to go " <> spaces;
move(spaces, direction, p.x, p.y, p);
}
else
{
run();
}
}
if(d == "R" || d == "r")
{
turnRight();
cout << "Would you like to move " << d << "? Y/N ";
cin >> mv;
if(mv == "Y" || mv == "y")
{
cout << "How many spaces would you like to go " <> spaces;
move(spaces, direction, p.x, p.y, p);
}
else
{
run();
}
}
if(d == "F" || d == "f")
{
turnForward();
cout << "Would you like to move " << d << "? Y/N ";
cin >> mv;
if(mv == "Y" || mv == "y")
{
cout << "How many spaces would you like to go " <> spaces;
move(spaces, direction, p.x, p.y, p);
}
else
{
run();
}
}
if(d == "B" || d == "b")
{
turnBackward();
cout << "Would you like to move " << d << "? Y/N ";
cin >> mv;
if(mv == "Y" || mv == "y")
{
cout << "How many spaces would you like to go " <> spaces;
move(spaces, direction, p.x, p.y, p);
}
else
{
run();
}
}
}
}
int main(int argc, char *argv[])
{
cout << "Enter in your name (This will be your username): ";
cin >> p.id;
run();
}