I need to make a 20 by 20 array or floor which is initialized to zeros, keep track of the current position of the turtle at all times, the direction it is heading, and whether the pen is currently up or down. The set of turtle commands I need are:
1 change pen position
2 turn
3 move forward
4 print
5 change brush
6 erase/start over
7 jump(go to a position given by the user)
8 see menu again
9 end program
I have a bit started but have no clue where to go. I have .cpp files for all class which just "#include classname.h". So far i have:
floor.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class floor
{
private:
static const int size = 22;
char grid[size][size];
int x = 0;
int y = 0;
public:
floor();
};
floor::floor()
{
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
grid[x][y] = '0';// single character, not the string "0"
std::cout << grid[x][y];// checking actual value
}
std::cout << std::endl;
}
};
|
direction.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <cctype>
#include <iostream>
class direction
{
private:
char facing;
//N, S, E, or W
public:
direction();
direction(const direction &init);
~direction();
char lookTo();
};
direction::direction()
{
std::cout << "created" << std::endl;
}
/*
direction::direction(const direction &init)
{
init.facing = facing;
}
*/
char direction::lookTo()
{
std::cout << "what is the direction the turtle is facing?/n";
std::cin >> facing;
toupper(facing);
while (!(facing = 'N') || !(facing = 'S') || !(facing = 'E') || !(facing = 'W'))
{
std::cout << "That is an invalid direction: N, S, E, or W.\n";
std::cin >> facing;
}
}
|
I have this working apart from the copy constructor
EDIT: no it is not, i have "IntelliSense: a nonstatic member reference must be relative to a specific object" and "error C2597: illegal reference to non-static member 'direction::facing'"
on every single "facing" in the lookTo implementation.
position.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include "direction.h"
class position
{
private:
int moveAmount;
public:
position();
position(const position &init);
~position();
void move(char, int);
};
int x, y;
position::position()
{
};
void position::move(char look, int moveAmout)
{
look = direction::lookTo();
if (look == 'E')
x = x + moveAmount;
else if (look == 'W')
x = x - moveAmount;
else if (look == 'N')
y = y + moveAmount;
else
y = y - moveAmount;
}
|
moveAmount is a given value in which moves the turtle. The x and y values are the position in the floor grid. how would i get this to work?
Pen.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
class pen
{
private:
bool penStatus = true;
//T up F down
public:
pen(); //constructor
~pen();
void changePen();
//change to up or down
char Brushstorke = '*';
//prints '*' when the turtle moves
};
bool penStatus
{
std::cout << penStatus
};
//changes if the pen is up or down
void changePen()
{
if (penStatus == true)
penStatus = false;
else penStatus = true;
}
//constructor
pen::pen()
{
}
//deconstructor
pen::~pen()
{
}
|
turtle.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include "pen.h"
#include "direction.h"
#include "position.h"
#include "floor.h"
class turtle
{
private:
public:
pen pen;
direction dir;
position pos;
floor ground; //error "'floor' is not a type name"
};
|
And an empty driver (has int main)
**************************
When I, for example, move forward(3) 5 places i would need to leave a '*' char.
*****0000000000000
000000000000000000
000000000000000000 |
etc.
I have a size of 22 because i was going to put a frame of 'X' around it.
**************************
Thanks to: fun2code