View Full Version : Turtle Graphics...??
Liquid Bunny
March 29, 2005, 01:41 PM
Ok in the Deitel book ex 6.23... there is this question... i dunno how to attempt it.. and i want to get it done... does anybody especi the UTECH massive have the code for this already so i can have a look @ it ?
this is the question for those with out the book that wish to be of some assistance:) // wishful thinking
The Logo language, which is popular among young computer users made the concept of Turtle graphics famous, Imagine a mechanical turtle that walks around the room under the control of a C program. 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. When the pen is up, the turtle moves about freely without writing anything. In this problem you will simulate the operation of the turtle and create a computerized sketchpad as well.
Use a 50 by 50 array floor that is initialized to Zeros. Read commands from an array that contains them. Assume the turtle always starts at position (0,0) of the floor with its pen up. The commands your script must process are as follows:
Command Meaning
1 Pen up
2 Pen down
3 Turn right
4 Turn left
5, 10 Move forward 10 spaces or a number other than ten
6 Print the 20 by 20 array
9 End of data (sentinel)
Suppose that the turtle is somewhere near the center of the floor. The following program would draw and print a 12 by 12 square and then leave the pen in the up position:
2
5, 12
3
5, 12
3
5, 12
3
5, 12
1
6
9
As the turtle moves with the pen down set the appropriate elements of the array floor to 1s. When the 6 (print) command is given, display an asterisk wherever there is a 1 in the array. Wherever there is a zero display a blank.
I need to write a program to implement the turtle graphics capabilities discussed here.
CKnight
March 29, 2005, 02:04 PM
Show of hands for those who are as lost as I am :eusa_hand
I get the basic concept but don't know enough C right now to assist. Best I could do is help you put together the pseudocode which I never use, so I'm probably not very good at that either.
Liquid Bunny
March 29, 2005, 02:07 PM
Show of hands for those who are as lost as I am :eusa_hand
:eusa_hand me too... hmm.. i dont kno what to do... cho :eusa_wall
CKnight
March 29, 2005, 02:15 PM
i dont kno what to do... cho
What you should do is have at it. It sounds like an interesting project. The best I could do is look for a mindsweeper project I did a few years back. It was done in Pascal so it should be easy to follow for a C minded person like yourself. It has a similar premise, a x by y array with multiple states, yadda yadda yadda.
Where did I put that diskette...?
Liquid Bunny
March 29, 2005, 02:25 PM
ok well if u find it .. u can PM me
leoandru
March 29, 2005, 03:16 PM
cing that i am no longer a utech student. do i qualify? :icon_mrgr
Liquid Bunny
March 29, 2005, 03:23 PM
but of course... how could i possibly deny u ? :)
leoandru
March 29, 2005, 03:32 PM
sweet!!! :D . i'll take a good long look at it. btw is that a sch project or a personal attempt at learning c?
Liquid Bunny
March 29, 2005, 03:55 PM
um.. which would u prefer to hear? which ever one will make u help me faster is my choice :D
Krems
March 29, 2005, 03:59 PM
think i did something similar outa practice like 2 years ago....suppopsed to have it on my hard drive
but then....i dont have a computer to put it on
leoandru
March 29, 2005, 04:00 PM
in-between :D . I'll assume its a school project but pretend its personal. hows that?
Liquid Bunny
March 29, 2005, 04:04 PM
thumbs up... ur good.... :)
it is what ever u want it to be
crosswire
March 29, 2005, 04:09 PM
This looks like an interesting project for a TJ competition. I give it a shot.
Liquid Bunny
March 29, 2005, 04:12 PM
yes man be all enthused, yes yes :) lol yes lets see who can give it to me first... lol
Krems
March 29, 2005, 04:15 PM
hello maam...i do recall saying that it sitting on my hard drive you nuh.... :eusa_eh:
jus true i suck at programming....you jus flop my ting dem :(
leoandru
March 29, 2005, 04:18 PM
yes man be all enthused, yes yes :) lol yes lets see who can give it to me first... lol
lol, crosswire win, lol.. gwaan yaw youte, mek sure u collect yu prize whn u done.
crosswire
March 29, 2005, 04:19 PM
Oh typing up pseudo code as I speak
crosswire
March 29, 2005, 04:23 PM
Psuedo
init state
execute lines 1, then 2, ....
TurtleAndBoard
Attribute:
TurtleDirection
TurtlePosition
PenState
BoardState
Behaviour:
ReadNextCommand(file)
PerformCommand(command)
PerformCommand(command)
{
switch command
1 Pen up
2 Pen down
3 Turn right
4 Turn left
5, 10 Move forward 10 spaces or a number other than ten
6 Print the 20 by 20 array
9 End of data (sentinel)
}
Liquid Bunny
March 29, 2005, 04:23 PM
lol.. leo ur a real battyfish.... :)
Krems i am sorry...no u dont suck....lol (K)
Liquid Bunny
March 29, 2005, 04:26 PM
lol, crosswire win, lol.. gwaan yaw youte, mek sure u collect yu prize whn u done.
PRIZE? ....uh.. who mentioned a prize.... hmm... YEA man u get a prize to... lol ROPE IN!!!
Liquid Bunny
March 29, 2005, 04:29 PM
Psuedo
init state
execute lines 1, then 2, ....
....
1 Pen up
2 Pen down
3 Turn right
4 Turn left
5, 10 Move forward 10 spaces or a number other than ten
6 Print the 20 by 20 array
9 End of data (sentinel)
}
jeepers!! :icon_eek: thanks that was quick anything else?
leoandru
March 29, 2005, 04:40 PM
PRIZE? ....uh.. who mentioned a prize.... hmm... YEA man u get a prize to... lol ROPE IN!!!
4 real :icon_eek:. what do i get? I hope is not ur courage dog painting on yu wall. :eusa_snoo . I want something expensive cuz mi nuh cheap :icon_mrgr .
Liquid Bunny
March 29, 2005, 04:42 PM
lol... yea right who u kiddin.. u ...lol...not cheap....lol... not in the same sentence
leoandru
March 29, 2005, 04:44 PM
lol... yea right who u kiddin.. u ...lol...not cheap....lol... not in the same sentence
uhhm, what gave you that idea? :eusa_whis
crosswire
March 29, 2005, 04:52 PM
Anybody done yet? Look like some people can just use the book still
crosswire
March 29, 2005, 07:09 PM
You know this thing was giving me half a box, but me did lazy to use the debugger, I felt I could spot the error. Eventually I debugged it to find an unusual typo for me, a break statement by itself :(. Its unfinished still.
#include <iostream.h>
#include <fstream.h>
//enum dir {up, right, down, left};
#define BoardSize 50
class TurtleAndBoard
{
//Attribute:
int TurtleDirection;
int TurtleXPosition;
int TurtleYPosition;
int *****Down;
int BoardState[BoardSize][BoardSize];
//Behaviour:
public:
void InitState();
void ReadNextCommand(ifstream & CommandFile);
bool PerformCommand(int Command, int CommandParameter, ostream & DisplayHandle);
};
void TurtleAndBoard::InitState()
{
this->TurtleDirection = 0;
this->TurtleXPosition = BoardSize/2;
this->TurtleYPosition = BoardSize/2;
this->*****Down = 0;
for(int y = BoardSize - 1; y >= 0; y--)
{
for(int x = 0; x < BoardSize; x++)
{
this->BoardState[x][y] = 0;
}
}
}
bool TurtleAndBoard::PerformCommand(int Command, int CommandParameter, ostream & DisplayHandle)
{
switch(Command)
{
//1 Pen up
case 1:
this->*****Down = 0;
break;
//2 Pen down
case 2:
this->*****Down = 1;
break;
//3 Turn right
case 3:
this->TurtleDirection++;
if(this->TurtleDirection > 3)
{
this->TurtleDirection = 0;
}
break;
//4 Turn left
case 4:
this->TurtleDirection--;
if(this->TurtleDirection < 0)
{
this->TurtleDirection = 3;
}
break;
//5, 10 Move forward 10 spaces or a number other than ten
case 5:
int i;
switch(this->TurtleDirection)
{
//move up by n spaces
case 0:
for(i = 0; i < CommandParameter; i++)
{
//move up
this->TurtleYPosition++;
if(this->TurtleYPosition > (BoardSize - 1))
{
this->TurtleYPosition = (BoardSize - 1);
}
if(this->*****Down)
{
this->BoardState[TurtleXPosition][TurtleYPosition] = 1;
}
}
break;
//move right by n spaces
case 1:
for(i = 0; i < CommandParameter; i++)
{
//move right
this->TurtleXPosition++;
if(this->TurtleXPosition > (BoardSize - 1))
{
this->TurtleXPosition = (BoardSize - 1);
}
if(this->*****Down)
{
this->BoardState[TurtleXPosition][TurtleYPosition] = 1;
}
}
break;
//move down by n spaces
case 2:
for(i = 0; i < CommandParameter; i++)
{
//move down
this->TurtleYPosition--;
if(this->TurtleYPosition < 0)
{
this->TurtleYPosition = 0;
}
if(this->*****Down)
{
this->BoardState[TurtleXPosition][TurtleYPosition] = 1;
}
}
break;
//move left by n spaces
case 3:
for(i = 0; i < CommandParameter; i++)
{
//move left
this->TurtleXPosition--;
if(this->TurtleXPosition < 0)
{
this->TurtleXPosition = 0;
}
if(this->*****Down)
{
this->BoardState[TurtleXPosition][TurtleYPosition] = 1;
}
}
break;
}//end moving n spaces in specified direction
break;
//6 Print the 20 by 20 array
case 6:
//Start print the highest y row first
{
for(int y = BoardSize - 1; y >= 0; y--)
{
for(int x = 0; x < BoardSize; x++)
{
if(this->BoardState[x][y])
{
DisplayHandle << "*";
}
else
{
DisplayHandle << " ";
}
}
DisplayHandle << "\n";
}
}
break;
//9 End of data (sentinel)
case 9:
//WantAend
DisplayHandle << "Yow\n";
break;
}
return true;
}
int main()
{
TurtleAndBoard tb;
//init state
tb.InitState();
//execute lines 1, then 2, ....
/*
2
5, 12
3
5, 12
3
5, 12
3
5, 12
1
6
9
*/
tb.PerformCommand(2, 0, cout);
tb.PerformCommand(5, 12, cout);
tb.PerformCommand(3, 0, cout);
tb.PerformCommand(5, 12, cout);
tb.PerformCommand(3, 0, cout);
tb.PerformCommand(5, 12, cout);
tb.PerformCommand(3, 0, cout);
tb.PerformCommand(5, 12, cout);
tb.PerformCommand(1, 0, cout);
tb.PerformCommand(6, 0, cout);
tb.PerformCommand(9, 0, cout);
return 0;
}
Liquid Bunny
March 29, 2005, 07:21 PM
Wow thank u :) much appreciated
icuucme
March 29, 2005, 07:24 PM
@Liquid ..didnt u want it in full C? that code is c++
Liquid Bunny
March 29, 2005, 07:27 PM
lol funny enough thats what i just realized... i said thanks first n copy n pasted it n mid way looking thru it i was like wtf? oh dear, but its ok i am thankful for the help i kinda understand a lil better now wha i have to do
Liquid Bunny
March 29, 2005, 10:48 PM
i dunno wah i doing .....
icuucme
March 29, 2005, 10:55 PM
I thought u were ok, I'm gonna look if i did that question last year because i did C last year and i did some of those questions out of the deitel ...gonna search now
Liquid Bunny
March 29, 2005, 11:16 PM
thank u very much ....
leoandru
March 29, 2005, 11:22 PM
Liquid, mi notice how everybody running to ur rescue.. a wha so? anyway mi glad still.. spare me the long nights. crosswire u need to change up that code to c still. please!!
Liquid Bunny
March 29, 2005, 11:23 PM
Liquid, mi notice how everybody running to ur rescue.. a wha so? anyway mi glad still.. spare me the long nights. crosswire u need to change up that code to c still. please!!
if u neva comment...lol well.. i am a nice person so they are nice to me.... ;)
fir real tho Crosswire if is not too much work :D
crosswire
March 30, 2005, 04:28 AM
Alright. The code is not tidy either. Maybe C will be cleaner.
crosswire
March 30, 2005, 05:35 AM
Still unfinished
#include <stdlib.h>
#include <stdio.h>
//enum dir {up, right, down, left};
#define BoardSize 50
//void InitState();
//void ReadNextCommand(ifstream & CommandFile);
//bool PerformCommand(int Command, int CommandParameter, bool & WantaPrint);
__inline void InitState(int * pTurtleDirection, int * pTurtleXPosition, int * pTurtleYPosition, int * p*****Down, int BoardState[BoardSize][BoardSize])
{
int x;
int y;
(*pTurtleDirection) = 0;
(*pTurtleXPosition) = BoardSize/2;
(*pTurtleYPosition) = BoardSize/2;
(*p*****Down) = 0;
for(y = BoardSize - 1; y >= 0; y--)
{
for(x = 0; x < BoardSize; x++)
{
BoardState[x][y] = 0;
}
}
}
int PerformCommand(int Command, int CommandParameter, int * pWantaEnd,
int * pTurtleDirection, int * pTurtleXPosition, int * pTurtleYPosition, int * p*****Down, int BoardState[BoardSize][BoardSize])
{
int i;
int x;
int y;
switch(Command)
{
//1 Pen up
case 1:
(*p*****Down) = 0;
break;
//2 Pen down
case 2:
(*p*****Down) = 1;
break;
//3 Turn right
case 3:
(*pTurtleDirection)++;
if((*pTurtleDirection) > 3)
{
(*pTurtleDirection) = 0;
}
break;
//4 Turn left
case 4:
(*pTurtleDirection)--;
if((*pTurtleDirection) < 0)
{
(*pTurtleDirection) = 3;
}
break;
//5, 10 Move forward 10 spaces or a number other than ten
case 5:
switch((*pTurtleDirection))
{
//move up by n spaces
case 0:
for(i = 0; i < CommandParameter; i++)
{
//move up
(*pTurtleYPosition)++;
if((*pTurtleYPosition) > (BoardSize - 1))
{
(*pTurtleYPosition) = (BoardSize - 1);
}
if((*p*****Down))
{
BoardState[(*pTurtleXPosition)][(*pTurtleYPosition)] = 1;
}
}
break;
//move right by n spaces
case 1:
for(i = 0; i < CommandParameter; i++)
{
//move right
(*pTurtleXPosition)++;
if((*pTurtleXPosition) > (BoardSize - 1))
{
(*pTurtleXPosition) = (BoardSize - 1);
}
if((*p*****Down))
{
BoardState[(*pTurtleXPosition)][(*pTurtleYPosition)] = 1;
}
}
break;
//move down by n spaces
case 2:
for(i = 0; i < CommandParameter; i++)
{
//move down
(*pTurtleYPosition)--;
if((*pTurtleYPosition) < 0)
{
(*pTurtleYPosition) = 0;
}
if((*p*****Down))
{
BoardState[(*pTurtleXPosition)][(*pTurtleYPosition)] = 1;
}
}
break;
//move left by n spaces
case 3:
for(i = 0; i < CommandParameter; i++)
{
//move left
(*pTurtleXPosition)--;
if((*pTurtleXPosition) < 0)
{
(*pTurtleXPosition) = 0;
}
if((*p*****Down))
{
BoardState[(*pTurtleXPosition)][(*pTurtleYPosition)] = 1;
}
}
break;
}//end moving n spaces in specified direction
break;
//6 Print the 20 by 20 array
case 6:
//Start print the highest y row first
for(y = BoardSize - 1; y >= 0; y--)
{
for(x = 0; x < BoardSize; x++)
{
if(BoardState[x][y])
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
break;
break;
//9 End of data (sentinel)
case 9:
//WantAend
(*pWantaEnd) = 1;
break;
}
return 1;
}
int main()
{
//State variables
int TurtleDirection;
int TurtleXPosition;
int TurtleYPosition;
int *****Down;
int BoardState[BoardSize][BoardSize];
int WantaEnd;
//init state
InitState(&TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
//execute lines 1, then 2, ....
/*
2
5, 12
3
5, 12
3
5, 12
3
5, 12
1
6
9
*/
PerformCommand(2, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(5, 12, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(3, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(5, 12, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(3, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(5, 12, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(3, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(5, 12, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(1, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(6, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
PerformCommand(9, 0, &WantaEnd, &TurtleDirection, &TurtleXPosition, &TurtleYPosition, &*****Down, BoardState);
return 0;
}
crosswire
March 30, 2005, 05:43 AM
Something just look wrong bout it. Did I need so much pointers! Mi nah see something.
Skillachi
March 30, 2005, 08:30 AM
4 real :icon_eek:. what do i get? I hope is not ur courage dog painting on yu wall. :eusa_snoo . I want something expensive cuz mi nuh cheap :icon_mrgr .
Dont diss the courage painting... it look tuff :eusa_danc
megiddo
April 3, 2005, 08:46 PM
ok what about the rest of the games needed? like knights tale etc...
Liquid Bunny
April 3, 2005, 09:43 PM
i have them just the tortoise and the hare simulation i need
LEON WILSON
April 4, 2005, 12:07 AM
yOU GUYS ARE REAL HARDCORE TECHIES :icon_eek: jAMAICAN GEEKS OF THE GEEKS
legasy
April 4, 2005, 12:32 AM
//work from this and change wat u want yo. i cant give u mine but i worked //from this
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <conio.h>
int random_1();
int main()
{
int i = 0;
int j = 0;
int check;
int check_1;
char play_again = '\n' ;
int tortoise[70];
int hare[70];
printf("BANG !!!!!\n");
printf("AND THEY'RE OFF !!!!!\n");
while(play_again == '\n')
{
while(i <= 69 && j <= 69)
{
tortoise[i] = 0;;
check = random_1();
if(check == 1 || check == 2 || check == 3 || check == 4 || check ==
5)
tortoise[i+=3] = 0;
if(check == 6 || check == 7)
tortoise[i-=6] = 0;
if(check == 8 || check == 9 || check == 10)
tortoise[i+=1] = 0;
char *ptr;
char line[71] = "-----------------------------------------------------------"
"-----------";
ptr = line;
if(i < 0){
i = 0;
*(ptr + i) = 'T';}
*(ptr + i) = 'T';
hare[j] = 0;
check_1 = random_1();
if(check_1 == 1 || check_1 == 2)
hare[j] = 0;
if(check_1 == 3 || check_1 == 4)
hare[j+=9] = 0;
if(check_1 == 5)
hare[j+=12] = 0;
if(check_1 == 6 || check_1 == 7 || check_1 == 8)
hare[j++] = 0;
if(check_1 == 9 || check_1 == 10)
hare[j-=2] = 0;
if(j < 0){
j = 0;
*(ptr + j) = 'H';}
*(ptr + j) = 'H';
if(i == j){
*(ptr + i) = 'O';
*(ptr + i + 1) = 'U';
*(ptr + i + 2) = 'C';
*(ptr + i + 3) = 'H';}
printf("%s\n\n", line);
break;
}
if(i >= 69)
{
printf("TORTOISE WINS!!! YAY!!!\n");
break;
}
if(j >= 69)
{
printf("HARE WINS. YUCH.\n");
break;
}
if(j >= 69 && i >= 69)
{
printf("IT'S A TIE\n");
break;
}
printf("Press enter");
scanf("%c", &play_again);
}
getch();
return 0;
}
int random_1()
{
srand(time(NULL));
return (1 + rand() % 10);
}
Liquid Bunny
April 4, 2005, 11:34 AM
THANKS...oh my gosh i really appreciate it .... :)
Liquid Bunny
April 5, 2005, 05:16 PM
ATTENTION UTECH 1st year students....
The above code has been distributed to a lot of students.... Mr Pyne is no fool ... as we all know..lol... so it is advised that u change up some of the coding...
leoandru
April 5, 2005, 05:36 PM
LOL yes.. plagiarizing ppls code :eusa_naug.
psybuck2002us
April 8, 2005, 04:52 PM
@ Liquid Bunny. I have a complete copy of the turtle graphics program. I'll upload it on Monday.
Liquid Bunny
April 8, 2005, 05:08 PM
thanks... cant wait to see it
Liquid Bunny
April 20, 2005, 10:39 PM
Mr. psybuck2002us what ever became of this?
psybuck2002us
May 11, 2005, 07:45 PM
OK, OK. I know i promised to upload this long ago, but i had my exams and last minute assignments killing me. This was my assignment for Turtle Graphics that i handed in when i was a first year at UTECH. Hope it's not too late to help you out. Anyway here goes......
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define up 0
#define down 1
#define north 4
#define south 5
#define east 6
#define west 7
#define row 20
#define col 20
int floor [row][col] = {0}, i, j, p, px = 0, py = 0, s, c, d, f;
char selection[20], e[20], n[20];
void choice (int);
void main()
{
printf("**************************************\n");
printf("* Welcome to Turtle Graphics *\n");
printf("**************************************\n");
again:
printf("\n============== MENU ==============\n");
printf("\n[1] Pen Off Canvas\n[2] Pen On Canvas\n[3] Turn Right\n[4] Turn Left\n[5] Turn Down\n[6] Turn Up\n[7] Move Pen\n[8] Display Canvas\n[9] Exit Turtle Graphics");
s = east; //Default Direction of the pen
p = up; //Default position of the pen; wether up or down
while (c != 9 || d == 2)
{
printf("\n\nSelection: ");
scanf("%s", selection);
c = atoi(selection); //Character Converted to Integar
/*This if structure was used to patch the problem where after the user enters 7 to move the pen, the menu is displayed
again before "Number of spaces to move forward" is displayed. The aim was to display the menu again only for all the other
options except 7. The problem is patched by telling the if statement to display the menu first, then continue to call the
function only when it is true that the value of "c" is not 7; else, if the value of "c" is 7, then the function is called immediately*/
if (c != 7) {
printf("\n============== MENU ==============\n");
printf("\n[1] Pen Off Canvas\n[2] Pen On Canvas\n[3] Turn Right\n[4] Turn Left\n[5] Turn Down\n[6] Turn Up\n[7] Move Pen\n[8] Display Canvas\n[9] Exit Turtle Graphics");
choice(c); //Call for function with the switch control structure
}
else {
if (c == 7)
choice(c); //Call for function with the switch control structure
}
}
printf ("\n[1] Yes\n[2] No\n\n");
printf ("Selection: ");
scanf ("%s", e);
d = atoi(e);
if (d == 1){
clrscr(); //Clears the screen
printf ("See You Later!!!\n");
}
else
if (d == 2)
goto again;
getch();
}
void choice (int)
{
switch(c)
{
case 1: //Pen Off Canvas
p = up;
break;
case 2: //Pen On Canvas
p = down;
break;
case 3: //Turn Right
if (s == north || s == south || s == east || s == west)
s = east;
break;
case 4: //Turn Left
if(s == north || s == south || s == east || s == west)
s = west;
break;
case 5: //Turn Down
if (s == north || s == south || s == east || s == west)
s = south;
break;
case 6: //Turn Up
if (s == north || s == south || s == east || s == west)
s = north;
break;
case 7: //Draw or Move Pen
printf("\nNumber of spaces to move forward: ");
scanf("%s", n);
f = atoi(n);
if (p == up) {
if(s == north)
{
for(i = 0; i < f; i++)
floor[px - i][py] = 0;
px = px - i + 1;
}
if(s == east)
{
for(i = 0; i < f; i++)
floor[px][py + i] = 0;
py = py + i - 1;
}
if(s == south)
{
for(i = 0; i < f; i++)
floor[px + i][py] = 0;
px = px + i - 1;
}
if(s == west)
{
for(i = 0; i < f; i++)
floor[px][py - i] = 0;
py = py - i + 1;
}
}
if (p == down) {
if(s == north)
{
for(i = 0; i < f; i++)
floor[px - i][py] = 1;
px = px - i + 1;
}
if(s == east)
{
for(i = 0; i < f; i++)
floor[px][py + i] = 1;
py = py + i - 1;
}
if(s == south)
{
for(i = 0; i < f; i++)
floor[px + i][py] = 1;
px = px + i - 1;
}
if(s == west)
{
for(i = 0; i < f; i++)
floor[px][py - i] = 1;
py = py - i + 1;
}
}
break;
case 8: //Display Canvas (20 x 20 Array)
clrscr();
printf("\n");
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
if (floor[i][j] == 0)
printf(". ");
if (floor[i][j] == 1)
printf("* ");
}
printf("\n");
}
break;
case 9: //Exit Program
clrscr();
printf ("Are you sure you want to exit?\n");
break;
default:
printf ("\nInvalid Input\n");
break;
}
}
Liquid Bunny
May 11, 2005, 11:29 PM
better late than never, i suppose... :) thanks Psy
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.