// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <stdio.h>
#include <conio.h>

#define WAIT 100
#define SCR_WIDTH 80
#define SCR_HEIGTH 25
#define A_CHAR '@'

struct COORD
{
   int X,Y;
};

void putmch(char *s)
{
   char *p = s;
   while(*p)
   {
      putch(*p);
      p++;
   }
}

int main()
{
    COORD pos = { SCR_WIDTH / 2, SCR_HEIGTH / 2 };
    COORD old = pos ;
    COORD null = {1,1};
    COORD skrive = {25,1};
    highvideo();
    textcolor(GREEN);
    clrscr();
    gotoxy(pos.X, pos.Y) ;
    putch(A_CHAR);
    for(;;)
    {
        if(kbhit())
        {
           int c = getch();
           if(c == 0x1B) break;
           if(c == 0)
           {
               c = getch();
               if(c==75) pos.X = ( pos.X > 0 ? pos.X - 1 : 0 );
               if(c==77) pos.X = ( pos.X < SCR_WIDTH - 1 ? pos.X + 1 : SCR_WIDTH );
               if(c==72) pos.Y = ( pos.Y > 0 ? pos.Y - 1 : 0 );
               if(c==80) pos.Y = ( pos.Y < SCR_HEIGTH - 1 ? pos.Y + 1 : SCR_HEIGTH );
           }
        }
        if ( pos.X != old.X || pos.Y != old.Y)
        {
            gotoxy(old.X,old.Y) ;
            putch(' ');
            gotoxy(pos.X, pos.Y) ;
            putch(A_CHAR);
            old = pos ;
            gotoxy(null.X,null.Y);
            putmch("           ");
            gotoxy(null.X,null.Y);
            char s[17];
            sprintf(s,"x: %d y: %d",pos.X,pos.Y);
            putmch(s);
            gotoxy(pos.X,pos.Y);    
            if ( pos.X == 10 && pos.Y == 10)
            {
                gotoxy(skrive.X,skrive.Y) ;
                putmch("Fundet");
                gotoxy(pos.X,pos.Y);    
            }
        }
    }
    return 0 ;
}
