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

New Free Tools on Dev Shed!

#16
June 15th, 2002, 01:51 PM
 suhailkaleem
Junior Member

Join Date: Jun 2002
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
no ! it is not for a class i was getting bored so i decided to make some thing , so i tried out this but unluckly i got stuck so that is why i am asking you people to help me ,

and thanks Nichademus for giving it a try

any body else who would like to help me !

suhailkaleem

#17
June 17th, 2002, 09:34 AM
 Michael_Bray
Contributing User

Join Date: Sep 2000
Location: Sydney, NSW, Australia
Posts: 40
Time spent in forums: < 1 sec
Reputation Power: 14
First off to make sure its a square you'll want to make sure that the two diagonals of the square have the same length. Easiest way to make sure its a square.

Think about pythagorus to do this. I could give you a formula, but from what I have read you wouldn't understand it. Have a think about pythagorus and how you can use it to find the length of the diagnols, then sub in the (x,y) values to your working...

If you want the square to be "flat", as in not on an angle, Y1 will equal Y2, and X1 will equal X3, with the coordinates being

(x1,y1) (x2,y2)
(x3,y3) (x4,y4)

Hope that helps.
__________________
Cheers,
Michael Bray

#18
June 17th, 2002, 12:34 PM
 suhailkaleem
Junior Member

Join Date: Jun 2002
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
here is the code

i already know the lengs of the sides ,
ok here is the code see for yr self wat i am trying to tell you !

*************************************************

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)

{
clrscr();
int vary =9 ,varx =15 ,var_d =5;
int x,y,y1,x1,x2,y2,x3,y3,key,key2,key3,key_d=1,key_l=varx,key_u=vary,key_r=1,z ;

y =var_d ;
x=var_d ;
do
{
key3 =getch();

y1 =var_d ;
for (y3=0 ;y3<vary ; y3++ )
{
x1 =var_d ;
for(x3=0;x3<varx;x3++)
{
gotoxy(x1,y1);
textcolor(RED);
printf("%c",t);
x1=x1+var_d ;
}
y1=y1+var_d ;

}

do
{
//vars ='l' ;
// printf ("%c", vars );
key =getch ();
if (key =='x')
{
exit(1) ;
}
if (key==80)
if ( key_d < vary)
if (vars !='s')
{

{
{
key_d ++ ;
key_u--;

y =y+var_d;
gotoxy(x,y);
printf (" ") ;
gotoxy(x,y);
y=y-var_d ;
gotoxy(x,y) ;
printf("%c",t);
y=y+var_d;

gotoxy(10,40);
printf("x=%d ,y=%d",x,y);

}
}
}
if (key==72)
if( key_u < vary)
if ( vars !='s')
{
{
{
key_u++ ;
key_d--;

y =y-var_d;
gotoxy(x,y);
printf (" ") ;
gotoxy(x,y);
y=y+var_d ;
gotoxy(x,y);
printf("%c",t);
y=y-var_d;
gotoxy(10,40);
printf("x=%d ,y=%d",x,y);

}
}

}
if ( key==77 )

if ( key_r < varx )
if (vars !='s' )
{
{
{
key_r++;
key_l --;

x =x+var_d;
gotoxy(x,y);
printf (" ") ;
gotoxy(x,y);
x=x-var_d ;
gotoxy(x,y);
printf("%c",t);
x=x+var_d ;

gotoxy(10,40);
printf("x=%d ,y=%d",x,y);
}
}
}

if (key==75)
if ( key_l < varx)
if (vars != 's')
{
{
{
key_l++;
key_r--;

x =x-var_d;
gotoxy(x,y);
printf (" ") ;
gotoxy(x,y);
x=x+var_d ;
gotoxy(x,y) ;
printf("%c",t);
x=x-var_d;
gotoxy(10,40);
printf("x=%d ,y=%d",x,y);
}
} }

}

while (key!=13) ;

x2= x;
y2= y ;

do
{

if (key == 13)
{
vars ='s';
{

key2 =getch();
if (key2 =='x')
{
exit(1) ;
}
if ( key2==80)

if (vars =='s')
{
{

y=y-var_d ;
gotoxy(x,y) ;
printf("%c",sm);
x=x+var_d ;
y=y+var_d ;
gotoxy(x,y);
printf("%c",sm);
x=x-2*var_d ;
gotoxy(x,y);
printf("%c",sm);
x=x+var_d;
y=y+var_d ;
gotoxy(x,y);
y=y-var_d ;
key2 = getch();
if (key2 ==13)
{

for ( z =0 ; z <=var_d ; z++)
{
gotoxy(x2,y2);
printf ("|");
y2++ ;

}
// y2=y2-var_d ;
// int n=y2+var_d ;
// int p=0 ;
//int array[100] ;
// array[p] = n ;

// printf("%d",array[p]);
//p++ ;

vars='l' ;
}
}
}
if ( key2==72)
if (vars =='s')
{
{
y=y-var_d ;
gotoxy(x,y) ;
x=x+var_d ;
y=y+var_d ;
gotoxy(x,y);
printf("%c",sm);
x=x-2*var_d ;
gotoxy(x,y);
printf("%c",sm);
x=x+var_d;
y=y+var_d ;
gotoxy(x,y);
printf("%c",sm);
y=y-var_d ;

key2 = getch();
if (key2 ==13)
{

for ( z =0 ; z <=var_d ; z++)
{
gotoxy(x2,y2);
printf ("|");
y2-- ;
}
y2=y2+var_d ;
vars='l' ;
}

}
}

if ( key2==77)
if (vars =='s')
{
{
y=y-var_d ;
gotoxy(x,y) ;
printf("%c",sm);
x=x+var_d ;
y=y+var_d ;
gotoxy(x,y);
x=x-2*var_d ;
gotoxy(x,y);
printf("%c",sm);
x=x+var_d;
y=y+var_d ;
gotoxy(x,y);
printf("%c",sm);
y =y-var_d ;

key2 = getch();
if (key2 ==13)
{
for ( z =0 ; z <=var_d ; z++)
{
gotoxy(x2,y2);
printf ("-");
x2++ ;
}
x2 =x2-var_d ;
vars='l' ;
}
}
}

if ( key2==75)
if (vars =='s')
{
{
y=y-var_d ;
gotoxy(x,y) ;
printf("%c",sm);
x=x+var_d ;
y=y+var_d ;
gotoxy(x,y);
printf("%c",sm);
x=x-2*var_d ;
gotoxy(x,y);
x=x+var_d;
y=y+var_d ;
gotoxy(x,y);
printf("%c",sm);
y=y-var_d;

key2 = getch();
if (key2 ==13)
{
for ( z =0 ; z <=var_d; z++)
{
gotoxy(x2,y2);
printf ("-");
x2-- ;
}
x2 =x2+var_d ;
vars='l' ;
}

}
}

}
}

}

while (vars!='l');
}
while (key3!='x');

}

*************************************************

the code runs on tc ,
u will know wat the codes do if anything is not clear do ask me
suhailkaleem

#19
June 19th, 2002, 02:59 PM
 suhailkaleem
Junior Member

Join Date: Jun 2002
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
no help ?

 Viewing: Dev Shed Forums > Programming Languages - More > Software Design > x , y coordinates