Everytime i try to run it it screws up, it works but you can only do one move then you cant change direction any more. here is the code and I recommend that you try it first before replying
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
void grid(char array[][79],int row, int col)
{
system("color 0C");
int i, j, k=178;
for(i=0, j=0; j<col; j++)
{
array[i][j]=k;
}
for(i=23, j=0; j<col; j++)
{
array[i][j]=k;
}
for(i=0, j=0; i<row; i++)
{
array[i][j]=k;
}
for(i=0, j=78; i<row; i++)
{
array[i][j]=k;
}
for(i=0; i<24; i++)
{
for(j=0; j<79; j++)
{
cout<<array[i][j];
}
cout<<endl;
}
}
void main()
{
int f=237;
char a;
char array[24][79]={32};
int p=3+rand()%78;
int u=p;
srand(p);
for(int i=0;i<3;i++,p++)
{
array[3][p]=f;
}
grid(array,24,79);
a=getch();
if(a=='d')
{
for(int z=p; z<78; z++)
{
int t=z-1;
t=t-2;
system("cls");
array[3][t]=' ';
array[3][z]=f;
grid(array,24,79);
if ( kbhit() )
{
int c;
a = getch();
if(a=='x'||a=='w'||a=='a')
{
switch(a)
{
case('x'):
for(c=3;c<24;)
{
int t=z-3;
t++;
int e=c-3;
system("cls");
array[3][t]=' ';
array[e][z]=' ';
array[c][z]=f;
grid(array,24,79);
c++;
}
break;
case('w'):
for(c=3;c>0;)
{
int t=z-3;
t++;
int e=c-3;
system("cls");
array[3][t]=' ';
u++;
array[e][z]=' ';
array[c][z]=f;
grid(array,24,79);
c--;
}
break;
case('a'):
for(int z=p-4; z>0; z--)
{
int t=z+1;
t=t+2;
system("cls");
array[3][t]=' ';
array[3][z]=f;
grid(array,24,79);
}
break;
}
}
}
}
}
else if(a=='a')
{
for(int z=p-4; z>0; z--)
{
int t=z+1;
t=t+2;
system("cls");
array[3][t]=' ';
array[3][z]=f;
grid(array,24,79);
}
}
else if(a=='x')
{
for(int c=3;c<24;)
{
int e=c-3;
system("cls");
array[3][u]=' ';
u++;
array[e][p]=' ';
array[c][p]=f;
grid(array,24,79);
c++;
}
}
else if(a=='w')
{
for(int c=3;c>0;)
{
int e=c-3;
system("cls");
array[3][u]=' ';
u++;
array[e][p]=' ';
array[c][p]=f;
grid(array,24,79);
c--;
}
}
}