Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi @ everyone again.
I havent gotte naround to alot of programming lately but just today i found some time to start on something new. Im sure you all know the infamous Turtle Graphics Program. I have a little problem...but heres my code first.
//----------INCLUDES----------
#include <iostream>
using std::cout;
using std::cin;
using std::endl;#include <iomanip>
using std::setw;//----------PROTOTYPES----------
int penUP( int );
int penDOWN( int );
enum turnRIGHT( enum );
enum turnLEFT( enum );
void moveFORWARD(int & [][20],int, enum );
void print(int & [][20]);
void commandList();
int end(int);
//----------PROGRAM STARTS HERE----------
int main()
{
//main declarations
int command = 0, penStatus = 0;
enum Direction ( LEFT, RIGHT };
//declare floor array and initialize to 0
int floor[20][20];
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 20; j++)
{
floor[i][j] = 0;
}
}Direction moveDirection; //Direction enum object declared
cout << "Welcome! Im zour drawing TURTLE for tonight."
<< "\nTell me how to move" << endl;//loop until sentinal value returned
while(command != -1)
{
cout << "Please Insert Command (10 for command list): ";
cin >> command;
cout << endl;
//process command input
switch(command)
{
case 1: //input command 1
penDOWN(penStatus); //lower the pen
break; //break out of switchcase 2: //input command 2
penUP(penStatus); //raise the pen
break; //break out of switchcase 3: //input command 3
turnRIGHT(moveDirection); //turn turtle right
break; //break out of switchcase 4: //input command 4
turnLEFT(moveDirection); //turn turtle left
break; //break out of switchcase 5: //input command 5
moveFORWARD(floor[20][20],penStatus,moveDirection); //Move turtle forward x times
break; //break out of switchcase 6: //input command 6
print(); //print floor array
break; //break out of switchcase 9: //input command 9
end(); //returns sentinal value
break; //break out of switchcase 10: //input command 10
commandList(); //display list of commands
break; //break out of switchdefault:
cout << "Invalid command input."
<< " Enter new command." << endl;
break;
}
}
return 0; //indicate successful termination
}//----------FUNCTIONS----------
int penUP( int newPenStatus )
{
cout << "Im not drawing now" << endl;
return newPenStatus = 2;
}int penDOWN( int newPenStatus )
{
cout << "Im ready to draw" << endl;
return newPenStatus = 1;
}enum turnRIGHT( enum newDirection )
{
cout << "From now on I shall move to the right!" << endl;
return newDirection = RIGHT;
}enum turnLEFT( enum newDirection )
{
cout << "From now on I shall move to the left!" << endl;
return newDirection = LEFT;
}void moveFORWARD( int array [][20], int currentPenStatus, enum currentDirection)
{
int steps;
cout << "How many steps should I take? ";
cin >> steps;
if(currentPenStatus == 1)
{
if(currentDirection == RIGHT)
{
for(int i = 0; 0 < steps; i++)
{
//to be created
}
}
}}
void print()
{
}void commandList()
{
}int end()
{
cout << "Creativity makes you sleepy does it? Good night." << endl;
return command = -1;
}
Now the problem i am having is in the moveFORWARD function (which is also the actual drawing routine). When i set the direction of enum to left or right, how can i make sure i loop through the array properly? For example if you would 'travel' vertically through the area, its all well and good (just increment/decrement the counter value in the for loop respectivly to row/column). But if i were 'travel' horizontaly then it doesnt work anymore.Or maybe i just have a mental block. Can someone help me out?
Cheers
Dark_KartugWar sucks, but the sound is good and WE are the DJ's

Left and Right should act the same as Up and Down.
A question. Why are you trying to reinvent LOGO and not including all the good stuff?

==============================================================================
Actually, left and right should NOT act the same as up and down.The trick is remembering what you already know. Programmers have the benefit of knowing (or at least knowing where) the information they need is stored or specifically what it is all together. i.e. how wide is your matrix? 200 cells? then up means -200 and down means +200 (first checking for >=200 condition of course). Your matrix is 500?! Well it's all the same to me...-500/+500. What's that you say? The matrix width is unknown?!!! well -/+ mWidth (still checking for >=mWidth) etc....
borelli35

@borrelli
I think im getting the idea haha...basically like a vector plane with inverted y axis. ok i will give it a shot@wizard
Well im doing some teach-yourself-C++. i thought trying to 'reinvent the wheel' without ever having seen the original is gonne give me a good strong understanding of the concepts of arrays and control structures. So first im gonne get a basic version working...and then i can add more features later on. Theoretical knowledge is worhtless if you dont know how to apply it right?War sucks, but the sound is good and WE are the DJ's

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |