General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 29th, 2012, 06:01 PM
hellishviking hellishviking is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 1 hellishviking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 2 sec
Reputation Power: 0
Turtle Graphics

okay, I have a turtle graphics program that works just fine.My program takes the users input and uses that for directions for the turtle to draw. I want to make it so that the input is a text file instead of the user inputting the data. Can anyone lend me a hand ? any help is apppreciated!

Here is my code :

Code:
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//-Prototypes-

int loadArray(int [],int );
void docommands(int [],int [][30],int );
void printArray(int [][30]);
void trnrgt(int *);
void trnlft(int *);
int moveit(int *,int ,int [],int [][30],int *,int *,int);
void doc(void);

void main(void)
{
int commands[100]={0};
int position[30][30]={{0},{0}};int count=0;

system("CLS");
printf("This is a turtle graphics program.");
doc(); //how to use the program
//ount=loadArray(commands,count); //count is how many numbers were entered
docommands(commands,position,count);
system ("PAUSE");

}
int loadArray(int array[],int temp){
int x;
for(x=0;;x++) {
temp++; //temp is the count
printf("Enter command : ");
scanf("%d",&array[x]);
if (array[x]==9)
break ;
if (array[x]==7 || array[x]==8){
printf("Invalid entry !!!Try Again\n");
x--;//erase what we just wrote
temp--;//decrement our count
}
if (array[x]<= 0 || array[x]>9){
printf("Invalid entry !!!Try Again\n");
x--;
temp--;
}
if (array[x]==5) {
scanf(",%d",&array[x+1]);
x++; //move to next element
temp++; //increae count
}
}
return temp;
}
void docommands(int array[],int ddarray[][30],int c){
int x,y,pendwn,count,post=1,bounds1=0,bounds2=0;
for (x=0;x<=c;x++){
switch (array[x]){
case 1: pendwn = 0;
break ;
case 2:pendwn = 1;
break;
case 3:trnrgt(&post);
break;
case 4:trnlft(&post);
break;
case 5:x=moveit(&post,x,array,ddarray,&bounds1,&bounds2,pendwn);
break;
case 6:printArray(ddarray);
break;
case 9:break;
}
}
}
void printArray(int array [][30]){
int x,col,rows;
for (rows=0;rows <30;rows++){
for (col=0;col<30;col++)
printf("%c" ,array[rows][col]);
printf("\n");
}
}
int moveit(int *post,int x,int array[],int ddarray[][30],int *bounds1,int *bounds2,int pendwn){
int y,b,bnds1,bnds2;
x++;
bnds1=*bounds1; //watch the bounds for going up and down
bnds2=*bounds2; //watch the bounds for going sideways
switch (*post){
case 1:
if (bnds2<30){
if (array[x]>29)
array[x]=29;
for(y=0;y<(array[x]);y++){
if (pendwn){
ddarray[bnds1][bnds2]=42;
bnds2++;
}
else {
ddarray[bnds1][bnds2]=32;
bnds2++;
}
}
}
break;
case 2: {
if (array[x]>29)
array[x]=29;
for (y=(array[x]);y>0;y--){
if (bnds2>0){
if (bnds1>=30)
bnds1=19;
if (pendwn){
ddarray[bnds1][bnds2]=42;
bnds2--;
}
else {
ddarray[bnds1][bnds2]= 32;
bnds2--;
}
}
else
break;
}
break;
case 3:{
if (array[x]>29)
array[x]=29;
for (y =0;y<(array[x]);y++){
if (bnds1>0){
if (pendwn){
ddarray[bnds1][bnds2]=42;
bnds1--;
}
else{
ddarray[bnds1][bnds2]=32;
bnds1--;
}
}
}
break;
}
case 4:{
if (array[x]>29)
array[x]=29;
for (y=0;y < (array[x]);y++){
if (bnds2>29)
bnds2=19;
if (pendwn){
ddarray[bnds1][bnds2]= 42;
bnds1++;
}
else{
ddarray[bnds1][bnds2]= 32;
bnds1++;
}
}
break;
}
}
}
*bounds1=bnds1;
*bounds2=bnds2;
return x;
}
void trnlft(int *post){
switch (*post){
case 1:*post = 3; // 1 = east
break;
case 2:*post = 4; // 2 = west
break;
case 3:*post = 2; // 3 = north
break;
case 4:*post = 1; //4 = south
break;
}
}
void trnrgt(int *post){
switch (*post){
case 1: *post = 4;
break;
case 2: *post = 3;
break;
case 3: *post = 1;
break;
case 4: *post = 2;
break;
}
}
void doc (void){
printf("This program will draw a series of * with the commands that ");
printf("are entered. \nHere are the commands : \n\n");
printf("1 pushes your pen up meaning leaving no traces.\n");
printf("2 puts the pen down to leave traces.\n");
printf("3 turns right.\n");
printf("4 turns left.\n");
printf("5 moves after entering a 5 you have to specify the number of moves.\n");
printf(" for example : 5,10 you have to put the coma before the number.\n");
printf("6 prints the result on the screen.\n");
printf("9 ends the program.\n\n");
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Turtle Graphics


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap