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--;
           }
            

       }
}

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

Compiles and runs okay, and I'm seeing what you're seeing. It looks like you're working your way toward a standard game loop. You've got a start inside the code for when the player hits 'd', but it kind of freaks out if you hit anything else after that.

Here's an outline of the kind of program structure I'm talking about:

void main()
{
    // Set up player position and direction.
    
    bool done = false;
    
    do
    {
        // Draw the board and player.
        
        // Get input:
        if(kbhit())
        {
            switch(getch())
            {
                case 'd':
                    // Set player direction to "right".
                    break;
                    
                case 'a':
                    // Set player direction to "left".
                    break;
                    
                case 'x':
                    // Set player direction to "down".
                    break;
                    
                case 'w':
                    // Set player direction to "up".
                    break;
            }
        }
        
        // Update player position based on player direction.
        
        // If player position is over something solid, set 'done' to true.
    }
    while(!done)
}

I'd start by organizing your code so it looks something like this example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.