turtle graphics

I am creating a turtle graphics program. I am in the beginning stages of the program and just want to continue down the right path. I am also going to create a direction class to control the turning and moving forward of the turtle. I guess my question is more or less to get suggestions on how to initially set activePosition to floor[0][0] and how to continue moving it as well as setting the previousPositions after the active moves. I don't want the code given to me. Just suggestions and ongoing advice as I continue the program. Thank You.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//turtle.h
#ifndef TURTLE_H
#define TURTLE_H
#include <iostream>

//ASCII Constants
#define TURTLE char  (001)   //Smiley
#define MARKI char   (003)   //Heart
#define MARKII char  (004)   //Diamond
#define MARKIII char (005)   //Club
#define MARKIV char  (006)   //Spade

class Turtle
{
private:
	bool activePosition;
	bool pastPosition;
	bool penStatus;
	char penTip;

public:
	//default constructor
	Turtle(void);
	//destructor
	~Turtle(void);

	//Mutators
	bool setActivePosition();
	char setPenTip();
	bool setPenStatus();
	
	//Accessors
	bool getActivePosition();
	bool getPastPosition();
	bool getPenStatus();
	char getPenTip();


};
#endif
//turtle.cpp
#include "turtle.h"
#include <iostream>

using namespace std;


Turtle::Turtle(void)
{
	activePosition = false;
	pastPosition = false;
	penStatus = false;
}

Turtle::~Turtle(void)
{
}

//Unsure how to set this. How can I contact a private array of another class
bool Turtle::setActivePosition(){
if (!activePosition)
}

char Turtle::setPenTip(){
	int choice;
	cout << "PEN TYPES\n";
	cout << "---------\n";
	cout << "1) Is the Heart " << MARKI << endl;
	cout << "2) Is the Diamond " << MARKII << endl;
	cout << "3) Is the Club " << MARKIII << endl;
	cout << "4) Is the Spade " << MARKIV<< endl;
	cout << "Please select the pen you'd like to use.\n";
	cin >> choice;
	switch(choice){
case'1':
	penTip = MARKI;
	break;
case'2':
	penTip = MARKII;
	break;
case'3':
	penTip = MARKIII;
	break;
case'4':
	penTip = MARKIV;
	break;
default:
	cout << "Incorrect Entry\n";
	setPenTip();
	break;
	}
	return penTip;
}

bool Turtle::setPenStatus(){
	int choice;
	cout << "Pen Status\n";
	cout << "----------\n";
	cout << "1)Pen not marking\n";
	cout << "2)Pen marking\n";
	cin >> choice;
	switch(choice){
case '1':
	penStatus = false;
	break;
case '2':
	penStatus = true;
	break;
default:
	cout <<"Incorrect selection, please choose again\n";
	setPenStatus();
	break;
	}
return penStatus;
}

bool Turtle::getActivePosition(){
	return activePosition;
}

bool Turtle::getPastPosition(){
	return pastPosition;
}

bool Turtle::getPenStatus(){
	return penStatus;
}
char Turtle::getPenTip(){
	return penTip;
}
//position.h
#ifndef POSITION_H
#define POSITION_H
#include <iostream>
#include "turtle.h"


class Position
{
private:
int floor[20][20];

public:
	Position(void);
	~Position(void);
void draw(int row, int column);
};
#endif
//position.cpp
#include<iostream>
#include "position.h"
using namespace std;


Turtle turtle;
//Default Constructor (empty floor)
Position::Position(){

	for (int i = 1; i < 20; i++) {
		// ... then each column and set each space to '.'
		for (int j = 1; j < 20; j++) {
			floor[i][j] = 0;
		}
	
	}

}

Position::~Position(void)
{
}

void Position::draw(int row, int column){

	for (int i = 0; i < row; i++) {
		for (int j = 0; j < column; j++) {
			if (turtle.getActivePosition())
				floor[i][j] = TURTLE;
			else if(turtle.getPastPosition()){
				if (turtle.getPenStatus())
				floor[i][j] = turtle.getPenTip();
				else 
					cout << ' ';
			}
			else 
				cout << ' ';
		}
	}
}




bump so the thread doesn't get lost
bump so the thread doesn't get lost
Don't triple post.
Wow very constructive chrisname. I apologize . As you can see on the second and third times it was a glitch that double posted at the exact same time.
Ah, yeah... You can either apologize or be sarcastic. You can't do both.
Geez, the guy was only bumping his thread in case someone who might have been able to help him had missed it. He double posted clearly by accident, and chrisname jumps on his back 5 hours later...
Sorry, my mistake. I thought this was another person bumping their own threads every five minutes. I didn't even look at the times -- clearly he double posted by accident.

I apologise.
I just wanted to get some help with an issue I am having with the above program. Chrisname I figured that is what happened thats why I brought it to attention. This thread has turned into a discussion about forum etiquitte instead of anything constructive, hence the sarcasm helios. I will ask elsewhere for assistance, though hopefully someone here will help and get the thread back on track.

EDIT: I did add a few methods since original post but nothing to change the above issues I am having.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//Copy Constructor
Turtle::Turtle (Turtle& that){
this->activePosition = that.activePosition;
this->pastPosition = that.pastPosition;
this->penStatus = that.penStatus;
}

//Assignment Operator
Turtle& Turtle::operator = (Turtle& that){
	this->activePosition = that.activePosition;
	this->pastPosition = that.pastPosition;
	this->penStatus = that.penStatus;
	return *this;
}

int Position::getFloor(){
	return floor[20][20];
}
Last edited on
Topic archived. No new replies allowed.