
PS: Since the blog editor doesn't accept the special characters '<' & '>' (or I haven't figured out how to make them accepted) which are very frequently used in C++, I have replaced them (using Microsoft Word).
'<' has been replaced by '~' and '>' has been replaced by '?'. So to run the program first replace the characters back to original.
This program may not work on various computers due to different dimension.
Didn't really work out the way I wanted it to.
But deserves a look!
There are some minor problems with this one.
The cursor can be navigated using the keys W,A,S,D. But in the beginning of the program, the nagigation is sort of stuck.
Here is the solution: Press 'S' 3-4 times and then press'D' 3-4 times. This will make the navigation part work freely.
Then move the cursor anywhere on the screen and press 'ENTER'. Whoa!
The program won't end by pressing Esc. So press 'Ctrl + Break' 2-3 times.
#include~iostream.h?
#include~conio.h?
#include~process.h?
void main()
{
clrscr();
int t=0;
int x=0,y=0; //Coordinates.
int a=42; //Will tell the direction of ball. Left upper corner is position 1. Here 42 means, ball goes from corner # 4 to corner # 2.
int l=2; //The # of Wall : Upper frame is wall # 1.
int len=79, br=49; //Dimensions of Length and Breadth.
long speed=2999999; //Defines how fast the ball moves.
char ch; //Choice for W,A,S,D.
char cha='*'; //Character which will represent the ball.
char cha2='*';
while(x?=0 && y?=0)
{
ch=getch();
if(ch=='w')
gotoxy(x,y=y-1);
else if(ch=='a')
gotoxy(x=x-1,y);
else if(ch=='s')
gotoxy(x,y=y+1);
else if(ch=='d')
gotoxy(x=x+1,y);
else if(ch!='w' || ch!='a' || ch!='s' || ch!='d')
break;
}
while(x~=len && y~=br)
{
//clrscr();
if(y==br && x~len)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(++x,--y);
l=3;
}
if(y==0 && x~len)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(--x,++y);
l=1;
}
if(x==0 && y~br)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(++x,++y);
l=2;
}
if(x==len && y~br)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(--x,--y);
l=4;
}
while(x~len && x?0 && y?0 && y~br && l==2 && a==42)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(++x,++y);
t=1;
}
if(t==1)
a=13;
while(x~len && x?0 && y?0 && y~br && l==2 && a==31)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(++x,--y);
t=2;
}
if(t==2)
a=24;
while(x~len && x?0 && y?0 && y~br && l==3 && a==13)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(++x,--y);
t=3;
}
if(t==3)
a=24;
while(x~len && x?0 && y?0 && y~br && l==3 && a==42)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(--x,--y);
t=4;
}
if(t==4)
a=31;
while(x~len && x?0 && y?0 && y~br && l==4 && a==24)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(--x,--y);
t=5;
}
if(t==5)
a=31;
while(x~len && x?0 && y?0 && y~br && l==4 && a==13)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(--x,++y);
t=6;
}
if(t==6)
a=42;
while(x~len && x?0 && y?0 && y~br && l==1 && a==31)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(--x,++y);
t=7;
}
if(t==7)
a=42;
while(x~len && x?0 && y?0 && y~br && l==1 && a==24)
{
gotoxy(x,y);
cout~~cha;
gotoxy(x,y);
for(long j=1;j~speed;j++);
cout~~cha2;
gotoxy(++x,++y);
t=8;
}
if(t==8)
a=13;
}
getch();
}
No comments:
Post a Comment