I have to deisgn a game for computer class that is due tommorow and I have been working on for a while and have not yet been able to figure it out so I'm hoping someone here can help me out with my problem.
I have to write a program that simulates Turtle Graphics (an old computer game). The turtle holds the pen in one of two positions, up or down. When the pen is down, the turtle traces out shapes as it moves; while the turtle is up, the turtle moves about freely without writing anything.
I have to use a 20x20 array "floor" which is initialized to zeros. The user gets to input commands. It has to keep track of the current position at all times and wether the pen is currently up or down. Assuming that the turtle always starts at position 0,0 with the pen up. The commands work as follows:
Command:
1-pen up
2-pen down
3-turn right
4-turn left
5, # - move forward, and # represents amount of spaces moved.
6- prints the array
9-ends data
Here's what I have in my program so far. I dont know how to have it inout for each space so say if it's going forward 3 spaces with the pen down to input a 1 in each of the spaces and then be able to turn in any direction and continue, etc. Please let me know if you see something wrong with it so far and if you could, can you fill in the command steps 5 and 6, changing what I have now for it too work. If you have any questions on the program and what it's susposed to do please let me know. Here's my program..:
//turtle.cpp
//This program uses a double dimension array to draw shapes and lines base on the users input of commands
#include <iostream.h>
int func_name();
int func_game();
int commands;
int pen;
int main(void)
{ char yesorno;
func_name();
Again:
func_game();
cout<<"Would you like to play again? (y/n)";
cin>>yesorno;
cout<<endl<<endl;
if (yesorno=='y')
{
cout<<endl<<endl;
goto Again;
}
else
cout<<"Thanks for using my program. Please come again sometime soon.";
cout<<endl<<endl;
return 0;
}
//**************************************************
//This part of the program just allows the user to enter their name
int func_name()
{
char f_name[20];
cout<<"Hello, and welcome to my game!";
cout<<endl;
cout<<"Please input your first name. ";
cin>>f_name;
char l_name[30];
cout<<"Please input your last name. ";
cin>>l_name;
cout<<endl;
cout<<"Welcome "<<f_name<<" "<<l_name<<" I hope you have fun with my game!";
cout<<endl<<endl<<endl;
return 0;
}
//**************************************************
//This is the actual game part of the program that uses the double dimension array
int func_game()
{ int R, C, I, turtle[20][20], spaces, stop=0, num=0, direction=1;
cout<<"Instructions: The purpose of the game will use you to input commands to make a ";
cout<<endl;
cout<<"picture using * and blank spaces. A list of what the commands do will be above ";
cout<<endl;
cout<<"the command space to enter.";
cout<<endl<<endl;
cout<<"The commands: ";
cout<<endl;
cout<<"1-pen up";
cout<<endl;
cout<<"2-pen down";
cout<<endl;
cout<<"3-Turn right";
cout<<endl;
cout<<"4-Turn left";
cout<<endl;
cout<<"5,#-Amount of spaces moved ";
cout<<endl;
cout<<"6-Prints game on screen";
cout<<endl;
cout<<"9-Ends data ";
cout<<endl<<endl;
Default:
cout<<"Please input your command: ";
cin>>commands;
cout<<endl;
switch (commands)
{
case 1: {pen=0;
commands=0;
goto Default;
break;}
case 2: {pen=1;
commands=0;
goto Default;
break;}
case 3: {if (direction==4)
{direction==1;}
else
{direction=direction++;}
commands=0;
goto Default;
break;}
case 4: {if (direction==1)
{direction==4;}
else
{direction=direction--;}
commands=0;
goto Default;
break;}
case 5: {
cout<<"How many spaces would you like to move? ";
cin>>spaces;
turtle[R][C]=pen;
cout<<endl<<endl;
goto Default;
}
case 6: {
for(R=0; R<20;R++)
{
for(C=0; C<20; C++)
{
cout<<turtle[R][C]<<" ";//you'll see
}
cout<<endl;
}
cout<<endl<<endl;
goto Default;
break;}
case 9: {return 0;}
default: {cout<<"You entered a wrong number please type a correct number. ";
cout<<endl<<endl;
goto Default;
break;}
}
return 0;
}